Changeset 21474 in osm for applications/editors/josm/plugins
- Timestamp:
- 2010-05-27T21:07:52+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
r21472 r21474 38 38 39 39 private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png"))); 40 p rivatefinal EditGpxData data;40 public final EditGpxData data; 41 41 private GPXLayerImportAction layerImport; 42 42 -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
r21472 r21474 3 3 */ 4 4 package org.openstreetmap.josm.plugins.editgpx; 5 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 7 6 8 import java.awt.Color; … … 11 13 import java.awt.event.InputEvent; 12 14 import java.awt.event.MouseEvent; 15 import java.util.List; 13 16 14 17 import org.openstreetmap.josm.Main; 15 18 import org.openstreetmap.josm.actions.mapmode.MapMode; 16 19 import org.openstreetmap.josm.gui.MapFrame; 20 import org.openstreetmap.josm.gui.MapView; 21 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 22 import org.openstreetmap.josm.gui.layer.Layer; 17 23 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxData; 18 24 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxTrack; … … 21 27 22 28 23 public class EditGpxMode extends MapMode {29 public class EditGpxMode extends MapMode implements LayerChangeListener { 24 30 25 31 private static final long serialVersionUID = 7940589057093872411L; 26 32 Point pointPressed; 27 EditGpxData data;28 33 MapFrame mapFrame; 29 34 Rectangle oldRect; 30 35 MapFrame frame; 36 EditGpxLayer currentEditLayer; 31 37 32 public EditGpxMode(MapFrame mapFrame, String name, String desc , EditGpxData gpxData) {38 public EditGpxMode(MapFrame mapFrame, String name, String desc) { 33 39 super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 34 this.data = gpxData;35 40 } 36 41 … … 39 44 Main.map.mapView.addMouseListener(this); 40 45 Main.map.mapView.addMouseMotionListener(this); 46 MapView.addLayerChangeListener(this); 47 updateLayer(); 41 48 } 42 49 … … 63 70 if (e.getButton() != MouseEvent.BUTTON1) { 64 71 return; 65 } else { 66 Point pointReleased = e.getPoint(); 72 } 67 73 68 Rectangle r = createRect(pointReleased, pointPressed);74 Point pointReleased = e.getPoint(); 69 75 70 //go through nodes and mark the ones in the selection rect as deleted 71 for (EditGpxTrack track: data.getTracks()) { 76 Rectangle r = createRect(pointReleased, pointPressed); 77 78 //go through nodes and mark the ones in the selection rect as deleted 79 if (currentEditLayer != null) { 80 for (EditGpxTrack track: currentEditLayer.data.getTracks()) { 72 81 for (EditGpxTrackSegment segment: track.getSegments()) { 73 82 for (EditGpxWayPoint wayPoint: segment.getWayPoints()) { … … 79 88 } 80 89 } 81 oldRect = null;82 Main.map.mapView.repaint();83 90 } 91 oldRect = null; 92 Main.map.mapView.repaint(); 93 84 94 } 85 95 … … 139 149 frame = mapFrame; 140 150 } 151 152 /** 153 * create new layer, add listeners and try importing gpx data. 154 */ 155 private void updateLayer() { 156 157 List<EditGpxLayer> layers = Main.map.mapView.getLayersOfType(EditGpxLayer.class); 158 currentEditLayer = layers.isEmpty()?null:layers.get(0); 159 160 if(currentEditLayer == null) { 161 currentEditLayer = new EditGpxLayer(tr("EditGpx"), new EditGpxData()); 162 Main.main.addLayer(currentEditLayer); 163 currentEditLayer.initializeImport(); 164 } 165 Main.map.mapView.repaint(); 166 } 167 168 public void activeLayerChange(Layer oldLayer, Layer newLayer) { } 169 170 public void layerAdded(Layer newLayer) { } 171 172 public void layerRemoved(Layer oldLayer) { 173 if (oldLayer instanceof EditGpxLayer) { 174 currentEditLayer = null; 175 } 176 } 177 141 178 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java
r21472 r21474 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.awt.event.ActionEvent;9 import java.awt.event.ActionListener;10 8 import java.net.URL; 11 9 … … 15 13 import org.openstreetmap.josm.gui.IconToggleButton; 16 14 import org.openstreetmap.josm.gui.MapFrame; 17 import org.openstreetmap.josm.gui.MapView;18 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;19 import org.openstreetmap.josm.gui.layer.Layer;20 15 import org.openstreetmap.josm.plugins.Plugin; 21 16 import org.openstreetmap.josm.plugins.PluginInformation; 22 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxData;23 17 24 18 /** … … 40 34 private IconToggleButton btn; 41 35 private EditGpxMode mode; 42 protected static EditGpxLayer eGpxLayer;43 protected static EditGpxData gpxData;44 public static boolean active = false;45 36 46 37 public EditGpxPlugin(PluginInformation info) { 47 38 super(info); 48 gpxData = new EditGpxData(); 49 mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"), gpxData); 39 mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks")); 50 40 51 41 btn = new IconToggleButton(mode); … … 63 53 if(Main.map != null) 64 54 Main.map.addMapMode(btn); 65 66 active = btn.isSelected();67 68 btn.addActionListener(new ActionListener() {69 public void actionPerformed(ActionEvent e) {70 active = btn.isSelected();71 if (active) {72 Main.worker.execute(new Runnable() {73 public void run() {74 updateLayer();75 }76 });77 }78 }79 });80 55 } 81 }82 83 /**84 * create new layer, add listeners and try importing gpx data.85 */86 private void updateLayer() {87 if(eGpxLayer == null) {88 eGpxLayer = new EditGpxLayer(tr("EditGpx"), gpxData);89 Main.main.addLayer(eGpxLayer);90 MapView.addLayerChangeListener(new LayerChangeListener(){91 92 public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {93 if(newLayer instanceof EditGpxLayer)94 EditGpxPlugin.eGpxLayer = (EditGpxLayer)newLayer;95 }96 97 public void layerAdded(final Layer newLayer) {98 }99 100 public void layerRemoved(final Layer oldLayer) {101 if(oldLayer == eGpxLayer) {102 eGpxLayer = null;103 //dataSet = new DataSet();104 MapView.removeLayerChangeListener(this);105 }106 }107 });108 109 eGpxLayer.initializeImport();110 }111 Main.map.mapView.repaint();112 56 } 113 57
Note:
See TracChangeset
for help on using the changeset viewer.