Ignore:
Timestamp:
2013-03-21T07:28:34+01:00 (13 years ago)
Author:
zverik
Message:

updated alpha of iodb

File:
1 edited

Legend:

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

    r29379 r29380  
    1111import javax.swing.border.EmptyBorder;
    1212import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.tools.GBC;
     13import org.openstreetmap.josm.gui.JosmUserIdentityManager;
     14import org.openstreetmap.josm.gui.NavigatableComponent;
     15import org.openstreetmap.josm.gui.layer.ImageryLayer;
    1416import static org.openstreetmap.josm.tools.I18n.tr;
     17import org.openstreetmap.josm.tools.ImageProvider;
     18import org.openstreetmap.josm.tools.OpenBrowser;
    1519
    1620/**
     
    1923 * @author zverik
    2024 */
    21 public class OffsetDialog extends JDialog implements ActionListener {
     25public class OffsetDialog extends JDialog implements ActionListener, NavigatableComponent.ZoomChangeListener {
    2226    protected static final String PREF_CALIBRATION = "iodb.show.calibration";
    2327    protected static final String PREF_DEPRECATED = "iodb.show.deprecated";
    2428    private static final int MAX_OFFSETS = Main.main.pref.getInteger("iodb.max.offsets", 5);
     29    private static final boolean MODAL = false; // modal does not work for executing actions
    2530
    2631    private List<ImageryOffsetBase> offsets;
     
    2934
    3035    public OffsetDialog( List<ImageryOffsetBase> offsets ) {
    31         super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL);
     36        super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE,
     37                MODAL ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS);
    3238        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    33 //        setResizable(false);
     39        setResizable(false);
    3440        this.offsets = offsets;
     41        NavigatableComponent.addZoomChangeListener(this);
    3542
    3643        // make this dialog close on "escape"
     
    6168        checkBoxPanel.add(calibrationBox);
    6269        checkBoxPanel.add(deprecatedBox);
    63         JButton cancelButton = new JButton("Cancel");
     70        JButton cancelButton = new JButton(tr("Cancel"), ImageProvider.get("cancel"));
    6471        cancelButton.addActionListener(this);
    65         cancelButton.setAlignmentX(CENTER_ALIGNMENT);
     72        JButton helpButton = new JButton(new HelpAction());
     73        JPanel cancelPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
     74        cancelPanel.add(cancelButton);
     75        cancelPanel.add(helpButton);
    6676
    6777        Box dialog = new Box(BoxLayout.Y_AXIS);
    6878        dialog.add(buttonPanel);
    6979        dialog.add(checkBoxPanel);
    70         dialog.add(cancelButton);
     80        dialog.add(cancelPanel);
    7181
    7282        dialog.setBorder(new CompoundBorder(dialog.getBorder(), new EmptyBorder(5, 5, 5, 5)));
     
    8797            JPopupMenu popupMenu = new JPopupMenu();
    8898            popupMenu.add(new OffsetInfoAction(offset));
    89             if( !offset.isDeprecated() )
    90                 popupMenu.add(new DeprecateOffsetAction(offset));
     99            if( !offset.isDeprecated() ) {
     100                DeprecateOffsetAction action = new DeprecateOffsetAction(offset);
     101                action.setListener(new DeprecateOffsetListener(offset));
     102                popupMenu.add(action);
     103            }
    91104            button.setComponentPopupMenu(popupMenu);
    92105            buttonPanel.add(button);
     
    110123        return filteredOffsets;
    111124    }
     125
     126    public void zoomChanged() {
     127        for( Component c : buttonPanel.getComponents() ) {
     128            if( c instanceof OffsetDialogButton ) {
     129                ((OffsetDialogButton)c).updateLocation();
     130            }
     131        }
     132    }
    112133   
    113134    public ImageryOffsetBase showDialog() {
     
    118139    }
    119140
     141    public void applyOffset() {
     142        if( selectedOffset instanceof ImageryOffset ) {
     143            ImageryLayer layer = ImageryOffsetTools.getTopImageryLayer();
     144            ImageryOffsetTools.applyLayerOffset(layer, (ImageryOffset)selectedOffset);
     145            Main.map.repaint();
     146            if( !Main.pref.getBoolean("iodb.offset.message", false) ) {
     147                JOptionPane.showMessageDialog(Main.parent,
     148                        tr("The topmost imagery layer has been shifted to presumably match\n"
     149                        + "OSM data in the area. Please check that the offset is still valid\n"
     150                        + "by downloading GPS tracks and comparing them and OSM data to the imagery."),
     151                        ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE);
     152                Main.pref.put("iodb.offset.message", true);
     153            }
     154        } else if( selectedOffset instanceof CalibrationObject ) {
     155            CalibrationLayer clayer = new CalibrationLayer((CalibrationObject)selectedOffset);
     156            Main.map.mapView.addLayer(clayer);
     157            clayer.panToCenter();
     158            if( !Main.pref.getBoolean("iodb.calibration.message", false) ) {
     159                JOptionPane.showMessageDialog(Main.parent,
     160                        tr("A layer has been added with a calibration geometry. Hide data layers,\n"
     161                        + "find the corresponding feature on the imagery layer and move it accordingly."),
     162                        ImageryOffsetTools.DIALOG_TITLE, JOptionPane.INFORMATION_MESSAGE);
     163                Main.pref.put("iodb.calibration.message", true);
     164            }
     165        }
     166    }
     167
    120168    public void actionPerformed( ActionEvent e ) {
    121169        if( e.getSource() instanceof OffsetDialogButton ) {
     
    123171        } else
    124172            selectedOffset = null;
     173        NavigatableComponent.removeZoomChangeListener(this);
    125174        setVisible(false);
     175        if( !MODAL && selectedOffset != null )
     176            applyOffset();
     177    }
     178
     179    private class DeprecateOffsetListener implements QuerySuccessListener {
     180        ImageryOffsetBase offset;
     181
     182        public DeprecateOffsetListener( ImageryOffsetBase offset ) {
     183            this.offset = offset;
     184        }
     185
     186        public void queryPassed() {
     187            offset.setDeprecated(new Date(), JosmUserIdentityManager.getInstance().getUserName(), "");
     188            updateButtonPanel();
     189        }
     190    }
     191
     192    class HelpAction extends AbstractAction {
     193
     194        public HelpAction() {
     195            super(tr("Help"));
     196            putValue(SMALL_ICON, ImageProvider.get("help"));
     197        }
     198
     199        public void actionPerformed( ActionEvent e ) {
     200            String base = "http://wiki.openstreetmap.org/wiki/";
     201            String page = "Imagery_Offset_Database";
     202            String lang = "RU:"; // todo: determine it
     203            OpenBrowser.displayUrl(base + lang + page);
     204        }
    126205    }
    127206}
Note: See TracChangeset for help on using the changeset viewer.