Changeset 29384 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
- Timestamp:
- 2013-03-22T22:18:26+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29382 r29384 5 5 import javax.swing.ImageIcon; 6 6 import javax.swing.JButton; 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.coor.EastNorth; 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.projection.Projection; 7 11 import org.openstreetmap.josm.gui.layer.ImageryLayer; 8 12 import org.openstreetmap.josm.tools.ImageProvider; 9 13 10 14 /** 11 * A button which shows offset information. 15 * A button which shows offset information. Must be spectacular, since it's the only 16 * non-JOptionPane GUI in the plugin. 12 17 * 13 * @author zverik 18 * @author Zverik 19 * @license WTFPL 14 20 */ 15 21 public class OffsetDialogButton extends JButton { … … 20 26 private double direction; 21 27 28 /** 29 * Initialize the button with an offset. Calculated all relevant values. 30 * @param offset An offset to display on the button. 31 */ 22 32 public OffsetDialogButton( ImageryOffsetBase offset ) { 23 33 super(); … … 49 59 } 50 60 61 /** 62 * Returns the offset associated with this button. 63 */ 51 64 public ImageryOffsetBase getOffset() { 52 65 return offset; … … 69 82 } 70 83 84 /** 85 * Calculates length and direction for two points in the imagery offset object. 86 * @see #getLengthAndDirection(iodb.ImageryOffset, double, double) 87 */ 71 88 private double[] getLengthAndDirection( ImageryOffset offset ) { 72 89 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 73 90 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()}; 74 return ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);91 return getLengthAndDirection(offset, dxy[0], dxy[1]); 75 92 } 76 93 94 /** 95 * Calculates length and direction for two points in the imagery offset object 96 * taking into account an existing imagery layer offset. 97 * 98 * @see #getLengthAndDirection(iodb.ImageryOffset) 99 */ 100 public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) { 101 Projection proj = Main.getProjection(); 102 EastNorth pos = proj.latlon2eastNorth(offset.getPosition()); 103 LatLon correctedCenterLL = proj.eastNorth2latlon(pos.add(-dx, -dy)); 104 double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos()); 105 double direction = length < 1e-2 ? 0.0 : correctedCenterLL.heading(offset.getImageryPos()); 106 // todo: north vs south. Meanwhile, let's fix this dirty: 107 // direction = Math.PI - direction; 108 if( direction < 0 ) 109 direction += Math.PI * 2; 110 return new double[] {length, direction}; 111 } 112 113 /** 114 * An offset icon. Displays a plain calibration icon for a geometry 115 * and an arrow for an imagery offset. 116 */ 77 117 class OffsetIcon implements Icon { 78 118 private boolean isDeprecated; … … 82 122 private ImageIcon background; 83 123 124 /** 125 * Initialize the icon with an offset object. Calculates length and direction 126 * of an arrow if they're needed. 127 */ 84 128 public OffsetIcon( ImageryOffsetBase offset ) { 85 129 isDeprecated = offset.isDeprecated(); … … 89 133 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 90 134 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] { layer.getDx(), layer.getDy() }; 91 double[] ld = ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);135 double[] ld = getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 92 136 length = ld[0]; 93 137 direction = ld[1]; … … 97 141 } 98 142 143 /** 144 * Paints the base image and adds to it according to the offset. 145 */ 99 146 public void paintIcon( Component comp, Graphics g, int x, int y ) { 100 147 background.paintIcon(comp, g, x, y); … … 110 157 } else { 111 158 // draw an arrow 112 double arrowLength = length < 5? getIconWidth() / 2 - 1 : getIconWidth() - 4;159 double arrowLength = length < 10 ? getIconWidth() / 2 - 1 : getIconWidth() - 4; 113 160 g2.setStroke(new BasicStroke(2)); 114 161 int dx = (int)Math.round(Math.sin(direction) * arrowLength / 2);
Note:
See TracChangeset
for help on using the changeset viewer.
