Changeset 28624 in osm for applications/editors/josm/plugins/measurement/src/org
- Timestamp:
- 2012-08-24T13:41:33+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java
r28589 r28624 32 32 * @author ramack 33 33 */ 34 public class MeasurementDialog extends ToggleDialog { 34 public class MeasurementDialog extends ToggleDialog implements SelectionChangedListener { 35 35 private static final long serialVersionUID = 4708541586297950021L; 36 36 … … 59 59 */ 60 60 protected JLabel segAngleLabel; 61 61 62 62 /** 63 63 * Constructor … … 112 112 resetButton 113 113 })); 114 115 final MeasurementDialog dlg = this; 116 117 DataSet.addSelectionListener(new SelectionChangedListener() { 118 @Override 119 public void selectionChanged(Collection<? extends OsmPrimitive> arg0) { 120 double length = 0.0; 121 double segAngle = 0.0; 122 double area = 0.0; 123 Node lastNode = null; 124 for(OsmPrimitive p:arg0) { 125 // ignore incomplete nodes 126 if(p instanceof Node && !((Node)p).isIncomplete()) { 127 Node n =(Node)p; 128 if(lastNode == null) { 129 lastNode = n; 130 } else { 131 length += lastNode.getCoor().greatCircleDistance(n.getCoor()); 132 segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor()); 133 lastNode = n; 134 } 135 } else if (p instanceof Way) { 136 Way w = (Way)p; 137 Node lastN = null; 138 for (Node n: w.getNodes()) { 139 if (lastN != null && lastN.getCoor() != null && n.getCoor() != null) { 140 length += lastN.getCoor().greatCircleDistance(n.getCoor()); 141 //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ 142 area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor())) 143 - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor())); 144 segAngle = MeasurementLayer.angleBetween(lastN.getCoor(), n.getCoor()); 145 } 146 lastN = n; 147 } 148 if (lastN != null && lastN == w.getNodes().iterator().next()) 149 area = Math.abs(area / 2); 150 else 151 area = 0; 152 } 153 } 154 dlg.selectLengthLabel.setText(new DecimalFormat("#0.00").format(length) + " m"); 155 156 dlg.segAngleLabel.setText(new DecimalFormat("#0.0").format(segAngle) + " \u00b0"); 157 dlg.selectAreaLabel.setText(new DecimalFormat("#0.00").format(area) + " m\u00b2"); 158 } 159 }); 114 115 DataSet.addSelectionListener(this); 160 116 } 161 117 … … 166 122 MeasurementPlugin.getCurrentLayer().reset(); 167 123 } 124 125 @Override 126 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 127 double length = 0.0; 128 double segAngle = 0.0; 129 double area = 0.0; 130 Node lastNode = null; 131 for (OsmPrimitive p : newSelection) { 132 // ignore incomplete nodes 133 if (p instanceof Node && !((Node)p).isIncomplete()) { 134 Node n =(Node)p; 135 if (lastNode == null) { 136 lastNode = n; 137 } else { 138 length += lastNode.getCoor().greatCircleDistance(n.getCoor()); 139 segAngle = MeasurementLayer.angleBetween(lastNode.getCoor(), n.getCoor()); 140 lastNode = n; 141 } 142 } else if (p instanceof Way) { 143 Way w = (Way)p; 144 Node lastN = null; 145 for (Node n: w.getNodes()) { 146 if (lastN != null && lastN.getCoor() != null && n.getCoor() != null) { 147 length += lastN.getCoor().greatCircleDistance(n.getCoor()); 148 //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ 149 area += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor())) 150 - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor())); 151 segAngle = MeasurementLayer.angleBetween(lastN.getCoor(), n.getCoor()); 152 } 153 lastN = n; 154 } 155 if (lastN != null && lastN == w.getNodes().iterator().next()) 156 area = Math.abs(area / 2); 157 else 158 area = 0; 159 } 160 } 161 selectLengthLabel.setText(new DecimalFormat("#0.00").format(length) + " m"); 162 segAngleLabel.setText(new DecimalFormat("#0.0").format(segAngle) + " \u00b0"); 163 selectAreaLabel.setText(new DecimalFormat("#0.00").format(area) + " m\u00b2"); 164 } 165 166 /* (non-Javadoc) 167 * @see org.openstreetmap.josm.gui.dialogs.ToggleDialog#destroy() 168 */ 169 @Override 170 public void destroy() { 171 super.destroy(); 172 DataSet.removeSelectionListener(this); 173 } 168 174 } -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java
r25137 r28624 141 141 DecimalFormat nf = new DecimalFormat("#0.00"); 142 142 DecimalFormat nf2 = new DecimalFormat("#0.0"); 143 MeasurementPlugin.measurementDialog.pathLengthLabel.setText(pathLength < 800?nf2.format(pathLength) + " m":nf.format(pathLength/1000) + " km"); 143 if (MeasurementPlugin.measurementDialog != null) { 144 MeasurementPlugin.measurementDialog.pathLengthLabel.setText(pathLength < 800?nf2.format(pathLength) + " m":nf.format(pathLength/1000) + " km"); 145 } 144 146 } 145 147 -
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java
r23193 r28624 21 21 public MeasurementPlugin(PluginInformation info) { 22 22 super(info); 23 mode = new MeasurementMode(Main.map, "measurement", tr("measurement mode"));24 btn = new IconToggleButton(mode);25 btn.setVisible(true);26 measurementDialog = new MeasurementDialog();27 23 } 28 24 29 25 @Override 30 26 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 31 if(newFrame != null) 32 newFrame.addToggleDialog(measurementDialog); 33 if(Main.map != null) 34 Main.map.addMapMode(btn); 27 if (newFrame != null) { 28 newFrame.addToggleDialog(measurementDialog = new MeasurementDialog()); 29 mode = new MeasurementMode(newFrame, "measurement", tr("measurement mode")); 30 btn = new IconToggleButton(mode); 31 btn.setVisible(true); 32 newFrame.addMapMode(btn); 33 } else { 34 btn = null; 35 mode = null; 36 measurementDialog = null; 37 } 35 38 } 36 39 37 public static MeasurementLayer getCurrentLayer(){ 38 if(currentLayer == null){ 40 public static MeasurementLayer getCurrentLayer() { 41 if (currentLayer == null) { 39 42 currentLayer = new MeasurementLayer(tr("Measurements")); 40 43 Main.main.addLayer(currentLayer);
Note:
See TracChangeset
for help on using the changeset viewer.