Changeset 15498 in josm for trunk/src/org
- Timestamp:
- 2019-11-02T16:40:58+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r15496 r15498 38 38 import java.util.TimeZone; 39 39 import java.util.concurrent.TimeUnit; 40 import java.util.stream.Collectors; 40 41 41 42 import javax.swing.AbstractAction; 42 43 import javax.swing.AbstractListModel; 43 44 import javax.swing.BorderFactory; 45 import javax.swing.DefaultComboBoxModel; 44 46 import javax.swing.JButton; 45 47 import javax.swing.JCheckBox; … … 246 248 247 249 private ExtendedDialog syncDialog; 248 private final transient List<GpxDataWrapper> gpxLst = new ArrayList<>();250 private MutableComboBoxModel<GpxDataWrapper> gpxModel; 249 251 private JPanel outerPanel; 250 252 private JosmComboBox<GpxDataWrapper> cbGpx; … … 276 278 try { 277 279 outerPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 278 279 for (int i = gpxLst.size() - 1; i >= 0; i--) { 280 GpxDataWrapper wrapper = gpxLst.get(i); 280 for (int i = gpxModel.getSize() - 1; i >= 0; i--) { 281 GpxDataWrapper wrapper = gpxModel.getElementAt(i); 281 282 if (sel.equals(wrapper.file)) { 282 cbGpx.setSelectedIndex(i);283 gpxModel.setSelectedItem(wrapper); 283 284 if (!sel.getName().equals(wrapper.name)) { 284 285 JOptionPane.showMessageDialog( … … 319 320 } 320 321 321 MutableComboBoxModel<GpxDataWrapper> model = (MutableComboBoxModel<GpxDataWrapper>) cbGpx.getModel();322 322 loadedGpxData.add(data); 323 if (gpxLst.get(0).file == null) { 324 gpxLst.remove(0); 325 model.removeElementAt(0); 323 if (gpxModel.getElementAt(0).file == null) { 324 gpxModel.removeElementAt(0); 326 325 } 327 326 GpxDataWrapper elem = new GpxDataWrapper(sel.getName(), data, sel); 328 gpxLst.add(elem); 329 model.addElement(elem); 330 cbGpx.setSelectedIndex(cbGpx.getItemCount() - 1); 327 gpxModel.addElement(elem); 328 gpxModel.setSelectedItem(elem); 331 329 } finally { 332 330 outerPanel.setCursor(Cursor.getDefaultCursor()); … … 795 793 GpxLayer gpx = (GpxLayer) layer; 796 794 GpxDataWrapper gdw = new GpxDataWrapper(gpx.getName(), gpx.data, gpx.data.storageFile); 797 gpxLst.add(gdw); 798 MutableComboBoxModel<GpxDataWrapper> model = (MutableComboBoxModel<GpxDataWrapper>) cbGpx.getModel(); 799 if (gpxLst.get(0).file == null) { 800 gpxLst.remove(0); 801 model.removeElementAt(0); 795 if (gpxModel.getElementAt(0).file == null) { 796 gpxModel.removeElementAt(0); 802 797 } 803 model.addElement(gdw);798 gpxModel.addElement(gdw); 804 799 } 805 800 } … … 820 815 public void actionPerformed(ActionEvent ae) { 821 816 // Construct the list of loaded GPX tracks 822 gpx Lst.clear();817 gpxModel = new DefaultComboBoxModel<>(); 823 818 GpxDataWrapper defaultItem = null; 824 for (GpxLayer cur : MainApplication.getLayerManager().getLayersOfType(GpxLayer.class) ) {819 for (GpxLayer cur : MainApplication.getLayerManager().getLayersOfType(GpxLayer.class).stream().filter(GpxLayer::isLocalFile).collect(Collectors.toList())) { 825 820 GpxDataWrapper gdw = new GpxDataWrapper(cur.getName(), cur.data, cur.data.storageFile); 826 gpx Lst.add(gdw);827 if (cur == yLayer.gpxLayer ) {821 gpxModel.addElement(gdw); 822 if (cur == yLayer.gpxLayer || (defaultItem == null && gdw.file != null)) { 828 823 defaultItem = gdw; 829 824 } 830 825 } 831 826 for (GpxData data : loadedGpxData) { 832 gpxLst.add(new GpxDataWrapper(data.storageFile.getName(), 833 data, 834 data.storageFile)); 835 } 836 837 if (gpxLst.isEmpty()) { 838 gpxLst.add(new GpxDataWrapper(tr("<No GPX track loaded yet>"), null, null)); 827 GpxDataWrapper gdw = new GpxDataWrapper(data.storageFile.getName(), data, data.storageFile); 828 gpxModel.addElement(gdw); 829 if (defaultItem == null && gdw.file != null) { // select first GPX track associated to a file 830 defaultItem = gdw; 831 } 832 } 833 834 GpxDataWrapper nogdw = new GpxDataWrapper(tr("<No GPX track loaded yet>"), null, null); 835 if (gpxModel.getSize() == 0) { 836 gpxModel.addElement(nogdw); 837 } else if (defaultItem != null) { 838 gpxModel.setSelectedItem(defaultItem); 839 839 } 840 840 … … 843 843 panelCb.add(new JLabel(tr("GPX track: "))); 844 844 845 cbGpx = new JosmComboBox<>(gpxLst.toArray(new GpxDataWrapper[0])); 846 if (defaultItem != null) { 847 cbGpx.setSelectedItem(defaultItem); 848 } else { 849 // select first GPX track associated to a file 850 gpxLst.stream().filter(i -> i.file != null).findFirst().ifPresent(cbGpx::setSelectedItem); 851 } 845 cbGpx = new JosmComboBox<>(gpxModel); 846 cbGpx.setPrototypeDisplayValue(nogdw); 852 847 cbGpx.addActionListener(statusBarUpdaterWithRepaint); 853 848 panelCb.add(cbGpx); … … 1365 1360 1366 1361 private GpxDataWrapper selectedGPX(boolean complain) { 1367 Object item = cbGpx.getSelectedItem();1362 Object item = gpxModel.getSelectedItem(); 1368 1363 1369 1364 if (item == null || ((GpxDataWrapper) item).file == null) {
Note:
See TracChangeset
for help on using the changeset viewer.