Ignore:
Timestamp:
2013-05-13T03:10:05+02:00 (11 years ago)
Author:
Don-vip
Message:
  • Improve PopupMenuLauncher to automatically select JTable/JList/JTree line under cursor
  • Simplify all popup menus with this new feature
  • Remove custom popup menus in BoundingBoxSelection and BoundingBoxSelection to use default text field popup menus recently introduced
  • Fix EDT violations in changeset window
  • Make Autoscale actions publicly available in MainMenu
  • Add a new "Zoom to problem" mode in AutoScaleAction
  • Make "Zoom to problem" menu item in validator dialog use this new feature
  • Update enabled state of "Zoom to Conflict" and "Zoom to problem" against selection of conflict/validator dialog
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r5460 r5958  
    1313
    1414import javax.swing.JOptionPane;
     15import javax.swing.event.ListSelectionEvent;
     16import javax.swing.event.ListSelectionListener;
     17import javax.swing.event.TreeSelectionEvent;
     18import javax.swing.event.TreeSelectionListener;
    1519
    1620import org.openstreetmap.josm.Main;
     
    1923import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2024import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     25import org.openstreetmap.josm.data.validation.TestError;
     26import org.openstreetmap.josm.gui.MapFrame;
     27import org.openstreetmap.josm.gui.MapFrameListener;
    2128import org.openstreetmap.josm.gui.MapView;
    2229import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     30import org.openstreetmap.josm.gui.dialogs.ValidatorDialog.ValidatorBoundingXYVisitor;
    2331import org.openstreetmap.josm.gui.layer.Layer;
    2432import org.openstreetmap.josm.tools.Shortcut;
     
    3644        marktr("conflict"),
    3745        marktr("download"),
     46        marktr("problem"),
    3847        marktr("previous"),
    3948        marktr("next")};
     49   
     50    private final String mode;
     51
     52    protected ZoomChangeAdapter zoomChangeAdapter;
     53    protected MapFrameAdapter mapFrameAdapter;
    4054
    4155    /**
     
    7791    }
    7892
    79     private final String mode;
    80 
    8193    private static int getModeShortcut(String mode) {
    8294        int shortcut = -1;
     
    88100        else if (mode.equals("conflict")) { shortcut = KeyEvent.VK_4; }
    89101        else if (mode.equals("download")) { shortcut = KeyEvent.VK_5; }
     102        else if (mode.equals("problem")) { shortcut = KeyEvent.VK_6; }
    90103        else if (mode.equals("previous")) { shortcut = KeyEvent.VK_8; }
    91104        else if (mode.equals("next")) { shortcut = KeyEvent.VK_9; }
     
    95108
    96109    /**
    97      *
    98      * @param mode
     110     * Constructs a new {@code AutoScaleAction}.
     111     * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES})
    99112     * @param marker Used only to differentiate from default constructor
    100113     */
     
    104117    }
    105118
    106 
    107     public AutoScaleAction(String mode) {
     119    /**
     120     * Constructs a new {@code AutoScaleAction}.
     121     * @param mode The autoscale mode (one of {@link AutoScaleAction#MODES})
     122     */
     123    public AutoScaleAction(final String mode) {
    108124        super(tr("Zoom to {0}", tr(mode)), "dialogs/autoscale/" + mode, tr("Zoom the view to {0}.", tr(mode)),
    109                 Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT), true);
     125                Shortcut.registerShortcut("view:zoom"+mode, tr("View: {0}", tr("Zoom to {0}", tr(mode))), getModeShortcut(mode), Shortcut.DIRECT),
     126                true, null, false);
    110127        String modeHelp = Character.toUpperCase(mode.charAt(0)) + mode.substring(1);
    111128        putValue("help", "Action/AutoScale/" + modeHelp);
     
    119136        } else if (mode.equals("conflict")) {
    120137            putValue("help", ht("/Action/ZoomToConflict"));
     138        } else if (mode.equals("problem")) {
     139            putValue("help", ht("/Action/ZoomToProblem"));
    121140        } else if (mode.equals("download")) {
    122141            putValue("help", ht("/Action/ZoomToDownload"));
     
    125144        } else if (mode.equals("next")) {
    126145            putValue("help", ht("/Action/ZoomToNext"));
    127         }
     146        } else {
     147            throw new IllegalArgumentException("Unknown mode: "+mode);
     148        }
     149        installAdapters();
    128150    }
    129151
     
    171193
    172194    private BoundingXYVisitor getBoundingBox() {
    173         BoundingXYVisitor v = new BoundingXYVisitor();
    174         if (mode.equals("data")) {
     195        BoundingXYVisitor v = mode.equals("problem") ? new ValidatorBoundingXYVisitor() : new BoundingXYVisitor();
     196
     197        if (mode.equals("problem")) {
     198            TestError error = Main.map.validatorDialog.getSelectedError();
     199            if (error == null) return null;
     200            ((ValidatorBoundingXYVisitor) v).visit(error);
     201            if (v.getBounds() == null) return null;
     202            v.enlargeBoundingBox(Main.pref.getDouble("validator.zoom-enlarge-bbox", 0.0002));
     203        } else if (mode.equals("data")) {
    175204            for (Layer l : Main.map.mapView.getAllLayers()) {
    176205                l.visitBoundingBox(v);
     
    236265                setEnabled(true);
    237266            }
     267        } else if ("conflict".equals(mode)) {
     268            setEnabled(Main.map != null && Main.map.conflictDialog.getSelectedConflict() != null);
     269        } else if ("problem".equals(mode)) {
     270            setEnabled(Main.map != null && Main.map.validatorDialog.getSelectedError() != null);
    238271        } else if ("previous".equals(mode)) {
    239272            setEnabled(Main.isDisplayingMapView() && Main.map.mapView.hasZoomUndoEntries());
     
    258291    protected void installAdapters() {
    259292        super.installAdapters();
    260         // make this action listen to zoom change events
     293        // make this action listen to zoom and mapframe change events
    261294        //
    262         zoomChangeAdapter = new ZoomChangeAdapter();
    263         MapView.addZoomChangeListener(zoomChangeAdapter);
     295        MapView.addZoomChangeListener(zoomChangeAdapter = new ZoomChangeAdapter());
     296        Main.addMapFrameListener(mapFrameAdapter = new MapFrameAdapter());
    264297        initEnabledState();
    265298    }
    266299
    267300    /**
    268      * Adapter for selection change events
    269      *
     301     * Adapter for zoom change events
    270302     */
    271303    private class ZoomChangeAdapter implements MapView.ZoomChangeListener {
     
    275307    }
    276308
    277     private ZoomChangeAdapter zoomChangeAdapter;
     309    /**
     310     * Adapter for MapFrame change events
     311     */
     312    private class MapFrameAdapter implements MapFrameListener {
     313        private ListSelectionListener conflictSelectionListener;
     314        private TreeSelectionListener validatorSelectionListener;
     315
     316        public MapFrameAdapter() {
     317            if (mode.equals("conflict")) {
     318                conflictSelectionListener = new ListSelectionListener() {
     319                    @Override public void valueChanged(ListSelectionEvent e) {
     320                        updateEnabledState();
     321                    }
     322                };
     323            } else if (mode.equals("problem")) {
     324                validatorSelectionListener = new TreeSelectionListener() {
     325                    @Override public void valueChanged(TreeSelectionEvent e) {
     326                        updateEnabledState();
     327                    }
     328                };
     329            }
     330        }
     331
     332        @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
     333            if (conflictSelectionListener != null) {
     334                if (newFrame != null) {
     335                    newFrame.conflictDialog.addListSelectionListener(conflictSelectionListener);
     336                } else if (oldFrame != null) {
     337                    oldFrame.conflictDialog.removeListSelectionListener(conflictSelectionListener);
     338                }
     339            } else if (validatorSelectionListener != null) {
     340                if (newFrame != null) {
     341                    newFrame.validatorDialog.addTreeSelectionListener(validatorSelectionListener);
     342                } else if (oldFrame != null) {
     343                    oldFrame.validatorDialog.removeTreeSelectionListener(validatorSelectionListener);
     344                }
     345            }
     346        }
     347    }
    278348}
Note: See TracChangeset for help on using the changeset viewer.