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/OffsetInfoAction.java

    r29371 r29377  
    22
    33import java.awt.event.ActionEvent;
     4import java.text.SimpleDateFormat;
    45import javax.swing.AbstractAction;
    56import javax.swing.JOptionPane;
    67import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.data.coor.LatLon;
    79import static org.openstreetmap.josm.tools.I18n.tr;
    810import org.openstreetmap.josm.tools.ImageProvider;
     
    1416 */
    1517public class OffsetInfoAction extends AbstractAction {
    16     private ImageryOffsetBase offset;
     18    public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
     19
     20    private Object info;
    1721   
    1822    public OffsetInfoAction( ImageryOffsetBase offset ) {
    1923        super(tr("Offset Information"));
    20         putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
    21         this.offset = offset;
     24        putValue(SMALL_ICON, ImageProvider.get("info"));
     25        if( offset != null )
     26            this.info = getInformationObject(offset);
    2227        setEnabled(offset != null);
    2328    }
    2429
    2530    public void actionPerformed(ActionEvent e) {
    26         JOptionPane.showMessageDialog(Main.parent, "TODO", ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE);
     31        JOptionPane.showMessageDialog(Main.parent, info, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE);
     32    }
     33
     34    public static Object getInformationObject( ImageryOffsetBase offset ) {
     35        StringBuilder sb = new StringBuilder();
     36        if( offset instanceof ImageryOffset ) {
     37            double[] ld = getLengthAndDirection((ImageryOffset)offset);
     38            sb.append(tr("An imagery offset of {0} m to {1}", ld[0], explainDirection(ld[1]))).append('\n');
     39            sb.append("Imagery ID: ").append(((ImageryOffset)offset).getImagery());
     40        } else
     41            sb.append(tr("A calibration {0}", getGeometryType((CalibrationObject)offset)));
     42        sb.append("\n\nCreated by ").append(offset.getAuthor());
     43        sb.append(" on ").append(DATE_FORMAT.format(offset.getDate())).append("\n");
     44        sb.append("Description: ").append(offset.getDescription());
     45        if( offset.isDeprecated() ) {
     46            sb.append("\n\nThis geometry was marked obsolete\n");
     47            sb.append("by ").append(offset.getAbandonAuthor());
     48            sb.append(" on ").append(DATE_FORMAT.format(offset.getAbandonDate())).append("\n");
     49            sb.append("Reason: ").append(offset.getAbandonReason());
     50        }
     51        return sb.toString();
     52    }
     53
     54    public static String getGeometryType( CalibrationObject obj ) {
     55        if( obj.getGeometry() == null )
     56            return tr("nothing");
     57        int n = obj.getGeometry().length;
     58        if( n == 1 )
     59            return tr("point");
     60        else if( n > 1 && !obj.getGeometry()[0].equals(obj.getGeometry()[n - 1]) )
     61            return tr("path ({0} nodes)", n);
     62        else if( n > 1 && obj.getGeometry()[0].equals(obj.getGeometry()[n - 1]) )
     63            return tr("polygon ({0} nodes)", n - 1);
     64        else
     65            return "geometry";
     66    }
     67
     68    public static double[] getLengthAndDirection( ImageryOffset offset ) {
     69        return getLengthAndDirection(offset, 0.0, 0.0);
     70    }
     71
     72    public static double[] getLengthAndDirection( ImageryOffset offset, double dx, double dy ) {
     73        double length = 0.0;
     74        double direction = 0.0;
     75        // todo: calculate length and angular direction
     76        return new double[] { length, direction };
     77    }
     78
     79    public static String explainDirection( double dir ) {
     80        return "nowhere"; // todo
    2781    }
    2882}
Note: See TracChangeset for help on using the changeset viewer.