Ignore:
Timestamp:
2013-03-21T21:30:58+01:00 (13 years ago)
Author:
zverik
Message:

iodb updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialogButton.java

    r29380 r29382  
    11package iodb;
    22
    3 import java.awt.Component;
    4 import java.awt.Dimension;
    5 import java.awt.Graphics;
     3import java.awt.*;
    64import javax.swing.Icon;
    75import javax.swing.ImageIcon;
     
    2523        super();
    2624        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));
    2927        setRelevantText();
    3028        setIcon(new OffsetIcon(offset));
     
    3230        offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0;
    3331        // 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
    3440    }
    3541
     
    3844     */
    3945    public void setRelevantText() {
    40         setText("<html>"
     46        setText("<html><div style=\"width: 400px;\">"
    4147                + ImageryOffsetTools.formatDistance(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter()))
    42                 + ": " + offset.getDescription() + "</html>");
     48                + ": " + offset.getDescription() + "</div></html>");
    4349    }
    4450
     
    4753    }
    4854
    49     @Override
     55/*    @Override
    5056    public Dimension getPreferredSize() {
    5157        Dimension size = super.getPreferredSize();
     
    5359        size.height = 70;
    5460        return size;
    55     }
     61    }*/
    5662
    5763    /**
     
    7278        private boolean isDeprecated;
    7379        private boolean isCalibration;
    74         private double direction;
     80        private double direction = -1.0;
    7581        private double length;
    7682        private ImageIcon background;
     
    9197        }
    9298
    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            }
    97136        }
    98137
Note: See TracChangeset for help on using the changeset viewer.