Ignore:
Timestamp:
2013-03-20T08:05:48+01:00 (13 years ago)
Author:
zverik
Message:

some updates to iodb plugin

File:
1 edited

Legend:

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

    r29371 r29377  
    11package iodb;
    22
     3import java.awt.Component;
     4import java.awt.Dimension;
     5import java.awt.Graphics;
     6import javax.swing.Icon;
     7import javax.swing.ImageIcon;
    38import javax.swing.JButton;
     9import org.openstreetmap.josm.gui.layer.ImageryLayer;
     10import org.openstreetmap.josm.tools.ImageProvider;
    411
    512/**
     
    1118   
    1219    private ImageryOffsetBase offset;
     20    private double offsetLength;
     21    private double distance;
     22    private double direction;
    1323
    1424    public OffsetDialogButton( ImageryOffsetBase offset ) {
    15         super(offset.getDescription() + " (" + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m)");
     25        super();
     26        // todo: fix layout
     27        setMinimumSize(new Dimension(500, 80));
     28        setMaximumSize(new Dimension(500, 140));
     29        setText("<html>"
     30                + Math.round(offset.getPosition().greatCircleDistance(ImageryOffsetTools.getMapCenter())) + " m: "
     31                + offset.getDescription() + "</html>");
     32        setIcon(new OffsetIcon(offset));
    1633        this.offset = offset;
     34
     35        offsetLength = offset instanceof ImageryOffset ? getLengthAndDirection((ImageryOffset)offset)[0] : 0.0;
     36        // todo: layout, info, map distance and direction
    1737    }
    1838
     
    2040        return offset;
    2141    }
    22    
     42
     43/*    @Override
     44    public Dimension getPreferredSize() {
     45        return new Dimension(500, super.getPreferredSize().height);
     46    }*/
     47
     48    private double[] getLengthAndDirection( ImageryOffset offset ) {
     49        ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
     50        double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] {layer.getDx(), layer.getDy()};
     51        return OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);
     52    }
     53
     54    class OffsetIcon implements Icon {
     55        private boolean isDeprecated;
     56        private boolean isCalibration;
     57        private double direction;
     58        private double length;
     59        private ImageIcon background;
     60
     61        public OffsetIcon( ImageryOffsetBase offset ) {
     62            isDeprecated = offset.isDeprecated();
     63            isCalibration = offset instanceof CalibrationObject;
     64            if( offset instanceof ImageryOffset ) {
     65                background = ImageProvider.get("offset");
     66                ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
     67                double[] dxy = layer == null ? new double[] {0.0, 0.0} : new double[] { layer.getDx(), layer.getDy() };
     68                double[] ld = OffsetInfoAction.getLengthAndDirection((ImageryOffset)offset, dxy[0], dxy[1]);
     69                length = ld[0];
     70                direction = ld[1];
     71            } else {
     72                background = ImageProvider.get("calibration");
     73            }
     74        }
     75
     76        public void paintIcon( Component c, Graphics g, int x, int y ) {
     77            background.paintIcon(c, g, x, y);
     78            // todo: draw an arrow
     79            // todo: apply deprecation
     80        }
     81
     82        public int getIconWidth() {
     83            return background.getIconWidth();
     84        }
     85
     86        public int getIconHeight() {
     87            return background.getIconHeight();
     88        }
     89    }
    2390}
Note: See TracChangeset for help on using the changeset viewer.