Changeset 32263 in osm for applications/editors/josm/plugins/editgpx/src/org
- Timestamp:
- 2016-06-15T14:46:51+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
r30634 r32263 38 38 private GPXLayerImportAction layerImport; 39 39 40 public EditGpxLayer(String str, EditGpxData gpxData) { 41 super(str); 40 /** 41 * Constructs a new {@code EditGpxLayer}. 42 * @param gpxData edit gpx data 43 */ 44 public EditGpxLayer(EditGpxData gpxData) { 45 super(tr("EditGpx")); 42 46 data = gpxData; 43 47 layerImport = new GPXLayerImportAction(data); … … 49 53 */ 50 54 public void initializeImport() { 51 try { 52 if (data.isEmpty()) { 53 layerImport.activateImport(); 54 } 55 } catch (Exception e) { 56 Main.error(e); 55 if (data.isEmpty()) { 56 layerImport.activateImport(); 57 57 } 58 58 } … … 116 116 } 117 117 118 119 118 public void reset(){ 120 119 //TODO implement a reset 121 120 } 122 123 121 124 122 @Override … … 126 124 // TODO Auto-generated method stub 127 125 } 128 129 126 130 127 /** … … 142 139 */ 143 140 public class ConvertToGpxLayerAction extends AbstractAction { 141 /** 142 * Constructs a new {@code ConvertToGpxLayerAction}. 143 */ 144 144 public ConvertToGpxLayerAction() { 145 145 super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx")); … … 147 147 @Override 148 148 public void actionPerformed(ActionEvent e) { 149 if (Main.map.mapMode instanceof EditGpxMode) { 150 if (!Main.map.selectSelectTool(false)) { 151 Main.map.selectZoomTool(false); // Select tool might not be support of active layer, zoom is always supported 152 } 149 if (Main.map.mapMode instanceof EditGpxMode && !Main.map.selectSelectTool(false)) { 150 Main.map.selectZoomTool(false); // Select tool might not be support of active layer, zoom is always supported 153 151 } 154 152 Main.main.addLayer(new GpxLayer(toGpxData(false), tr("Converted from: {0}", getName()))); … … 161 159 */ 162 160 public class ConvertToAnonTimeGpxLayerAction extends AbstractAction { 161 /** 162 * Constructs a new {@code ConvertToAnonTimeGpxLayerAction}. 163 */ 163 164 public ConvertToAnonTimeGpxLayerAction() { 164 165 super(tr("Convert to GPX layer with anonymised time"), ImageProvider.get("converttogpx")); … … 166 167 @Override 167 168 public void actionPerformed(ActionEvent e) { 168 if (Main.map.mapMode instanceof EditGpxMode) { 169 if (!Main.map.selectSelectTool(false)) { 170 Main.map.selectZoomTool(false); // Select tool might not be support of active layer, zoom is always supported 171 } 169 if (Main.map.mapMode instanceof EditGpxMode && !Main.map.selectSelectTool(false)) { 170 Main.map.selectZoomTool(false); // Select tool might not be support of active layer, zoom is always supported 172 171 } 173 172 Main.main.addLayer(new GpxLayer(toGpxData(true), tr("Converted from: {0}", getName()))); -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
r32223 r32263 18 18 import org.openstreetmap.josm.actions.mapmode.MapMode; 19 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; 20 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 21 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 22 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 23 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 23 24 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 24 25 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxData; … … 31 32 private static final long serialVersionUID = 7940589057093872411L; 32 33 Point pointPressed; 33 MapFrame mapFrame; 34 private final MapFrame mapFrame; 34 35 Rectangle oldRect; 35 MapFrame frame; 36 EditGpxLayer currentEditLayer; 36 transient EditGpxLayer currentEditLayer; 37 37 38 public EditGpxMode(MapFrame mapFrame, String name, String desc) { 39 super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 38 /** 39 * Constructs a new {@code EditGpxMode}. 40 * @param mapFrame map frame 41 */ 42 public EditGpxMode(MapFrame mapFrame) { 43 super("editgpx", "editgpx_mode.png", tr("edit gpx tracks"), Main.map, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 44 this.mapFrame = mapFrame; 40 45 } 41 46 … … 45 50 Main.map.mapView.addMouseListener(this); 46 51 Main.map.mapView.addMouseMotionListener(this); 47 Ma pView.addLayerChangeListener(this);52 Main.map.mapView.getLayerManager().addLayerChangeListener(this); 48 53 updateLayer(); 49 54 } … … 54 59 Main.map.mapView.removeMouseListener(this); 55 60 Main.map.mapView.removeMouseMotionListener(this); 56 Ma pView.removeLayerChangeListener(this);61 Main.map.mapView.getLayerManager().removeLayerChangeListener(this); 57 62 } 58 63 … … 78 83 requestFocusInMapView(); 79 84 80 Point pointReleased = e.getPoint(); 81 82 Rectangle r = createRect(pointReleased, pointPressed); 85 Rectangle r = createRect(e.getPoint(), pointPressed); 83 86 84 87 //go through nodes and mark the ones in the selection rect as deleted … … 133 136 */ 134 137 private void paintRect(Point p1, Point p2) { 135 if ( frame != null) {136 Graphics g = frame.getGraphics();138 if (mapFrame != null) { 139 Graphics g = mapFrame.getGraphics(); 137 140 138 141 Rectangle r = oldRect; … … 152 155 } 153 156 154 public void setFrame(MapFrame mapFrame) {155 frame = mapFrame;156 }157 158 157 /** 159 158 * create new layer, add listeners and try importing gpx data. … … 161 160 private void updateLayer() { 162 161 163 List<EditGpxLayer> layers = Main.map.mapView.getLayersOfType(EditGpxLayer.class); 164 currentEditLayer = layers.isEmpty() ?null:layers.get(0);162 List<EditGpxLayer> layers = Main.map.mapView.getLayerManager().getLayersOfType(EditGpxLayer.class); 163 currentEditLayer = layers.isEmpty() ? null : layers.get(0); 165 164 166 165 if(currentEditLayer == null) { 167 currentEditLayer = new EditGpxLayer( tr("EditGpx"),new EditGpxData());166 currentEditLayer = new EditGpxLayer(new EditGpxData()); 168 167 Main.main.addLayer(currentEditLayer); 169 168 currentEditLayer.initializeImport(); … … 172 171 } 173 172 174 public void activeLayerChange(Layer oldLayer, Layer newLayer) { } 173 @Override 174 public void layerAdded(LayerAddEvent e) { 175 // Do nothing 176 } 175 177 176 public void layerAdded(Layer newLayer) { } 177 178 public void layerRemoved(Layer oldLayer) { 179 if (oldLayer instanceof EditGpxLayer) { 178 @Override 179 public void layerRemoving(LayerRemoveEvent e) { 180 if (e.getRemovedLayer() instanceof EditGpxLayer) { 180 181 currentEditLayer = null; 181 182 if (Main.map.mapMode instanceof EditGpxMode) { 182 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) { 183 if (Main.map.mapView.getLayerManager().getActiveLayer() instanceof OsmDataLayer) { 183 184 Main.map.selectSelectTool(false); 184 185 } else { … … 190 191 191 192 @Override 192 public void destroy() { 193 super.destroy(); 194 MapView.removeLayerChangeListener(this); 193 public void layerOrderChanged(LayerOrderChangeEvent e) { 194 // Do nothing 195 195 } 196 196 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java
r28612 r32263 3 3 */ 4 4 package org.openstreetmap.josm.plugins.editgpx; 5 6 import static org.openstreetmap.josm.tools.I18n.tr;7 8 import java.net.URL;9 5 10 6 import javax.swing.ImageIcon; … … 26 22 * - BUG: when importing eGpxLayer is shown as RawGpxLayer?? 27 23 * - implement reset if user made mistake while marking 28 *29 *30 24 */ 31 25 public class EditGpxPlugin extends Plugin { 32 26 33 private IconToggleButton btn; 34 private EditGpxMode mode; 35 27 /** 28 * Constructs a new {@code EditGpxPlugin}. 29 * @param info plugin information 30 */ 36 31 public EditGpxPlugin(PluginInformation info) { 37 32 super(info); 38 mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"));39 40 btn = new IconToggleButton(mode);41 btn.setVisible(true);42 33 } 43 34 … … 47 38 @Override 48 39 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 49 mode.setFrame(newFrame);50 if (oldFrame == null &&newFrame!= null) {40 if (newFrame != null) { 41 EditGpxMode mode = new EditGpxMode(newFrame); 51 42 if (Main.map != null) 52 Main.map.addMapMode( btn);43 Main.map.addMapMode(new IconToggleButton(mode)); 53 44 } 54 45 } 55 46 56 47 public static ImageIcon loadIcon(String name) { 57 URL url = EditGpxPlugin.class.getResource("/images/editgpx.png"); 58 return new ImageIcon(url); 48 return new ImageIcon(EditGpxPlugin.class.getResource("/images/editgpx.png")); 59 49 } 60 50 } -
applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/GPXLayerImportAction.java
r30634 r32263 11 11 import java.awt.Component; 12 12 import java.awt.event.ActionEvent; 13 import java.util.Collection;14 13 15 14 import javax.swing.AbstractAction; … … 53 52 54 53 final JList<GpxLayer> layerList = new JList<>(dModel); 55 Collection<Layer> data = Main.map.mapView.getAllLayers();56 54 int layerCnt = 0; 57 55 58 for (Layer l : data){59 if(l instanceof GpxLayer){ 56 for (Layer l : Main.map.mapView.getLayerManager().getLayers()){ 57 if (l instanceof GpxLayer){ 60 58 dModel.addElement((GpxLayer) l); 61 59 layerCnt++; … … 65 63 layerList.setSelectionInterval(0, layerCnt-1); 66 64 layerList.setCellRenderer(new DefaultListCellRenderer(){ 67 @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 65 @Override 66 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 68 67 Layer layer = (Layer)value; 69 68 JLabel label = (JLabel)super.getListCellRendererComponent(list, … … 114 113 /** 115 114 * called when pressing "Import.." from context menu of EditGpx layer 116 *117 115 */ 116 @Override 118 117 public void actionPerformed(ActionEvent arg0) { 119 118 activateImport();
Note:
See TracChangeset
for help on using the changeset viewer.