Changeset 5727 in josm


Ignore:
Timestamp:
2013-02-18T12:03:30+01:00 (12 years ago)
Author:
akks
Message:

Command Stack dialog (undo/redo): select and zoom to affected primitives on double-click, Enter or context menu action

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r5200 r5727  
    3838
    3939import org.openstreetmap.josm.Main;
     40import org.openstreetmap.josm.actions.AutoScaleAction;
    4041import org.openstreetmap.josm.command.Command;
    4142import org.openstreetmap.josm.command.PseudoCommand;
     
    7374    private UndoRedoType lastOperation = UndoRedoType.UNDO;
    7475
     76    // Actions for context menu and Enter key
     77    private SelectAction selectAction = new SelectAction();
     78    private SelectAndZoomAction selectAndZoomAction = new SelectAndZoomAction();
     79   
    7580    public CommandStackDialog(final MapFrame mapFrame) {
    7681        super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."),
     
    107112        treesPanel.setBackground(redoTree.getBackground());
    108113
    109         SelectAction selectAction = new SelectAction();
    110114        wireUpdateEnabledStateUpdater(selectAction, undoTree);
    111115        wireUpdateEnabledStateUpdater(selectAction, redoTree);
     
    123127        }));
    124128       
    125         InputMapUtils.addEnterAction(undoTree, selectAction);
    126         InputMapUtils.addEnterAction(redoTree, selectAction);
     129        InputMapUtils.addEnterAction(undoTree, selectAndZoomAction);
     130        InputMapUtils.addEnterAction(redoTree, selectAndZoomAction);
    127131    }
    128132
     
    301305        return node;
    302306    }
     307   
     308    /**
     309     * Return primitives that are affected by some command
     310     * @param path GUI elements
     311     * @return collection of affected primitives, onluy usable ones
     312     */
     313    protected static FilteredCollection<OsmPrimitive> getAffectedPrimitives(TreePath path) {
     314        PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
     315        final OsmDataLayer currentLayer = Main.map.mapView.getEditLayer();
     316        FilteredCollection<OsmPrimitive> prims = new FilteredCollection<OsmPrimitive>(
     317                c.getParticipatingPrimitives(),
     318                new Predicate<OsmPrimitive>(){
     319                    public boolean evaluate(OsmPrimitive o) {
     320                        OsmPrimitive p = currentLayer.data.getPrimitiveById(o);
     321                        return p != null && p.isUsable();
     322                    }
     323                }
     324        );
     325        return prims;
     326    }
    303327
    304328    public void commandChanged(int queueSize, int redoSize) {
     
    318342        }
    319343
     344        @Override
    320345        public void actionPerformed(ActionEvent e) {
    321346            TreePath path;
     
    329354
    330355            if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return;
    331             PseudoCommand c = ((CommandListMutableTreeNode) path.getLastPathComponent()).getCommand();
    332 
    333             final OsmDataLayer currentLayer = Main.map.mapView.getEditLayer();
    334 
    335             FilteredCollection<OsmPrimitive> prims = new FilteredCollection<OsmPrimitive>(
    336                     c.getParticipatingPrimitives(),
    337                     new Predicate<OsmPrimitive>(){
    338                         public boolean evaluate(OsmPrimitive o) {
    339                             OsmPrimitive p = currentLayer.data.getPrimitiveById(o);
    340                             return p != null && p.isUsable();
    341                         }
    342                     }
    343             );
    344             Main.map.mapView.getEditLayer().data.setSelected(prims);
    345         }
    346 
     356            Main.map.mapView.getEditLayer().data.setSelected( getAffectedPrimitives(path));
     357        }
     358       
     359        @Override
    347360        public void updateEnabledState() {
    348361            setEnabled(!undoTree.isSelectionEmpty() || !redoTree.isSelectionEmpty());
     
    351364    }
    352365
     366    public class SelectAndZoomAction extends SelectAction {
     367        public SelectAndZoomAction() {
     368            super();
     369            putValue(NAME,tr("Select and zoom"));
     370            putValue(SHORT_DESCRIPTION, tr("Selects the objects that take part in this command (unless currently deleted), then and zooms to it"));
     371            putValue(SMALL_ICON, ImageProvider.get("dialogs/autoscale","selection"));
     372        }
     373
     374        @Override
     375        public void actionPerformed(ActionEvent e) {
     376            super.actionPerformed(e);
     377            if (Main.map == null || Main.map.mapView == null || Main.map.mapView.getEditLayer() == null) return;
     378            AutoScaleAction.autoScale("selection");
     379        }
     380    }
     381   
    353382    /**
    354383     * undo / redo switch to reduce duplicate code
     
    417446
    418447    class PopupMenuHandler extends PopupMenuLauncher {
     448       
     449        @Override
     450        public void mouseClicked(MouseEvent evt) {
     451            super.mouseClicked(evt);
     452            if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount()>1) {
     453                selectAndZoomAction.actionPerformed(null);
     454            }
     455        }
     456       
    419457        @Override
    420458        public void launch(MouseEvent evt) {
     
    430468                TreePath[] selPaths = tree.getSelectionPaths();
    431469
    432                 CommandStackPopup menu = new CommandStackPopup(selPaths);
     470                CommandStackPopup menu = new CommandStackPopup();
    433471                menu.show(tree, p.x, p.y-3);
    434472            }
     
    436474    }
    437475
     476   
    438477    private class CommandStackPopup extends JPopupMenu {
    439         private TreePath[] sel;
    440         public CommandStackPopup(TreePath[] sel){
    441             this.sel = sel;
    442             add(new SelectAction());
     478        public CommandStackPopup(){
     479            add(selectAction);
     480            add(selectAndZoomAction);
    443481        }
    444482    }
Note: See TracChangeset for help on using the changeset viewer.