Ticket #16543: directdownload.patch
File directdownload.patch, 8.1 KB (added by , 6 years ago) |
---|
-
src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.util.ArrayList; 8 import java.util.HashMap; 7 9 8 10 import org.openstreetmap.josm.Main; 9 11 import org.openstreetmap.josm.actions.JosmAction; 10 12 import org.openstreetmap.josm.data.gpx.GpxData; 13 import org.openstreetmap.josm.data.gpx.GpxTrack; 14 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 15 import org.openstreetmap.josm.data.gpx.GpxConstants; 16 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 11 17 import org.openstreetmap.josm.gui.MainApplication; 12 18 import org.openstreetmap.josm.gui.MainMenu; 13 19 import org.openstreetmap.josm.gui.layer.GpxLayer; … … 16 22 import org.openstreetmap.josm.plugins.PluginInformation; 17 23 18 24 public class DirectDownload extends Plugin { 25 19 26 private DownloadAction openaction; 20 27 21 28 /** … … 41 48 DownloadDataGui go = new DownloadDataGui(); 42 49 go.setVisible(true); 43 50 44 UserTrack track = go.getSelectedUserTrack();51 ArrayList<UserTrack> tracks = go.getSelectedUserTracks(); 45 52 46 if (!((go.getValue() == 1) && (track != null))) {53 if (!((go.getValue() == 1) && (tracks != null))) { 47 54 return; 48 55 } 49 56 50 final GpxData data = new GpxServerReader().loadGpx(Long.parseLong(track.id)); 51 if (data == null) { 52 return; 53 } 54 final GpxLayer gpxLayer = new GpxLayer(data); 57 for (UserTrack track: tracks) { 55 58 56 if (data.hasRoutePoints() || data.hasTrackPoints()) { 57 MainApplication.getLayerManager().addLayer(gpxLayer); 58 } 59 GpxData data = new GpxServerReader().loadGpx(Long.parseLong(track.id)); 60 if (data == null) { 61 return; 62 } 59 63 60 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) { 61 MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer); 62 if (ml.data.size() > 0) { 63 MainApplication.getLayerManager().addLayer(ml); 64 for (GpxTrack trk : data.getTracks()) { 65 HashMap<String, Object> attrib = new HashMap<String, Object>(trk.getAttributes()); 66 if (!trk.getAttributes().containsKey(GpxConstants.GPX_NAME)) { 67 System.out.println(track.filename); 68 attrib.put(GpxConstants.GPX_NAME, track.filename); 69 } 70 if (!trk.getAttributes().containsKey(GpxConstants.GPX_DESC)) { 71 System.out.println(track.description); 72 attrib.put(GpxConstants.GPX_DESC, track.description); 73 } 74 // replace the existing trace in the unmodifiable tracks 75 data.removeTrack(trk); 76 trk = new ImmutableGpxTrack(new ArrayList<GpxTrackSegment>(trk.getSegments()), attrib); 77 data.addTrack(trk); 64 78 } 79 80 final GpxLayer gpxLayer = new GpxLayer(data, (track.filename + " " + track.description).trim()); 81 82 if (data.hasRoutePoints() || data.hasTrackPoints()) { 83 MainApplication.getLayerManager().addLayer(gpxLayer); 84 } 85 86 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) { 87 MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer); 88 if (ml.data.size() > 0) { 89 MainApplication.getLayerManager().addLayer(ml); 90 } 91 } 65 92 } 66 93 } 67 94 } -
src/org/openstreetmap/josm/plugins/directdownload/DownloadDataGui.java
47 47 columnmodel = new NamedResultTableColumnModel(); 48 48 tblSearchResults = new JTable(model, columnmodel); 49 49 tblSearchResults.setSelectionModel(selectionModel); 50 tblSearchResults.setSelectionMode(ListSelectionModel. SINGLE_SELECTION);50 tblSearchResults.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 51 51 JScrollPane scrollPane = new JScrollPane(tblSearchResults); 52 scrollPane.setPreferredSize(new Dimension(800, 300));52 scrollPane.setPreferredSize(new Dimension(800, 300)); 53 53 panel.add(scrollPane, BorderLayout.CENTER); 54 54 55 55 model.setData(new UserTrackReader().getTrackList()); … … 83 83 if (data == null) { 84 84 this.data.clear(); 85 85 } else { 86 this.data =new ArrayList<>(data);86 this.data = new ArrayList<>(data); 87 87 } 88 88 fireTableDataChanged(); 89 89 } 90 90 91 public ArrayList<UserTrack> getDataArrayList() { 92 return data; 93 } 94 91 95 @Override 92 96 public boolean isCellEditable(int row, int column) { 93 97 return false; … … 100 104 } 101 105 } 102 106 107 public ArrayList<UserTrack> getSelectedUserTracks() { 108 ArrayList<UserTrack> DataArray = model.getDataArrayList(); 109 int[] selected = tblSearchResults.getSelectedRows(); 110 ArrayList<UserTrack> selectedTracks = new ArrayList<>(selected.length); 111 for (int i = 0; i < selected.length; i++) { 112 selectedTracks.add(DataArray.get(selected[i])); 113 } 114 return selectedTracks; 115 } 116 103 117 public UserTrack getSelectedUserTrack() { 104 118 return model.getSelectedUserTrack(); 105 119 } … … 134 148 addColumn(col); 135 149 136 150 // column 3 - tags 137 /* 151 138 152 col = new TableColumn(3); 139 153 col.setHeaderValue(tr("Tags")); 140 154 col.setResizable(true); … … 141 155 col.setPreferredWidth(100); 142 156 col.setCellRenderer(renderer); 143 157 addColumn(col); 144 */ 158 145 159 } 146 160 147 161 public NamedResultTableColumnModel() { … … 153 167 154 168 public NamedResultCellRenderer() { 155 169 setOpaque(true); 156 setBorder(BorderFactory.createEmptyBorder(2, 2,2,2));170 setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); 157 171 } 158 172 159 173 protected void reset() { … … 172 186 } 173 187 174 188 @Override 175 189 public Component getTableCellRendererComponent(JTable table, Object value, 176 190 boolean isSelected, boolean hasFocus, int row, int column) { 177 191 178 192 reset(); … … 190 204 case 2: 191 205 setText(sr.description); 192 206 break; 193 /* 207 194 208 case 3: 195 209 setText(sr.tags); 196 210 break; 197 */ 211 198 212 } 199 213 return this; 200 214 } -
src/org/openstreetmap/josm/plugins/directdownload/UserTrackReader.java
89 89 if (qName.equals("description")) { 90 90 data.getFirst().description = cdata; 91 91 } 92 /* 92 93 93 else if (qName.equals("tag")) { 94 data.getFirst().tags = cdata;95 cdata = new String();94 data.getFirst().tags = cdata; 95 cdata = new String(); 96 96 } 97 */ 97 98 98 } 99 99 100 100 public List<UserTrack> getResult() {