Changeset 5727 in josm
- Timestamp:
- 2013-02-18T12:03:30+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r5200 r5727 38 38 39 39 import org.openstreetmap.josm.Main; 40 import org.openstreetmap.josm.actions.AutoScaleAction; 40 41 import org.openstreetmap.josm.command.Command; 41 42 import org.openstreetmap.josm.command.PseudoCommand; … … 73 74 private UndoRedoType lastOperation = UndoRedoType.UNDO; 74 75 76 // Actions for context menu and Enter key 77 private SelectAction selectAction = new SelectAction(); 78 private SelectAndZoomAction selectAndZoomAction = new SelectAndZoomAction(); 79 75 80 public CommandStackDialog(final MapFrame mapFrame) { 76 81 super(tr("Command Stack"), "commandstack", tr("Open a list of all commands (undo buffer)."), … … 107 112 treesPanel.setBackground(redoTree.getBackground()); 108 113 109 SelectAction selectAction = new SelectAction();110 114 wireUpdateEnabledStateUpdater(selectAction, undoTree); 111 115 wireUpdateEnabledStateUpdater(selectAction, redoTree); … … 123 127 })); 124 128 125 InputMapUtils.addEnterAction(undoTree, selectA ction);126 InputMapUtils.addEnterAction(redoTree, selectA ction);129 InputMapUtils.addEnterAction(undoTree, selectAndZoomAction); 130 InputMapUtils.addEnterAction(redoTree, selectAndZoomAction); 127 131 } 128 132 … … 301 305 return node; 302 306 } 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 } 303 327 304 328 public void commandChanged(int queueSize, int redoSize) { … … 318 342 } 319 343 344 @Override 320 345 public void actionPerformed(ActionEvent e) { 321 346 TreePath path; … … 329 354 330 355 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 347 360 public void updateEnabledState() { 348 361 setEnabled(!undoTree.isSelectionEmpty() || !redoTree.isSelectionEmpty()); … … 351 364 } 352 365 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 353 382 /** 354 383 * undo / redo switch to reduce duplicate code … … 417 446 418 447 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 419 457 @Override 420 458 public void launch(MouseEvent evt) { … … 430 468 TreePath[] selPaths = tree.getSelectionPaths(); 431 469 432 CommandStackPopup menu = new CommandStackPopup( selPaths);470 CommandStackPopup menu = new CommandStackPopup(); 433 471 menu.show(tree, p.x, p.y-3); 434 472 } … … 436 474 } 437 475 476 438 477 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); 443 481 } 444 482 }
Note:
See TracChangeset
for help on using the changeset viewer.