Changeset 32528 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationLayer.java
- Timestamp:
- 2016-07-02T03:55:03+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/CalibrationLayer.java
r29434 r32528 1 // License: WTFPL. For details, see LICENSE file. 1 2 package iodb; 2 3 3 import java.awt.*; 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.BasicStroke; 7 import java.awt.Color; 8 import java.awt.Component; 9 import java.awt.Graphics; 10 import java.awt.Graphics2D; 11 import java.awt.Point; 12 import java.awt.RenderingHints; 13 import java.awt.Stroke; 4 14 import java.awt.event.ActionEvent; 5 15 import java.awt.geom.GeneralPath; 6 import javax.swing.*; 16 17 import javax.swing.AbstractAction; 18 import javax.swing.Action; 19 import javax.swing.Icon; 20 7 21 import org.openstreetmap.josm.Main; 8 22 import org.openstreetmap.josm.actions.AutoScaleAction; … … 14 28 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 15 29 import org.openstreetmap.josm.gui.layer.Layer; 16 import static org.openstreetmap.josm.tools.I18n.tr;17 30 import org.openstreetmap.josm.tools.ImageProvider; 18 31 … … 29 42 private LatLon center; 30 43 31 public CalibrationLayer( CalibrationObject obj) {44 public CalibrationLayer(CalibrationObject obj) { 32 45 super(tr("Calibration Layer")); 33 46 color = Color.RED; … … 40 53 */ 41 54 @Override 42 public void paint( Graphics2D g, MapView mv, Bounds box) {55 public void paint(Graphics2D g, MapView mv, Bounds box) { 43 56 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 44 57 Stroke oldStroke = g.getStroke(); … … 46 59 g.setStroke(new BasicStroke(1)); 47 60 LatLon[] geometry = obj.getGeometry(); 48 if (geometry.length == 1) {61 if (geometry.length == 1) { 49 62 // draw crosshair 50 63 Point p = mv.getPoint(geometry[0]); … … 54 67 g.drawLine(p.x, p.y - 10, p.x, p.y - 20); 55 68 g.drawLine(p.x, p.y + 10, p.x, p.y + 20); 56 } else if (geometry.length > 1) {69 } else if (geometry.length > 1) { 57 70 // draw a line 58 71 GeneralPath path = new GeneralPath(); 59 for (int i = 0; i < geometry.length; i++) {72 for (int i = 0; i < geometry.length; i++) { 60 73 Point p = mv.getPoint(geometry[i]); 61 if ( i == 0)74 if (i == 0) 62 75 path.moveTo(p.x, p.y); 63 76 else … … 71 84 @Override 72 85 public Icon getIcon() { 73 if (icon == null)86 if (icon == null) 74 87 icon = ImageProvider.get("calibration_layer"); 75 88 return icon; … … 77 90 78 91 @Override 79 public void mergeFrom( Layer from) {80 } 81 82 @Override 83 public boolean isMergable( Layer other) {92 public void mergeFrom(Layer from) { 93 } 94 95 @Override 96 public boolean isMergable(Layer other) { 84 97 return false; 85 98 } … … 89 102 */ 90 103 @Override 91 public void visitBoundingBox( BoundingXYVisitor v) {92 for (LatLon ll : obj.getGeometry())104 public void visitBoundingBox(BoundingXYVisitor v) { 105 for (LatLon ll : obj.getGeometry()) { 93 106 v.visit(ll); 107 } 94 108 } 95 109 … … 99 113 @Override 100 114 public String getToolTipText() { 101 if (obj.isDeprecated())115 if (obj.isDeprecated()) 102 116 return tr("A deprecated calibration geometry of {0} nodes by {1}", obj.getGeometry().length, obj.getAuthor()); 103 117 else … … 116 130 public Action[] getMenuEntries() { 117 131 return new Action[] { 118 LayerListDialog.getInstance().createShowHideLayerAction(), 119 LayerListDialog.getInstance().createDeleteLayerAction(), 120 SeparatorLayerAction.INSTANCE, 121 new ZoomToLayerAction(), 122 new SelectColorAction(Color.RED), 123 new SelectColorAction(Color.CYAN), 124 new SelectColorAction(Color.YELLOW), 125 SeparatorLayerAction.INSTANCE, 126 new LayerListPopup.InfoAction(this) 132 LayerListDialog.getInstance().createShowHideLayerAction(), 133 LayerListDialog.getInstance().createDeleteLayerAction(), 134 SeparatorLayerAction.INSTANCE, 135 new ZoomToLayerAction(), 136 new SelectColorAction(Color.RED), 137 new SelectColorAction(Color.CYAN), 138 new SelectColorAction(Color.YELLOW), 139 SeparatorLayerAction.INSTANCE, 140 new LayerListPopup.InfoAction(this) 127 141 }; 128 142 } … … 134 148 */ 135 149 public void panToCenter() { 136 if (center == null) {150 if (center == null) { 137 151 LatLon[] geometry = obj.getGeometry(); 138 152 double lat = 0.0; 139 153 double lon = 0.0; 140 for (int i = 0; i < geometry.length; i++) {154 for (int i = 0; i < geometry.length; i++) { 141 155 lon += geometry[i].lon(); 142 156 lat += geometry[i].lat(); … … 155 169 private Color c; 156 170 157 publicSelectColorAction(Color color) {171 SelectColorAction(Color color) { 158 172 super(tr("Change Color")); 159 173 putValue(SMALL_ICON, new SingleColorIcon(color)); … … 161 175 } 162 176 163 public void actionPerformed( ActionEvent e ) { 177 @Override 178 public void actionPerformed(ActionEvent e) { 164 179 color = c; 165 180 Main.map.mapView.repaint(); … … 173 188 private Color color; 174 189 175 publicSingleColorIcon(Color color) {190 SingleColorIcon(Color color) { 176 191 this.color = color; 177 192 } 178 193 179 public void paintIcon( Component c, Graphics g, int x, int y ) { 194 @Override 195 public void paintIcon(Component c, Graphics g, int x, int y) { 180 196 g.setColor(color); 181 197 g.fillRect(x, y, 24, 24); 182 198 } 183 199 200 @Override 184 201 public int getIconWidth() { 185 202 return 24; 186 203 } 187 204 205 @Override 188 206 public int getIconHeight() { 189 207 return 24; 190 208 } 191 192 209 } 193 210 … … 197 214 */ 198 215 class ZoomToLayerAction extends AbstractAction { 199 publicZoomToLayerAction() {216 ZoomToLayerAction() { 200 217 super(tr("Zoom to {0}", tr("layer"))); // to use translation from AutoScaleAction 201 218 putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale/layer")); 202 219 } 203 220 204 public void actionPerformed( ActionEvent e ) { 221 @Override 222 public void actionPerformed(ActionEvent e) { 205 223 AutoScaleAction.autoScale("layer"); 206 224 }
Note:
See TracChangeset
for help on using the changeset viewer.
