Ignore:
Timestamp:
2016-07-02T03:55:03+02:00 (9 years ago)
Author:
donvip
Message:

checkstyle

File:
1 edited

Legend:

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

    r29432 r32528  
     1// License: WTFPL. For details, see LICENSE file.
    12package iodb;
    23
    3 import java.awt.*;
    4 import javax.swing.*;
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
     6import java.awt.AlphaComposite;
     7import java.awt.BasicStroke;
     8import java.awt.BorderLayout;
     9import java.awt.Color;
     10import java.awt.Component;
     11import java.awt.Font;
     12import java.awt.Graphics;
     13import java.awt.Graphics2D;
     14import java.awt.Point;
     15import java.awt.RenderingHints;
     16
     17import javax.swing.Box;
     18import javax.swing.BoxLayout;
     19import javax.swing.Icon;
     20import javax.swing.ImageIcon;
     21import javax.swing.JButton;
     22import javax.swing.JLabel;
     23import javax.swing.JPanel;
     24import javax.swing.SwingConstants;
     25
    526import org.openstreetmap.josm.Main;
    627import org.openstreetmap.josm.data.coor.EastNorth;
     
    930import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1031import org.openstreetmap.josm.tools.ImageProvider;
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    1232
    1333/**
    1434 * A button which shows offset information. Must be spectacular, since it's the only
    1535 * non-JOptionPane GUI in the plugin.
    16  * 
     36 *
    1737 * @author Zverik
    1838 * @license WTFPL
    1939 */
    2040public class OffsetDialogButton extends JButton {
    21    
     41
    2242    private ImageryOffsetBase offset;
    2343
     
    2949     * @param offset An offset to display on the button.
    3050     */
    31     public OffsetDialogButton( ImageryOffsetBase offset ) {
     51    public OffsetDialogButton(ImageryOffsetBase offset) {
    3252        this.offset = offset;
    3353        layoutComponents();
     
    5777        String authorAndDate = offset.isDeprecated()
    5878                ? tr("Deprecated by {0} on {1}", offset.getAbandonAuthor(),
    59                 OffsetInfoAction.DATE_FORMAT.format(offset.getAbandonDate()))
    60                 : tr("Created by {0} on {1}", 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         description = description.replace("<", "&lt;").replace(">", "&gt;");
    75         JLabel descriptionLabel = new JLabel("<html><div style=\"width: 300px;\">"+description+"</div></html>");
    76         Font descriptionFont = new Font(descriptionLabel.getFont().getName(), Font.BOLD, descriptionLabel.getFont().getSize());
    77         descriptionLabel.setFont(descriptionFont);
    78 
    79         OffsetIcon offsetIcon = new OffsetIcon(offset);
    80         double offsetDistance = offset instanceof ImageryOffset
    81                 ? offsetIcon.getDistance() : 0.0;
    82 //                ? ((ImageryOffset)offset).getImageryPos().greatCircleDistance(offset.getPosition()) : 0.0;
    83         JLabel offsetLabel = new JLabel(offsetDistance > 0.2 ? ImageryOffsetTools.formatDistance(offsetDistance) : "",
    84                 offsetIcon, SwingConstants.CENTER);
    85         Font offsetFont = new Font(offsetLabel.getFont().getName(), Font.PLAIN, offsetLabel.getFont().getSize() - 2);
    86         offsetLabel.setFont(offsetFont);
    87         offsetLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    88         offsetLabel.setVerticalTextPosition(SwingConstants.BOTTOM);
    89 
    90         Box topLine = new Box(BoxLayout.X_AXIS);
    91         topLine.add(authorAndDateLabel);
    92         topLine.add(Box.createHorizontalGlue());
    93         topLine.add(Box.createHorizontalStrut(10));
    94         topLine.add(distanceLabel);
    95 
    96         JPanel p = new JPanel(new BorderLayout(10, 5));
    97         p.setOpaque(false);
    98         p.add(topLine, BorderLayout.NORTH);
    99         p.add(offsetLabel, BorderLayout.WEST);
    100         p.add(descriptionLabel, BorderLayout.CENTER);
    101         add(p);
     79                        OffsetInfoAction.DATE_FORMAT.format(offset.getAbandonDate()))
     80                        : tr("Created by {0} on {1}", offset.getAuthor(),
     81                                OffsetInfoAction.DATE_FORMAT.format(offset.getDate()));
     82                JLabel authorAndDateLabel = new JLabel(authorAndDate);
     83                Font authorFont = new Font(authorAndDateLabel.getFont().getName(), Font.ITALIC, authorAndDateLabel.getFont().getSize());
     84                authorAndDateLabel.setFont(authorFont);
     85
     86                directionArrow = new DirectionIcon(offset.getPosition());
     87                distanceLabel = new JLabel("", directionArrow, SwingConstants.RIGHT);
     88                distanceLabel.setHorizontalTextPosition(SwingConstants.LEFT);
     89                Font distanceFont = new Font(distanceLabel.getFont().getName(), Font.PLAIN, distanceLabel.getFont().getSize());
     90                distanceLabel.setFont(distanceFont);
     91                updateLocation();
     92
     93                String description = offset.isDeprecated() ? offset.getAbandonReason() : offset.getDescription();
     94                description = description.replace("<", "&lt;").replace(">", "&gt;");
     95                JLabel descriptionLabel = new JLabel("<html><div style=\"width: 300px;\">"+description+"</div></html>");
     96                Font descriptionFont = new Font(descriptionLabel.getFont().getName(), Font.BOLD, descriptionLabel.getFont().getSize());
     97                descriptionLabel.setFont(descriptionFont);
     98
     99                OffsetIcon offsetIcon = new OffsetIcon(offset);
     100                double offsetDistance = offset instanceof ImageryOffset
     101                        ? offsetIcon.getDistance() : 0.0;
     102                        //                ? ((ImageryOffset)offset).getImageryPos().greatCircleDistance(offset.getPosition()) : 0.0;
     103                        JLabel offsetLabel = new JLabel(offsetDistance > 0.2 ? ImageryOffsetTools.formatDistance(offsetDistance) : "",
     104                                offsetIcon, SwingConstants.CENTER);
     105                        Font offsetFont = new Font(offsetLabel.getFont().getName(), Font.PLAIN, offsetLabel.getFont().getSize() - 2);
     106                        offsetLabel.setFont(offsetFont);
     107                        offsetLabel.setHorizontalTextPosition(SwingConstants.CENTER);
     108                        offsetLabel.setVerticalTextPosition(SwingConstants.BOTTOM);
     109
     110                        Box topLine = new Box(BoxLayout.X_AXIS);
     111                        topLine.add(authorAndDateLabel);
     112                        topLine.add(Box.createHorizontalGlue());
     113                        topLine.add(Box.createHorizontalStrut(10));
     114                        topLine.add(distanceLabel);
     115
     116                        JPanel p = new JPanel(new BorderLayout(10, 5));
     117                        p.setOpaque(false);
     118                        p.add(topLine, BorderLayout.NORTH);
     119                        p.add(offsetLabel, BorderLayout.WEST);
     120                        p.add(descriptionLabel, BorderLayout.CENTER);
     121                        add(p);
    102122    }
    103123
    104124    /**
    105125     * Calculates length and direction for two points in the imagery offset object.
    106      * @see #getLengthAndDirection(iodb.ImageryOffset, double, double) 
    107      */
    108     private double[] getLengthAndDirection( ImageryOffset offset ) {
     126     * @see #getLengthAndDirection(iodb.ImageryOffset, double, double)
     127     */
     128    private double[] getLengthAndDirection(ImageryOffset offset) {
    109129        ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
    110130        double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()};
     
    118138     * @see #getLengthAndDirection(iodb.ImageryOffset)
    119139     */
    120     public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) {
     140    public static double[] getLengthAndDirection(ImageryOffset offset, double dx, double dy) {
    121141        Projection proj = Main.getProjection();
    122142        EastNorth pos = proj.latlon2eastNorth(offset.getPosition());
     
    124144        double length = correctedCenterLL.greatCircleDistance(offset.getImageryPos());
    125145        double direction = length < 1e-2 ? 0.0 : correctedCenterLL.heading(offset.getImageryPos());
    126         if( direction < 0 )
     146        if (direction < 0)
    127147            direction += Math.PI * 2;
    128148        return new double[] {length, direction};
    129149    }
    130150
    131     private static void drawArrow( Graphics g, int cx, int cy, double length, double direction ) {
    132         int dx = (int)Math.round(Math.sin(direction) * length / 2);
    133         int dy = (int)Math.round(Math.cos(direction) * length / 2);
     151    private static void drawArrow(Graphics g, int cx, int cy, double length, double direction) {
     152        int dx = (int) Math.round(Math.sin(direction) * length / 2);
     153        int dy = (int) Math.round(Math.cos(direction) * length / 2);
    134154        g.drawLine(cx - dx, cy - dy, cx + dx, cy + dy);
    135155        double wingLength = Math.max(length / 3, 4);
    136156        double d1 = direction - Math.PI / 6;
    137         int dx1 = (int)Math.round(Math.sin(d1) * wingLength);
    138         int dy1 = (int)Math.round(Math.cos(d1) * wingLength);
     157        int dx1 = (int) Math.round(Math.sin(d1) * wingLength);
     158        int dy1 = (int) Math.round(Math.cos(d1) * wingLength);
    139159        g.drawLine(cx + dx, cy + dy, cx + dx - dx1, cy + dy - dy1);
    140160        double d2 = direction + Math.PI / 6;
    141         int dx2 = (int)Math.round(Math.sin(d2) * wingLength);
    142         int dy2 = (int)Math.round(Math.cos(d2) * wingLength);
     161        int dx2 = (int) Math.round(Math.sin(d2) * wingLength);
     162        int dy2 = (int) Math.round(Math.cos(d2) * wingLength);
    143163        g.drawLine(cx + dx, cy + dy, cx + dx - dx2, cy + dy - dy2);
    144164    }
     
    159179         * of an arrow if they're needed.
    160180         */
    161         public OffsetIcon( ImageryOffsetBase offset ) {
     181        OffsetIcon(ImageryOffsetBase offset) {
    162182            isDeprecated = offset.isDeprecated();
    163183            isCalibration = offset instanceof CalibrationObject;
    164             if( offset instanceof ImageryOffset ) {
     184            if (offset instanceof ImageryOffset) {
    165185                background = ImageProvider.get("offset");
    166                 double[] ld = getLengthAndDirection((ImageryOffset)offset);
     186                double[] ld = getLengthAndDirection((ImageryOffset) offset);
    167187                distance = ld[0];
    168188                direction = ld[1];
     
    179199         * Paints the base image and adds to it according to the offset.
    180200         */
    181         public void paintIcon( Component comp, Graphics g, int x, int y ) {
     201        @Override
     202        public void paintIcon(Component comp, Graphics g, int x, int y) {
    182203            background.paintIcon(comp, g, x, y);
    183204
    184             Graphics2D g2 = (Graphics2D)g.create();
     205            Graphics2D g2 = (Graphics2D) g.create();
    185206            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    186             if( !isCalibration ) {
     207            if (!isCalibration) {
    187208                g2.setColor(Color.black);
    188209                Point c = new Point(x + getIconWidth() / 2, y + getIconHeight() / 2);
    189                 if( distance < 1e-2 ) {
     210                if (distance < 1e-2) {
    190211                    // no offset
    191212                    g2.fillOval(c.x - 3, c.y - 3, 7, 7);
     
    197218                }
    198219            }
    199             if( isDeprecated ) {
     220            if (isDeprecated) {
    200221                // big red X
    201222                g2.setColor(Color.red);
     
    207228        }
    208229
     230        @Override
    209231        public int getIconWidth() {
    210232            return background.getIconWidth();
    211233        }
    212234
     235        @Override
    213236        public int getIconHeight() {
    214237            return background.getIconHeight();
     
    223246        private double direction;
    224247
    225         public DirectionIcon( LatLon to ) {
     248        DirectionIcon(LatLon to) {
    226249            this.to = to;
    227250        }
    228251
    229         public void updateIcon( LatLon from ) {
     252        public void updateIcon(LatLon from) {
    230253            distance = from.greatCircleDistance(to);
    231254            direction = to.heading(from);
     
    235258         * Paints the base image and adds to it according to the offset.
    236259         */
    237         public void paintIcon( Component comp, Graphics g, int x, int y ) {
    238             Graphics2D g2 = (Graphics2D)g.create();
     260        @Override
     261        public void paintIcon(Component comp, Graphics g, int x, int y) {
     262            Graphics2D g2 = (Graphics2D) g.create();
    239263            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    240264            g2.setColor(Color.black);
    241265            Point c = new Point(x + getIconWidth() / 2, y + getIconHeight() / 2);
    242             if( distance < 1 ) {
     266            if (distance < 1) {
    243267                // no offset
    244268                int r = 2;
     
    251275        }
    252276
     277        @Override
    253278        public int getIconWidth() {
    254279            return SIZE;
    255280        }
    256281
     282        @Override
    257283        public int getIconHeight() {
    258284            return SIZE;
Note: See TracChangeset for help on using the changeset viewer.