Changeset 29382 in osm for applications/editors/josm/plugins/imagery_offset_db
- Timestamp:
- 2013-03-21T21:30:58+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetPlugin.java
r29377 r29382 26 26 offsetMenu.add(getAction); 27 27 offsetMenu.add(storeAction); 28 29 // todo: add a button on toolbar30 // todo: make MapMode for viewing and updating imagery offsets (is it needed?)31 28 } 32 29 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java
r29380 r29382 176 176 Projection proj = Main.getProjection(); 177 177 EastNorth pos = proj.latlon2eastNorth(offset.getPosition()); 178 LatLon correctedCenterLL = proj.eastNorth2latlon(pos.add( dx,dy));178 LatLon correctedCenterLL = proj.eastNorth2latlon(pos.add(-dx, -dy)); 179 179 double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos()); 180 180 double direction = length < 1e-2 ? 0.0 : correctedCenterLL.heading(offset.getImageryPos()); 181 181 // todo: north vs south. Meanwhile, let's fix this dirty: 182 direction = Math.PI - direction;182 // direction = Math.PI - direction; 183 183 if( direction < 0 ) 184 184 direction += Math.PI * 2; -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29380 r29382 11 11 import javax.swing.border.EmptyBorder; 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.Bounds; 13 14 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 15 import org.openstreetmap.josm.gui.MapView; 14 16 import org.openstreetmap.josm.gui.NavigatableComponent; 15 17 import org.openstreetmap.josm.gui.layer.ImageryLayer; 18 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 16 19 import static org.openstreetmap.josm.tools.I18n.tr; 17 20 import org.openstreetmap.josm.tools.ImageProvider; … … 23 26 * @author zverik 24 27 */ 25 public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener {28 public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener, MapViewPaintable { 26 29 protected static final String PREF_CALIBRATION = "iodb.show.calibration"; 27 30 protected static final String PREF_DEPRECATED = "iodb.show.deprecated"; … … 106 109 } 107 110 pack(); 111 Main.map.mapView.repaint(); 108 112 } 109 113 … … 131 135 } 132 136 } 137 138 public void paint( Graphics2D g, MapView mv, Bounds bbox ) { 139 if( offsets == null ) 140 return; 141 142 Graphics2D g2 = (Graphics2D)g.create(); 143 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 144 g2.setStroke(new BasicStroke(2)); 145 for( ImageryOffsetBase offset : filterOffsets() ) { 146 Point p = mv.getPoint(offset.getPosition()); 147 g2.setColor(Color.BLACK); 148 g2.fillOval(p.x - 2, p.y - 2, 5, 5); 149 g2.setColor(Color.WHITE); 150 g2.drawOval(p.x - 3, p.y - 3, 7, 7); 151 } 152 } 133 153 134 154 public ImageryOffsetBase showDialog() { 155 // todo: add a temporary layer showing all offsets 135 156 selectedOffset = null; 136 157 prepareDialog(); 158 if( !MODAL ) { 159 Main.map.mapView.addTemporaryLayer(this); 160 Main.map.mapView.repaint(); 161 } 137 162 setVisible(true); 138 163 return selectedOffset; … … 173 198 NavigatableComponent.removeZoomChangeListener(this); 174 199 setVisible(false); 175 if( !MODAL && selectedOffset != null ) 176 applyOffset(); 200 if( !MODAL ) { 201 Main.map.mapView.removeTemporaryLayer(this); 202 Main.map.mapView.repaint(); 203 if( selectedOffset != null ) 204 applyOffset(); 205 } 177 206 } 178 207 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29380 r29382 1 1 package iodb; 2 2 3 import java.awt.Component; 4 import java.awt.Dimension; 5 import java.awt.Graphics; 3 import java.awt.*; 6 4 import javax.swing.Icon; 7 5 import javax.swing.ImageIcon; … … 25 23 super(); 26 24 this.offset = offset; 27 setMinimumSize(new Dimension(500, 10));28 setMaximumSize(new Dimension(500, 150));25 // setMinimumSize(new Dimension(500, 10)); 26 // setMaximumSize(new Dimension(500, 150)); 29 27 setRelevantText(); 30 28 setIcon(new OffsetIcon(offset)); … … 32 30 offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0; 33 31 // todo: layout, info, map distance and direction 32 // http://stackoverflow.com/questions/1048224/get-height-of-multi-line-text-with-fixed-width-to-make-dialog-resize-properly 33 // http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html#size 34 // http://stackoverflow.com/questions/8012646/setting-size-of-jbutton-inside-jpanel-with-boxlayout-doesnt-work-as-expected 35 // http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/ 36 // http://thebadprogrammer.com/swing-layout-manager-sizing/ 37 // http://stackoverflow.com/questions/3692987/why-will-boxlayout-not-allow-me-to-change-the-width-of-a-jbutton-but-let-me-chan 38 39 // http://stackoverflow.com/questions/2158/creating-a-custom-button-in-java 34 40 } 35 41 … … 38 44 */ 39 45 public void setRelevantText() { 40 setText("<html> "46 setText("<html><div style=\"width: 400px;\">" 41 47 + ImageryOffsetTools.formatDistance(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) 42 + ": " + offset.getDescription() + "</ html>");48 + ": " + offset.getDescription() + "</div></html>"); 43 49 } 44 50 … … 47 53 } 48 54 49 @Override55 /* @Override 50 56 public Dimension getPreferredSize() { 51 57 Dimension size = super.getPreferredSize(); … … 53 59 size.height = 70; 54 60 return size; 55 } 61 }*/ 56 62 57 63 /** … … 72 78 private boolean isDeprecated; 73 79 private boolean isCalibration; 74 private double direction ;80 private double direction = -1.0; 75 81 private double length; 76 82 private ImageIcon background; … … 91 97 } 92 98 93 public void paintIcon( Component c, Graphics g, int x, int y ) { 94 background.paintIcon(c, g, x, y); 95 // todo: draw an arrow 96 // todo: apply deprecation 99 public void paintIcon( Component comp, Graphics g, int x, int y ) { 100 background.paintIcon(comp, g, x, y); 101 102 Graphics2D g2 = (Graphics2D)g.create(); 103 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 104 if( direction >= 0 ) { 105 g2.setColor(Color.black); 106 Point c = new Point(x + getIconWidth() / 2, y + getIconHeight() / 2); 107 if( length < 1e-2 ) { 108 // no offset 109 g2.fillOval(c.x - 3, c.y - 3, 7, 7); 110 } else { 111 // draw an arrow 112 double arrowLength = length < 5 ? getIconWidth() / 2 - 1 : getIconWidth() - 4; 113 g2.setStroke(new BasicStroke(2)); 114 int dx = (int)Math.round(Math.sin(direction) * arrowLength / 2); 115 int dy = (int)Math.round(Math.cos(direction) * arrowLength / 2); 116 g2.drawLine(c.x - dx, c.y - dy, c.x + dx, c.y + dy); 117 double wingLength = arrowLength / 3; 118 double d1 = direction - Math.PI / 6; 119 int dx1 = (int)Math.round(Math.sin(d1) * wingLength); 120 int dy1 = (int)Math.round(Math.cos(d1) * wingLength); 121 g2.drawLine(c.x + dx, c.y + dy, c.x + dx - dx1, c.y + dy - dy1); 122 double d2 = direction + Math.PI / 6; 123 int dx2 = (int)Math.round(Math.sin(d2) * wingLength); 124 int dy2 = (int)Math.round(Math.cos(d2) * wingLength); 125 g2.drawLine(c.x + dx, c.y + dy, c.x + dx - dx2, c.y + dy - dy2); 126 } 127 } 128 if( isDeprecated ) { 129 // big red X 130 g2.setColor(Color.red); 131 g2.setStroke(new BasicStroke(5, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); 132 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f)); 133 g2.drawLine(x + 2, y + 2, x + getIconWidth() - 2, y + getIconHeight() - 2); 134 g2.drawLine(x + 2, y + getIconHeight() - 2, x + getIconWidth() - 2, y + 2); 135 } 97 136 } 98 137 -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
r29381 r29382 34 34 StringBuilder sb = new StringBuilder(); 35 35 if( offset instanceof ImageryOffset ) { 36 double [] ld = ImageryOffsetTools.getLengthAndDirection((ImageryOffset)offset);37 sb.append( ld[0] < 1e-2 ? tr("An imagery offset of 0 mm") : tr("An imagery offset of {0} to {1}",38 ImageryOffsetTools.formatDistance( ld[0]), explainDirection(ld[1]))).append('\n');36 double odist = ((ImageryOffset)offset).getImageryPos().greatCircleDistance(offset.getPosition()); 37 sb.append(odist < 1e-2 ? tr("An imagery offset of 0 mm") : tr("An imagery offset of {0}", 38 ImageryOffsetTools.formatDistance(odist))).append('\n'); 39 39 sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery()).append('\n'); 40 40 } else { … … 43 43 44 44 double dist = ImageryOffsetTools.getMapCenter().greatCircleDistance(offset.getPosition()); 45 double heading = dist < 10 ? 0.0 : ImageryOffsetTools.getMapCenter().heading(offset.getPosition()); 46 sb.append(dist < 50 ? tr("Determined right here") : tr("Determined at a point {0} to the {1}", 47 ImageryOffsetTools.formatDistance(dist), explainDirection(heading))); 45 sb.append(dist < 50 ? tr("Determined right here") : tr("Determined at a point {0} away", 46 ImageryOffsetTools.formatDistance(dist))); 48 47 49 48 sb.append('\n').append('\n'); … … 75 74 return "geometry"; 76 75 } 77 78 public static String explainDirection( double dir ) {79 dir = dir * 8 / Math.PI;80 if( dir < 1 || dir >= 15 ) return tr("north");81 if( dir < 3 ) return tr("northeast");82 if( dir < 5 ) return tr("east");83 if( dir < 7 ) return tr("southeast");84 if( dir < 9 ) return tr("south");85 if( dir < 11 ) return tr("southwest");86 if( dir < 13 ) return tr("west");87 if( dir < 15 ) return tr("northwest");88 return "nowhere";89 }90 76 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java
r29381 r29382 40 40 return; 41 41 } 42 if( userName.indexOf('@') > 0 ) 43 userName = userName.replace('@', ','); 42 44 43 45 // check if an object suitable for calibration is selected
Note:
See TracChangeset
for help on using the changeset viewer.