Changeset 29377 in osm for applications


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

some updates to iodb plugin

Location:
applications/editors/josm/plugins/imagery_offset_db/src/iodb
Files:
9 edited

Legend:

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

    r29376 r29377  
    8787    @Override
    8888    public String getToolTipText() {
    89         return "A calibration " + getGeometryType() + " by " + obj.getAuthor();
     89        return "A " + (obj.isDeprecated() ? "deprecated " : "") + "calibration " + OffsetInfoAction.getGeometryType(obj)
     90                + " by " + obj.getAuthor();
    9091    }
    9192
    9293    @Override
    9394    public Object getInfoComponent() {
    94         String info = "A calibration " + getGeometryType() + "\n"
    95                 + "Created by " + obj.getAuthor() + " on " + ImageryOffsetTools.DATE_FORMAT.format(obj.getDate()) + "\n"
    96                 + "Description: " + obj.getDescription();
    97         if( obj.isDeprecated() ) {
    98             info += "\nThis geometry was marked obsolete\n"
    99                     + "by " + obj.getAbandonAuthor() + " on " + ImageryOffsetTools.DATE_FORMAT.format(obj.getAbandonDate()) + "\n"
    100                     + "Reason: " + obj.getAbandonReason();
    101         }
    102         return info;
    103     }
    104 
    105     private String getGeometryType() {
    106         int n = obj.getGeometry().length;
    107         if( n == 1 )
    108             return "point";
    109         else if( n > 1 && !obj.getGeometry()[0].equals(obj.getGeometry()[n-1]) )
    110             return "path";
    111         else if( n > 1 && obj.getGeometry()[0].equals(obj.getGeometry()[n-1]) )
    112             return "polygon";
    113         else
    114             return "geometry";
     95        return OffsetInfoAction.getInformationObject(obj);
    11596    }
    11697
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/DeprecateOffsetAction.java

    r29371 r29377  
    3030            return;
    3131       
     32        String desc = offset instanceof ImageryOffset ? "imagery offset is wrong"
     33                : "calibration geometry is aligned badly";
    3234        if( JOptionPane.showConfirmDialog(Main.parent,
    33                 tr("Warning: deprecation is irreversible"), // todo: expand
     35                tr("Warning: deprecation is basically irreversible!\nAre you sure this " + desc + "?"),
    3436                ImageryOffsetTools.DIALOG_TITLE, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION ) {
    3537            return;
     
    4648
    4749        String message = "Please enter the reason why you mark this "
    48                 + (offset instanceof ImageryOffset ? "imagery offset" : "calibraion object") + " as deprecated:";
    49         String reason = null;
    50         boolean iterated = false;
    51         while( reason == null ) {
    52             reason = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE);
    53             if( reason == null || reason.length() == 0 ) {
    54                 return;
    55             }
    56             if( reason.length() < 3 || reason.length() > 200 ) {
    57                 reason = null;
    58                 if( !iterated ) {
    59                     message = message + "\n" + tr("Reason text should be 3 to 200 letters long.");
    60                     iterated = true;
    61                 }
    62             }
    63         }
     50                + (offset instanceof ImageryOffset ? "imagery offset" : "calibraion geometry") + " as deprecated:";
     51        String reason = StoreImageryOffsetAction.queryDescription(message);
     52        if( reason == null )
     53            return;
    6454       
    6555        try {
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/GetImageryOffsetAction.java

    r29376 r29377  
    7171                clayer.panToCenter();
    7272                if( !Main.pref.getBoolean("iodb.calibration.message", false) ) {
    73                     JOptionPane.showMessageDialog(Main.parent, // todo: update text
     73                    JOptionPane.showMessageDialog(Main.parent,
    7474                            tr("A layer has been added with a calibration geometry. Hide data layers,\n"
    7575                            + "find the corresponding feature on the imagery layer and move it accordingly."),
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetPlugin.java

    r29371 r29377  
    11package iodb;
    22
     3import java.awt.event.KeyEvent;
     4import javax.swing.JMenu;
    35import org.openstreetmap.josm.Main;
    46import org.openstreetmap.josm.plugins.Plugin;
    57import org.openstreetmap.josm.plugins.PluginInformation;
     8import static org.openstreetmap.josm.tools.I18n.marktr;
    69
    710/**
     
    2023        storeAction = new StoreImageryOffsetAction();
    2124       
    22         // todo: correct menu
    23         Main.main.menu.viewMenu.addSeparator();
    24         Main.main.menu.viewMenu.add(getAction);
    25         Main.main.menu.viewMenu.add(storeAction);
     25        JMenu offsetMenu = Main.main.menu.addMenu(marktr("Offset"), KeyEvent.VK_O, 6, "help");
     26        offsetMenu.add(getAction);
     27        offsetMenu.add(storeAction);
    2628
    2729        // todo: add a button on toolbar
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/ImageryOffsetTools.java

    r29376 r29377  
    1919public class ImageryOffsetTools {
    2020    public static final String DIALOG_TITLE = tr("Imagery Offset");
    21     public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    2221   
    2322    public static ImageryLayer getTopImageryLayer() {
     
    4241        Projection proj = Main.getProjection();
    4342        EastNorth offsetCenter = proj.latlon2eastNorth(center);
    44         EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy()); // todo: add or substract?
     43        EastNorth centerOffset = offsetCenter.add(-layer.getDx(), -layer.getDy());
    4544        LatLon offsetLL = proj.eastNorth2latlon(centerOffset);
    4645        return offsetLL;
     
    4847   
    4948    public static void applyLayerOffset( ImageryLayer layer, ImageryOffset offset ) {
     49        double[] dxy = calculateOffset(offset);
     50        layer.setOffset(dxy[0], dxy[1]);
     51    }
     52
     53    /**
     54     * Calculate dx and dy for imagery offset.
     55     * @return [dx, dy]
     56     */
     57    public static double[] calculateOffset( ImageryOffset offset ) {
    5058        Projection proj = Main.getProjection();
    5159        EastNorth center = proj.latlon2eastNorth(offset.getPosition());
    5260        EastNorth offsetPos = proj.latlon2eastNorth(offset.getImageryPos());
    53         layer.setOffset(center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY());
     61        return new double[] { center.getX() - offsetPos.getX(), center.getY() - offsetPos.getY() };
    5462    }
    5563   
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java

    r29376 r29377  
    2222    protected static final String PREF_CALIBRATION = "iodb.show.calibration";
    2323    protected static final String PREF_DEPRECATED = "iodb.show.deprecated";
     24    private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5);
    2425
    2526    private List<ImageryOffsetBase> offsets;
     
    4243        Box dialog = new Box(BoxLayout.Y_AXIS);
    4344        updateButtonPanel();
    44         // todo: calibration objects and deprecated offsets button
    45         final JCheckBox calibrationBox = new JCheckBox(tr("Hide calibration geometries"));
     45        final JCheckBox calibrationBox = new JCheckBox(tr("Calibration geometries"));
    4646        calibrationBox.setSelected(Main.pref.getBoolean(PREF_CALIBRATION, true));
    4747        calibrationBox.addActionListener(new ActionListener() {
     
    5151            }
    5252        });
    53         final JCheckBox deprecatedBox = new JCheckBox(tr("Show deprecated offsets"));
     53        final JCheckBox deprecatedBox = new JCheckBox(tr("Deprecated offsets"));
    5454        deprecatedBox.setSelected(Main.pref.getBoolean(PREF_DEPRECATED, false));
    5555        deprecatedBox.addActionListener(new ActionListener() {
     
    9292            buttonPanel.add(button);
    9393        }
     94//        buttonPanel.setMinimumSize(buttonPanel.getPreferredSize());
    9495        pack();
    9596    }
     
    105106                continue;
    106107            filteredOffsets.add(offset);
     108            if( filteredOffsets.size() >= MAX_OFFSETS )
     109                break;
    107110        }
    108111        return filteredOffsets;
  • 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}
  • 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}
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/StoreImageryOffsetAction.java

    r29376 r29377  
    4747            OsmPrimitive selection = selectedObjects.iterator().next();
    4848            if( (selection instanceof Node || selection instanceof Way) && !selection.isIncomplete() && !selection.isReferredByWays(1) ) {
    49                 String[] options = new String[] {tr("Store calibration geometry"), tr("Store imagery offset"), tr("Cancel")};
     49                String[] options = new String[] {tr("Store calibration geometry"), tr("Store imagery offset")};
    5050                int result = JOptionPane.showOptionDialog(Main.parent,
    5151                        tr("The selected object can be used as a calibration geometry. What do you intend to do?"),
     
    5959        }
    6060
    61         Object message = "";
     61        Object message;
    6262        LatLon center = ImageryOffsetTools.getMapCenter();
    6363        ImageryOffsetBase offsetObj;
     
    7676            // register calibration object
    7777            offsetObj = new CalibrationObject(calibration);
    78             message = "You are registering a calibration geometry. It should be the most precisely positioned object,\n"
    79                     + "with clearly visible boundaries on various satellite imagery.\n"
    80                     + "Please describe a region where this object is located.";
     78            message = "You are registering a calibration geometry. It should be the most precisely positioned object, with\n"
     79                    + "clearly visible boundaries on various satellite imagery. Please describe this object and its whereabouts.";
    8180        }
     81        String description = queryDescription(message);
     82        if( description == null )
     83            return;
    8284        offsetObj.setBasicInfo(center, userName, null, null);
    83         String description = null;
    84         boolean iterated = false;
    85         while( description == null ) {
    86             description = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE);
    87             if( description == null || description.length() == 0 )
    88                 return;
    89             if( description.length() < 3 || description.length() > 200 ) {
    90                 description = null;
    91                 if( !iterated ) {
    92                     message = message + "\n" + tr("Description should be 3 to 200 letters long.");
    93                     iterated = true;
    94                 }
    95             }
    96         }
    9785        offsetObj.setDescription(description);
    9886
     
    116104    }
    117105
     106    public static String queryDescription( Object message ) {
     107        String reason = null;
     108        boolean iterated = false;
     109        boolean ok = false;
     110        while( !ok ) {
     111            Object result = JOptionPane.showInputDialog(Main.parent, message, ImageryOffsetTools.DIALOG_TITLE, JOptionPane.PLAIN_MESSAGE, null, null, reason);
     112            if( result == null || result.toString().length() == 0 ) {
     113                return null;
     114            }
     115            reason = result.toString();
     116            if( reason.length() < 3 || reason.length() > 200 ) {
     117                if( !iterated ) {
     118                    message = message + "\n" + tr("This string should be 3 to 200 letters long.");
     119                    iterated = true;
     120                }
     121            } else
     122                ok = true;
     123        }
     124        return reason;
     125    }
     126
    118127    @Override
    119128    protected void updateEnabledState() {
Note: See TracChangeset for help on using the changeset viewer.