Changeset 29386 in osm
- Timestamp:
- 2013-03-23T09:45:46+01:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/imagery_offset_db/src/iodb
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29384 r29386 192 192 */ 193 193 public ImageryOffsetBase showDialog() { 194 // todo: add a temporary layer showing all offsets195 194 selectedOffset = null; 196 195 prepareDialog(); -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
r29384 r29386 2 2 3 3 import java.awt.*; 4 import javax.swing.Icon; 5 import javax.swing.ImageIcon; 6 import javax.swing.JButton; 4 import javax.swing.*; 7 5 import org.openstreetmap.josm.Main; 8 6 import org.openstreetmap.josm.data.coor.EastNorth; … … 11 9 import org.openstreetmap.josm.gui.layer.ImageryLayer; 12 10 import org.openstreetmap.josm.tools.ImageProvider; 11 import static org.openstreetmap.josm.tools.I18n.tr; 13 12 14 13 /** … … 22 21 23 22 private ImageryOffsetBase offset; 24 private double offsetLength; 25 private double distance;26 private double direction;23 24 private JLabel distanceLabel; 25 private DirectionIcon directionArrow; 27 26 28 27 /** … … 31 30 */ 32 31 public OffsetDialogButton( ImageryOffsetBase offset ) { 33 super();34 32 this.offset = offset; 35 // setMinimumSize(new Dimension(500, 10)); 36 // setMaximumSize(new Dimension(500, 150)); 37 setRelevantText(); 38 setIcon(new OffsetIcon(offset)); 39 40 offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0; 41 // todo: layout, info, map distance and direction 42 // http://stackoverflow.com/questions/1048224/get-height-of-multi-line-text-with-fixed-width-to-make-dialog-resize-properly 43 // http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html#size 44 // http://stackoverflow.com/questions/8012646/setting-size-of-jbutton-inside-jpanel-with-boxlayout-doesnt-work-as-expected 45 // http://blog.nobel-joergensen.com/2009/01/18/changing-preferred-size-of-a-html-jlabel/ 46 // http://thebadprogrammer.com/swing-layout-manager-sizing/ 47 // http://stackoverflow.com/questions/3692987/why-will-boxlayout-not-allow-me-to-change-the-width-of-a-jbutton-but-let-me-chan 48 49 // http://stackoverflow.com/questions/2158/creating-a-custom-button-in-java 50 } 51 52 /** 53 * Update text on the button. This method is to be deleted by release. 54 */ 55 public void setRelevantText() { 56 setText("<html><div style=\"width: 400px;\">" 57 + ImageryOffsetTools.formatDistance(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) 58 + ": " + offset.getDescription() + "</div></html>"); 33 layoutComponents(); 59 34 } 60 35 … … 66 41 } 67 42 68 /* @Override69 public Dimension getPreferredSize() {70 Dimension size = super.getPreferredSize();71 size.width = 500;72 size.height = 70;73 return size;74 }*/75 76 43 /** 77 44 * Update arrow for the offset location. 78 45 */ 79 46 public void updateLocation() { 80 // map was moved, update arrow. 81 setRelevantText(); 47 LatLon center = ImageryOffsetTools.getMapCenter(); 48 directionArrow.updateIcon(center); 49 double distance = center.greatCircleDistance(offset.getPosition()); 50 distanceLabel.setText(ImageryOffsetTools.formatDistance(distance)); 51 } 52 53 /** 54 * Adds a layout to this button and places labels, images and icons. 55 */ 56 private void layoutComponents() { 57 String authorAndDate = offset.isDeprecated() 58 ? tr("Deprecated by {0} on {1}\n", offset.getAbandonAuthor(), 59 OffsetInfoAction.DATE_FORMAT.format(offset.getAbandonDate())) 60 : tr("Created by {0} on {1}\n", offset.getAuthor(), 61 OffsetInfoAction.DATE_FORMAT.format(offset.getDate())); 62 JLabel authorAndDateLabel = new JLabel(authorAndDate); 63 Font authorFont = new Font(authorAndDateLabel.getFont().getName(), Font.ITALIC, authorAndDateLabel.getFont().getSize()); 64 authorAndDateLabel.setFont(authorFont); 65 66 directionArrow = new DirectionIcon(offset.getPosition()); 67 distanceLabel = new JLabel("", directionArrow, SwingConstants.RIGHT); 68 distanceLabel.setHorizontalTextPosition(SwingConstants.LEFT); 69 Font distanceFont = new Font(distanceLabel.getFont().getName(), Font.PLAIN, distanceLabel.getFont().getSize()); 70 distanceLabel.setFont(distanceFont); 71 updateLocation(); 72 73 String description = offset.isDeprecated() ? offset.getAbandonReason() : offset.getDescription(); 74 JLabel descriptionLabel = new JLabel("<html><div style=\"width: 300px;\">"+description+"</div></html>"); 75 76 double offsetDistance = offset instanceof ImageryOffset 77 ? ((ImageryOffset)offset).getImageryPos().greatCircleDistance(offset.getPosition()) : 0.0; 78 JLabel offsetLabel = new JLabel(offsetDistance > 1 ? ImageryOffsetTools.formatDistance(offsetDistance) : "", 79 new OffsetIcon(offset), SwingConstants.CENTER); 80 Font offsetFont = new Font(offsetLabel.getFont().getName(), Font.PLAIN, offsetLabel.getFont().getSize() - 2); 81 offsetLabel.setFont(offsetFont); 82 offsetLabel.setHorizontalTextPosition(SwingConstants.CENTER); 83 offsetLabel.setVerticalTextPosition(SwingConstants.BOTTOM); 84 85 Box topLine = new Box(BoxLayout.X_AXIS); 86 topLine.add(authorAndDateLabel); 87 topLine.add(Box.createHorizontalGlue()); 88 topLine.add(distanceLabel); 89 90 JPanel p = new JPanel(new BorderLayout(10, 5)); 91 p.setOpaque(false); 92 p.add(topLine, BorderLayout.NORTH); 93 p.add(offsetLabel, BorderLayout.WEST); 94 p.add(descriptionLabel, BorderLayout.CENTER); 95 add(p); 82 96 } 83 97 … … 104 118 double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos()); 105 119 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 120 if( direction < 0 ) 109 121 direction += Math.PI * 2; … … 111 123 } 112 124 125 private static void drawArrow( Graphics g, int cx, int cy, double length, double direction ) { 126 int dx = (int)Math.round(Math.sin(direction) * length / 2); 127 int dy = (int)Math.round(Math.cos(direction) * length / 2); 128 g.drawLine(cx - dx, cy - dy, cx + dx, cy + dy); 129 double wingLength = Math.max(length / 3, 4); 130 double d1 = direction - Math.PI / 6; 131 int dx1 = (int)Math.round(Math.sin(d1) * wingLength); 132 int dy1 = (int)Math.round(Math.cos(d1) * wingLength); 133 g.drawLine(cx + dx, cy + dy, cx + dx - dx1, cy + dy - dy1); 134 double d2 = direction + Math.PI / 6; 135 int dx2 = (int)Math.round(Math.sin(d2) * wingLength); 136 int dy2 = (int)Math.round(Math.cos(d2) * wingLength); 137 g.drawLine(cx + dx, cy + dy, cx + dx - dx2, cy + dy - dy2); 138 } 139 113 140 /** 114 141 * An offset icon. Displays a plain calibration icon for a geometry 115 142 * and an arrow for an imagery offset. 116 143 */ 117 class OffsetIcon implements Icon {144 private class OffsetIcon implements Icon { 118 145 private boolean isDeprecated; 119 146 private boolean isCalibration; … … 131 158 if( offset instanceof ImageryOffset ) { 132 159 background = ImageProvider.get("offset"); 133 ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer(); 134 double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] { layer.getDx(), layer.getDy() }; 135 double[] ld = getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]); 160 double[] ld = getLengthAndDirection((ImageryOffset)offset); 136 161 length = ld[0]; 137 162 direction = ld[1]; … … 159 184 double arrowLength = length < 10 ? getIconWidth() / 2 - 1 : getIconWidth() - 4; 160 185 g2.setStroke(new BasicStroke(2)); 161 int dx = (int)Math.round(Math.sin(direction) * arrowLength / 2); 162 int dy = (int)Math.round(Math.cos(direction) * arrowLength / 2); 163 g2.drawLine(c.x - dx, c.y - dy, c.x + dx, c.y + dy); 164 double wingLength = arrowLength / 3; 165 double d1 = direction - Math.PI / 6; 166 int dx1 = (int)Math.round(Math.sin(d1) * wingLength); 167 int dy1 = (int)Math.round(Math.cos(d1) * wingLength); 168 g2.drawLine(c.x + dx, c.y + dy, c.x + dx - dx1, c.y + dy - dy1); 169 double d2 = direction + Math.PI / 6; 170 int dx2 = (int)Math.round(Math.sin(d2) * wingLength); 171 int dy2 = (int)Math.round(Math.cos(d2) * wingLength); 172 g2.drawLine(c.x + dx, c.y + dy, c.x + dx - dx2, c.y + dy - dy2); 186 drawArrow(g2, c.x, c.y, arrowLength, direction); 173 187 } 174 188 } … … 191 205 } 192 206 } 207 208 private class DirectionIcon implements Icon { 209 private static final int SIZE = 10; 210 211 private LatLon to; 212 private double distance; 213 private double direction; 214 215 public DirectionIcon( LatLon to ) { 216 this.to = to; 217 } 218 219 public void updateIcon( LatLon from ) { 220 distance = from.greatCircleDistance(to); 221 direction = to.heading(from); 222 } 223 224 /** 225 * Paints the base image and adds to it according to the offset. 226 */ 227 public void paintIcon( Component comp, Graphics g, int x, int y ) { 228 Graphics2D g2 = (Graphics2D)g.create(); 229 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 230 g2.setColor(Color.black); 231 Point c = new Point(x + getIconWidth() / 2, y + getIconHeight() / 2); 232 if( distance < 1 ) { 233 // no offset 234 int r = 2; 235 g2.fillOval(c.x - r, c.y - r, r * 2 + 1, r * 2 + 1); 236 } else { 237 // draw an arrow 238 g2.setStroke(new BasicStroke(1)); 239 drawArrow(g2, c.x, c.y, SIZE, direction); 240 } 241 } 242 243 public int getIconWidth() { 244 return SIZE; 245 } 246 247 public int getIconHeight() { 248 return SIZE; 249 } 250 } 193 251 } -
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetInfoAction.java
r29384 r29386 58 58 59 59 sb.append('\n').append('\n'); 60 sb.append( "Created by ").append(offset.getAuthor());61 sb.append(" on ").append(DATE_FORMAT.format(offset.getDate())).append('\n');60 sb.append(tr("Created by {0} on {1}\n", offset.getAuthor(), 61 DATE_FORMAT.format(offset.getDate()))).append('\n'); 62 62 sb.append("Description: ").append(offset.getDescription()); 63 63 64 64 if( offset.isDeprecated() ) { 65 65 sb.append('\n').append('\n'); 66 sb.append("This geometry was marked obsolete").append('\n'); 67 sb.append("by ").append(offset.getAbandonAuthor()); 68 sb.append(" on ").append(DATE_FORMAT.format(offset.getAbandonDate())).append('\n'); 66 sb.append(tr("Deprecated by {0} on {1}\n",offset.getAbandonAuthor(), 67 DATE_FORMAT.format(offset.getAbandonDate()))).append('\n'); 69 68 sb.append("Reason: ").append(offset.getAbandonReason()); 70 69 }
Note:
See TracChangeset
for help on using the changeset viewer.