Changeset 30641 in osm for applications
- Timestamp:
- 2014-09-15T03:01:38+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java
r30353 r30641 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.measurement; 2 3 -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java
r30532 r30641 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.measurement; 2 3 /// @author Raphael Mack <ramack@raphael-mack.de> … … 46 47 public class MeasurementLayer extends Layer { 47 48 48 public MeasurementLayer(String arg0) {49 super( arg0);49 public MeasurementLayer(String name) { 50 super(name); 50 51 } 51 52 … … 53 54 private Collection<WayPoint> points = new ArrayList<WayPoint>(32); 54 55 55 @Override public Icon getIcon() { 56 @Override 57 public Icon getIcon() { 56 58 return icon; 57 59 } 58 60 59 @Override public String getToolTipText() { 61 @Override 62 public String getToolTipText() { 60 63 return tr("Layer to make measurements"); 61 64 } 62 65 63 @Override public boolean isMergable(Layer other) { 66 @Override 67 public boolean isMergable(Layer other) { 64 68 //return other instanceof MeasurementLayer; 65 69 return false; 66 70 } 67 71 68 @Override public void mergeFrom(Layer from) { 72 @Override 73 public void mergeFrom(Layer from) { 69 74 // TODO: nyi - doubts about how this should be done are around. Ideas? 70 71 } 72 73 @Overridepublic void paint(Graphics2D g, final MapView mv, Bounds bounds) {75 } 76 77 @Override 78 public void paint(Graphics2D g, final MapView mv, Bounds bounds) { 74 79 g.setColor(Color.green); 75 80 Point l = null; … … 84 89 } 85 90 86 @Override public void visitBoundingBox(BoundingXYVisitor v) { 91 @Override 92 public void visitBoundingBox(BoundingXYVisitor v) { 87 93 // nothing to do here 88 94 } 89 95 90 @Override public Object getInfoComponent() { 96 @Override 97 public Object getInfoComponent() { 91 98 return getToolTipText(); 92 99 } 93 100 94 @Override public Action[] getMenuEntries() { 101 @Override 102 public Action[] getMenuEntries() { 95 103 return new Action[]{ 96 104 LayerListDialog.getInstance().createShowHideLayerAction(), … … 141 149 MeasurementPlugin.measurementDialog.pathLengthLabel.setText(NavigatableComponent.getDistText(pathLength)); 142 150 } 151 if (Main.map.mapMode instanceof MeasurementMode) { 152 Main.map.statusLine.setDist(pathLength); 153 } 143 154 } 144 155 … … 207 218 private class GPXLayerImportAction extends AbstractAction { 208 219 209 /**210 * The data model for the list component.211 */212 private DefaultListModel<GpxLayer> model = new DefaultListModel<>();213 214 /**215 * @param layer the targeting measurement layer216 */217 public GPXLayerImportAction(MeasurementLayer layer) {218 super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit")); // TODO: find better image219 }220 221 @Override222 public void actionPerformed(ActionEvent e) {223 Box panel = Box.createVerticalBox();224 final JList<GpxLayer> layerList = new JList<>(model);225 Collection<Layer> data = Main.map.mapView.getAllLayers();226 Layer lastLayer = null;227 int layerCnt = 0;228 229 for (Layer l : data){230 if (l instanceof GpxLayer){220 /** 221 * The data model for the list component. 222 */ 223 private DefaultListModel<GpxLayer> model = new DefaultListModel<>(); 224 225 /** 226 * @param layer the targeting measurement layer 227 */ 228 public GPXLayerImportAction(MeasurementLayer layer) { 229 super(tr("Import path from GPX layer"), ImageProvider.get("dialogs", "edit")); // TODO: find better image 230 } 231 232 @Override 233 public void actionPerformed(ActionEvent e) { 234 Box panel = Box.createVerticalBox(); 235 final JList<GpxLayer> layerList = new JList<>(model); 236 Collection<Layer> data = Main.map.mapView.getAllLayers(); 237 Layer lastLayer = null; 238 int layerCnt = 0; 239 240 for (Layer l : data) { 241 if (l instanceof GpxLayer) { 231 242 model.addElement((GpxLayer) l); 232 243 lastLayer = l; 233 244 layerCnt++; 234 245 } 235 }236 if(layerCnt == 1){246 } 247 if (layerCnt == 1) { 237 248 layerList.setSelectedValue(lastLayer, true); 238 249 } 239 if(layerCnt > 0){ 240 250 if (layerCnt > 0) { 241 251 layerList.setCellRenderer(new DefaultListCellRenderer(){ 242 @Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 243 Layer layer = (Layer)value; 244 JLabel label = (JLabel)super.getListCellRendererComponent(list, 245 layer.getName(), index, isSelected, cellHasFocus); 246 Icon icon = layer.getIcon(); 247 label.setIcon(icon); 248 label.setToolTipText(layer.getToolTipText()); 249 return label; 250 } 251 }); 252 252 @Override 253 public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 254 Layer layer = (Layer)value; 255 JLabel label = (JLabel)super.getListCellRendererComponent(list, 256 layer.getName(), index, isSelected, cellHasFocus); 257 Icon icon = layer.getIcon(); 258 label.setIcon(icon); 259 label.setToolTipText(layer.getToolTipText()); 260 return label; 261 } 262 }); 263 253 264 JCheckBox dropFirst = new JCheckBox(tr("Drop existing path")); 254 265 255 266 panel.add(layerList); 256 267 panel.add(dropFirst); 257 268 258 269 final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 259 @Override public void selectInitialValue() { 270 @Override 271 public void selectInitialValue() { 260 272 layerList.requestFocusInWindow(); 261 273 } … … 263 275 final JDialog dlg = optionPane.createDialog(Main.parent, tr("Import path from GPX layer")); 264 276 dlg.setVisible(true); 265 277 266 278 Object answer = optionPane.getValue(); 267 279 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE || … … 269 281 return; 270 282 } 271 283 272 284 GpxLayer gpx = (GpxLayer)layerList.getSelectedValue(); 273 if (dropFirst.isSelected()){285 if (dropFirst.isSelected()) { 274 286 points = new ArrayList<WayPoint>(32); 275 287 } … … 281 293 } 282 294 } 283 }295 } 284 296 recalculate(); 285 297 Main.parent.repaint(); 286 } else{298 } else{ 287 299 // TODO: register a listener and show menu entry only if gps layers are available 288 300 // no gps layer -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java
r13497 r30641 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.measurement; 2 3 … … 16 17 17 18 private static final long serialVersionUID = 3853830673475744263L; 18 19 19 20 public MeasurementMode(MapFrame mapFrame, String name, String desc) { 20 21 super(name, "measurement.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); 21 22 } 22 23 23 @Override public void enterMode() { 24 @Override 25 public void enterMode() { 24 26 super.enterMode(); 25 27 Main.map.mapView.addMouseListener(this); 26 28 } 27 29 28 @Override public void exitMode() { 30 @Override 31 public void exitMode() { 29 32 super.exitMode(); 30 33 Main.map.mapView.removeMouseListener(this); … … 39 42 * was part of. 40 43 */ 41 @Override public void mouseClicked(MouseEvent e) { 44 @Override 45 public void mouseClicked(MouseEvent e) { 42 46 if (e.getButton() == MouseEvent.BUTTON3){ 43 47 MeasurementPlugin.getCurrentLayer().removeLastPoint(); 44 } else if (e.getButton() == MouseEvent.BUTTON1){48 } else if (e.getButton() == MouseEvent.BUTTON1){ 45 49 LatLon coor = Main.map.mapView.getLatLon(e.getX(), e.getY()); 46 50 if (coor.isOutSideWorld()) { … … 51 55 } 52 56 } 53 54 57 } -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java
r30353 r30641 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.measurement; 2 3 /// @author Raphael Mack <osm@raphael-mack.de>
Note:
See TracChangeset
for help on using the changeset viewer.