Changeset 29382 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java
- Timestamp:
- 2013-03-21T21:30:58+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 @Override 55 /* @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
Note:
See TracChangeset
for help on using the changeset viewer.
