Changeset 19683 in osm
- Timestamp:
- 2010-01-30T20:15:37+01:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/editgpx
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/editgpx/.classpath
r18426 r19683 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" path="src-common"/>4 <classpathentry excluding="src/" including="images/" kind="src" path=""/> 5 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JDK 5"/> 6 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> -
applications/editors/josm/plugins/editgpx/build.xml
r19434 r19683 29 29 30 30 <property name="commit.message" value="Changed constructor signature of plugin main class" /> 31 <property name="plugin.main.version" value="2 830" />31 <property name="plugin.main.version" value="2907" /> 32 32 33 33 -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
r18962 r19683 13 13 import java.awt.event.ActionEvent; 14 14 import java.util.ArrayList; 15 import java.util.Collection; 15 16 import java.util.Date; 17 import java.util.HashMap; 16 18 import java.util.HashSet; 19 import java.util.Iterator; 20 import java.util.List; 21 import java.util.Map; 17 22 18 23 import javax.swing.AbstractAction; … … 25 30 import org.openstreetmap.josm.data.Bounds; 26 31 import org.openstreetmap.josm.data.gpx.GpxData; 27 import org.openstreetmap.josm.data.gpx. GpxTrack;32 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 28 33 import org.openstreetmap.josm.data.gpx.WayPoint; 29 34 import org.openstreetmap.josm.data.osm.DataSet; … … 42 47 public class EditGpxLayer extends Layer { 43 48 44 private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png"))); 45 private DataSet dataSet; 46 private GPXLayerImportAction layerImport; 47 48 public EditGpxLayer(String str, DataSet ds) { 49 super(str); 50 dataSet = ds; 51 layerImport = new GPXLayerImportAction(dataSet); 52 } 53 54 /** 55 * check if dataSet is empty 56 * if so show import dialog to user 57 */ 58 public void initializeImport() { 59 try { 60 if(dataSet.getNodes().isEmpty() ) { 61 layerImport.activateImport(); 62 } 63 } catch (Exception e) { 64 System.out.println(e.getMessage()); 65 e.printStackTrace(); 66 } 67 } 68 69 @Override 70 public Icon getIcon() { 71 return icon; 72 } 73 74 @Override 75 public Object getInfoComponent() { 76 return getToolTipText(); 77 } 78 79 @Override 80 public Component[] getMenuEntries() { 81 return new Component[] { 82 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 83 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), 84 new JSeparator(), 85 new JMenuItem(layerImport), 86 new JMenuItem(new ConvertToGpxLayerAction()), 87 new JMenuItem(new ConvertToAnonTimeGpxLayerAction()), 88 new JSeparator(), 89 new JMenuItem(new LayerListPopup.InfoAction(this))}; 90 } 91 92 @Override 93 public String getToolTipText() { 94 return tr("Layer for editing GPX tracks"); 95 } 96 97 @Override 98 public boolean isMergable(Layer other) { 99 // TODO 100 return false; 101 } 102 103 @Override 104 public void mergeFrom(Layer from) { 105 // TODO 106 } 107 108 @Override 109 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 110 g.setColor(Color.yellow); 111 112 //don't iterate through dataSet whiling making changes 113 synchronized(layerImport.importing) { 114 for(Node n: dataSet.getNodes()) { 115 if (!n.isDeleted()) { 116 Point pnt = Main.map.mapView.getPoint(n.getEastNorth()); 117 g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4); 118 } 119 } 120 } 121 } 122 123 124 public void reset(){ 125 //TODO implement a reset 126 } 127 128 129 @Override 130 public void visitBoundingBox(BoundingXYVisitor v) { 131 // TODO Auto-generated method stub 132 } 133 134 135 /** 136 * convert a DataSet to GPX 137 * 138 * @param boolean anonTime If true set all time and date in GPX to 01/01/1970 00:00 ? 139 * @return GPXData 140 */ 141 private GpxData toGpxData(boolean anonTime) { 142 GpxData gpxData = new GpxData(); 143 HashSet<Node> doneNodes = new HashSet<Node>(); 144 //add all ways 145 for (Way w : dataSet.getWays()) { 146 if (w.isIncomplete() || w.isDeleted()) continue; 147 GpxTrack trk = new GpxTrack(); 148 gpxData.tracks.add(trk); 149 150 if (w.get("name") != null) 151 trk.attr.put("name", w.get("name")); 152 153 ArrayList<WayPoint> trkseg = null; 154 for (Node n : w.getNodes()) { 155 if (n.isIncomplete() || n.isDeleted()) { 156 trkseg = null; 157 continue; 158 } 159 160 Date tstamp = n.getTimestamp(); 161 162 if (trkseg == null) { 163 trkseg = new ArrayList<WayPoint>(); 164 trk.trackSegs.add(trkseg); 165 } 166 doneNodes.add(n); 167 168 WayPoint wpt = new WayPoint(n.getCoor()); 169 if (anonTime) { 170 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 171 } else { 172 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 173 } 174 wpt.setTime(); 175 176 trkseg.add(wpt); 177 } 178 } 179 180 // add nodes as waypoints 181 for (Node n : dataSet.getNodes()) { 182 if (n.isIncomplete() || n.isDeleted() || doneNodes.contains(n)) continue; 183 184 Date tstamp = n.getTimestamp(); 185 186 WayPoint wpt = new WayPoint(n.getCoor()); 187 if (anonTime) { 188 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 189 } else { 190 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 191 } 192 wpt.setTime(); 193 194 if (n.getKeys() != null && n.keySet().contains("name")) { 195 wpt.attr.put("name", n.get("name")); 196 } 197 gpxData.waypoints.add(wpt); 198 } 199 return gpxData; 200 } 201 202 //context item "Convert to GPX layer" 203 public class ConvertToGpxLayerAction extends AbstractAction { 204 public ConvertToGpxLayerAction() { 205 super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx")); 206 } 207 public void actionPerformed(ActionEvent e) { 208 Main.main.addLayer(new GpxLayer(toGpxData(false), tr("Converted from: {0}", getName()))); 209 Main.main.removeLayer(EditGpxLayer.this); 210 } 211 } 212 213 //context item "Convert to GPX layer with anonymised time" 214 public class ConvertToAnonTimeGpxLayerAction extends AbstractAction { 215 public ConvertToAnonTimeGpxLayerAction() { 216 super(tr("Convert to GPX layer with anonymised time"), ImageProvider.get("converttogpx")); 217 } 218 public void actionPerformed(ActionEvent e) { 219 Main.main.addLayer(new GpxLayer(toGpxData(true), tr("Converted from: {0}", getName()))); 220 Main.main.removeLayer(EditGpxLayer.this); 221 } 222 } 49 private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png"))); 50 private DataSet dataSet; 51 private GPXLayerImportAction layerImport; 52 53 public EditGpxLayer(String str, DataSet ds) { 54 super(str); 55 dataSet = ds; 56 layerImport = new GPXLayerImportAction(dataSet); 57 } 58 59 /** 60 * check if dataSet is empty 61 * if so show import dialog to user 62 */ 63 public void initializeImport() { 64 try { 65 if(dataSet.getNodes().isEmpty() ) { 66 layerImport.activateImport(); 67 } 68 } catch (Exception e) { 69 System.out.println(e.getMessage()); 70 e.printStackTrace(); 71 } 72 } 73 74 @Override 75 public Icon getIcon() { 76 return icon; 77 } 78 79 @Override 80 public Object getInfoComponent() { 81 return getToolTipText(); 82 } 83 84 @Override 85 public Component[] getMenuEntries() { 86 return new Component[] { 87 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)), 88 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)), 89 new JSeparator(), 90 new JMenuItem(layerImport), 91 new JMenuItem(new ConvertToGpxLayerAction()), 92 new JMenuItem(new ConvertToAnonTimeGpxLayerAction()), 93 new JSeparator(), 94 new JMenuItem(new LayerListPopup.InfoAction(this))}; 95 } 96 97 @Override 98 public String getToolTipText() { 99 return tr("Layer for editing GPX tracks"); 100 } 101 102 @Override 103 public boolean isMergable(Layer other) { 104 // TODO 105 return false; 106 } 107 108 @Override 109 public void mergeFrom(Layer from) { 110 // TODO 111 } 112 113 @Override 114 public void paint(Graphics2D g, MapView mv, Bounds bounds) { 115 g.setColor(Color.yellow); 116 117 //don't iterate through dataSet whiling making changes 118 synchronized(layerImport.importing) { 119 for(Node n: dataSet.getNodes()) { 120 if (!n.isDeleted()) { 121 Point pnt = Main.map.mapView.getPoint(n.getEastNorth()); 122 g.drawOval(pnt.x - 2, pnt.y - 2, 4, 4); 123 } 124 } 125 } 126 } 127 128 129 public void reset(){ 130 //TODO implement a reset 131 } 132 133 134 @Override 135 public void visitBoundingBox(BoundingXYVisitor v) { 136 // TODO Auto-generated method stub 137 } 138 139 140 /** 141 * convert a DataSet to GPX 142 * 143 * @param boolean anonTime If true set all time and date in GPX to 01/01/1970 00:00 ? 144 * @return GPXData 145 */ 146 private GpxData toGpxData(boolean anonTime) { 147 GpxData gpxData = new GpxData(); 148 HashSet<Node> doneNodes = new HashSet<Node>(); 149 //add all ways 150 for (Way w : dataSet.getWays()) { 151 if (w.isIncomplete() || w.isDeleted()) continue; 152 List<Collection<WayPoint>> segments = new ArrayList<Collection<WayPoint>>(); 153 154 List<WayPoint> trkseg = null; 155 for (Node n : w.getNodes()) { 156 if (n.isIncomplete() || n.isDeleted()) { 157 trkseg = null; 158 continue; 159 } 160 161 Date tstamp = n.getTimestamp(); 162 163 if (trkseg == null) { 164 trkseg = new ArrayList<WayPoint>(); 165 segments.add(trkseg); 166 } 167 doneNodes.add(n); 168 169 WayPoint wpt = new WayPoint(n.getCoor()); 170 if (anonTime) { 171 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 172 } else { 173 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 174 } 175 wpt.setTime(); 176 177 trkseg.add(wpt); 178 } 179 180 // Do not create empty segments 181 for (Iterator<Collection<WayPoint>> segIt = segments.iterator(); segIt.hasNext(); ) { 182 if (segIt.next().isEmpty()) { 183 segIt.remove(); 184 } 185 } 186 187 Map<String, Object> trkAttributes = new HashMap<String, Object>(); 188 if (w.get("name") != null) { 189 trkAttributes.put("name", w.get("name")); 190 } 191 if (!segments.isEmpty()) { 192 gpxData.tracks.add(new ImmutableGpxTrack(segments, trkAttributes)); 193 } 194 195 } 196 197 // add nodes as waypoints 198 for (Node n : dataSet.getNodes()) { 199 if (n.isIncomplete() || n.isDeleted() || doneNodes.contains(n)) continue; 200 201 Date tstamp = n.getTimestamp(); 202 203 WayPoint wpt = new WayPoint(n.getCoor()); 204 if (anonTime) { 205 wpt.attr.put("time", "1970-01-01T00:00:00Z"); 206 } else { 207 wpt.attr.put("time", DateUtils.fromDate(tstamp)); 208 } 209 wpt.setTime(); 210 211 if (n.getKeys() != null && n.keySet().contains("name")) { 212 wpt.attr.put("name", n.get("name")); 213 } 214 gpxData.waypoints.add(wpt); 215 } 216 return gpxData; 217 } 218 219 //context item "Convert to GPX layer" 220 public class ConvertToGpxLayerAction extends AbstractAction { 221 public ConvertToGpxLayerAction() { 222 super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx")); 223 } 224 public void actionPerformed(ActionEvent e) { 225 Main.main.addLayer(new GpxLayer(toGpxData(false), tr("Converted from: {0}", getName()))); 226 Main.main.removeLayer(EditGpxLayer.this); 227 } 228 } 229 230 //context item "Convert to GPX layer with anonymised time" 231 public class ConvertToAnonTimeGpxLayerAction extends AbstractAction { 232 public ConvertToAnonTimeGpxLayerAction() { 233 super(tr("Convert to GPX layer with anonymised time"), ImageProvider.get("converttogpx")); 234 } 235 public void actionPerformed(ActionEvent e) { 236 Main.main.addLayer(new GpxLayer(toGpxData(true), tr("Converted from: {0}", getName()))); 237 Main.main.removeLayer(EditGpxLayer.this); 238 } 239 } 223 240 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
r18426 r19683 9 9 import java.awt.Point; 10 10 import java.awt.Rectangle; 11 import java.awt.event.InputEvent; 11 12 import java.awt.event.MouseEvent; 12 13 … … 51 52 52 53 @Override public void mouseDragged(MouseEvent e) { 53 if ( (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {54 if ( (e.getModifiersEx() & InputEvent.BUTTON1_DOWN_MASK) == InputEvent.BUTTON1_DOWN_MASK) { 54 55 //if button1 is hold, draw the rectangle. 55 56 paintRect(pointPressed, e.getPoint()); -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java
r18426 r19683 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.data.gpx.GpxTrack; 28 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; 28 29 import org.openstreetmap.josm.data.gpx.WayPoint; 29 30 import org.openstreetmap.josm.data.osm.DataSet; … … 112 113 synchronized(importing) { 113 114 for (GpxTrack trk : gpx.data.tracks) { 114 for ( Collection<WayPoint> segment : trk.trackSegs) {115 for (GpxTrackSegment segment : trk.getSegments()) { 115 116 Way w = new Way(); 116 for (WayPoint p : segment ) {117 for (WayPoint p : segment.getWayPoints()) { 117 118 Node n = new Node(p.getCoor()); 118 119 String timestr = p.getString("time");
Note:
See TracChangeset
for help on using the changeset viewer.