- Timestamp:
- 2011-11-15T20:09:57+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r4456 r4595 16 16 import java.beans.PropertyChangeEvent; 17 17 import java.beans.PropertyChangeListener; 18 import java.lang.ref.WeakReference; 18 19 import java.util.ArrayList; 19 20 import java.util.Arrays; … … 64 65 import org.openstreetmap.josm.tools.CheckParameterUtil; 65 66 import org.openstreetmap.josm.tools.ImageProvider; 67 import org.openstreetmap.josm.tools.MultikeyActionsHandler; 68 import org.openstreetmap.josm.tools.MultikeyShortcutAction; 69 import org.openstreetmap.josm.tools.MultikeyShortcutAction.MultikeyInfo; 66 70 import org.openstreetmap.josm.tools.Shortcut; 67 71 … … 85 89 throw new IllegalStateException("Dialog was already created"); 86 90 instance = new LayerListDialog(mapFrame); 91 92 MultikeyActionsHandler.getInstance().addAction(instance.new ShowHideLayerAction(false)); 87 93 } 88 94 … … 113 119 ActivateLayerAction activateLayerAction; 114 120 121 //TODO This duplicates ShowHide actions functionality 115 122 /** stores which layer index to toggle and executes the ShowHide action if the layer is present */ 116 123 private final class ToggleLayerIndexVisibility extends AbstractAction { … … 123 130 final Layer l = model.getLayer(model.getRowCount() - layerIndex); 124 131 if(l != null) { 125 new ShowHideLayerAction(l).actionPerformed(e);132 l.toggleVisible(); 126 133 } 127 134 } … … 258 265 259 266 createLayout(layerList, true, Arrays.asList(new SideButton[] { 260 new SideButton(moveUpAction),261 new SideButton(moveDownAction),262 new SideButton(activateLayerAction),263 new SideButton(showHideLayerAction),264 opacityButton,265 new SideButton(mergeLayerAction),266 new SideButton(duplicateLayerAction),267 new SideButton(deleteLayerAction, false)267 new SideButton(moveUpAction), 268 new SideButton(moveDownAction), 269 new SideButton(activateLayerAction), 270 new SideButton(showHideLayerAction), 271 opacityButton, 272 new SideButton(mergeLayerAction), 273 new SideButton(duplicateLayerAction), 274 new SideButton(deleteLayerAction, false) 268 275 })); 269 276 … … 420 427 } 421 428 422 public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction { 423 private Layer layer; 424 425 /** 426 * Creates a {@see ShowHideLayerAction} which toggle the visibility of 427 * a specific layer. 428 * 429 * @param layer the layer. Must not be null. 430 * @exception IllegalArgumentException thrown, if layer is null 431 */ 432 public ShowHideLayerAction(Layer layer) throws IllegalArgumentException { 433 this(); 434 putValue(NAME, tr("Show/Hide")); 435 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 436 this.layer = layer; 437 updateEnabledState(); 438 } 429 public final class ShowHideLayerAction extends AbstractAction implements IEnabledStateUpdating, LayerAction, MultikeyShortcutAction { 430 431 private WeakReference<Layer> lastLayer; 439 432 440 433 /** … … 443 436 * 444 437 */ 445 public ShowHideLayerAction( ) {438 public ShowHideLayerAction(boolean init) { 446 439 putValue(SMALL_ICON, ImageProvider.get("dialogs", "showhide")); 447 440 putValue(SHORT_DESCRIPTION, tr("Toggle visible state of the selected layer.")); 448 441 putValue("help", HelpUtil.ht("/Dialog/LayerList#ShowHideLayer")); 449 updateEnabledState(); 442 putValue(ACCELERATOR_KEY, Shortcut.registerShortcut("core_multikey:showHideLayer", "", 'S', Shortcut.GROUP_DIRECT, KeyEvent.ALT_DOWN_MASK + KeyEvent.CTRL_DOWN_MASK).getKeyStroke()); 443 if (init) { 444 updateEnabledState(); 445 } 446 } 447 448 public ShowHideLayerAction() { 449 this(true); 450 450 } 451 451 452 452 @Override 453 453 public void actionPerformed(ActionEvent e) { 454 if (layer != null) { 455 layer.toggleVisible(); 456 } else { 457 for(Layer l : model.getSelectedLayers()) { 454 for(Layer l : model.getSelectedLayers()) { 455 l.toggleVisible(); 456 } 457 } 458 459 @Override 460 public void executeMultikeyAction(int index) { 461 Layer l = LayerListDialog.getLayerForIndex(index); 462 if (l != null) { 463 l.toggleVisible(); 464 lastLayer = new WeakReference<Layer>(l); 465 } 466 } 467 468 @Override 469 public void repeateLastMultikeyAction() { 470 if (lastLayer != null) { 471 Layer l = lastLayer.get(); 472 if (LayerListDialog.isLayerValid(l)) { 458 473 l.toggleVisible(); 459 474 } … … 463 478 @Override 464 479 public void updateEnabledState() { 465 if (layer == null) { 466 setEnabled(! getModel().getSelectedLayers().isEmpty()); 467 } else { 468 setEnabled(true); 469 } 480 setEnabled(!model.getSelectedLayers().isEmpty()); 470 481 } 471 482 … … 488 499 public int hashCode() { 489 500 return getClass().hashCode(); 501 } 502 503 @Override 504 public List<MultikeyInfo> getMultikeyCombinations() { 505 return LayerListDialog.getLayerInfoByClass(Layer.class); 506 } 507 508 @Override 509 public MultikeyInfo getLastMultikeyAction() { 510 if (lastLayer != null) 511 return LayerListDialog.getLayerInfo(lastLayer.get()); 512 return null; 490 513 } 491 514 } … … 905 928 } 906 929 } 907 if(c == null) 930 if(c == null) { 908 931 c = Main.pref.getUIColor(isSelected ? "Table.selectionForeground" : "Table.foreground"); 932 } 909 933 label.setForeground(c); 910 934 } … … 1459 1483 */ 1460 1484 public ShowHideLayerAction createShowHideLayerAction() { 1461 ShowHideLayerAction act = new ShowHideLayerAction( );1485 ShowHideLayerAction act = new ShowHideLayerAction(true); 1462 1486 act.putValue(Action.NAME, tr("Show/Hide")); 1463 1487 return act; … … 1497 1521 return new MergeAction(layer); 1498 1522 } 1523 1524 public static Layer getLayerForIndex(int index) { 1525 1526 if (!Main.isDisplayingMapView()) 1527 return null; 1528 1529 List<Layer> layers = Main.map.mapView.getAllLayersAsList(); 1530 1531 if (index < layers.size()) 1532 return layers.get(index); 1533 else 1534 return null; 1535 } 1536 1537 public static List<MultikeyInfo> getLayerInfoByClass(Class<? extends Layer> layerClass) { 1538 1539 List<MultikeyInfo> result = new ArrayList<MultikeyShortcutAction.MultikeyInfo>(); 1540 1541 if (!Main.isDisplayingMapView()) 1542 return result; 1543 1544 List<Layer> layers = Main.map.mapView.getAllLayersAsList(); 1545 1546 int index = 0; 1547 for (Layer l: layers) { 1548 if (layerClass.isAssignableFrom(l.getClass())) { 1549 result.add(new MultikeyInfo(index, l.getName())); 1550 } 1551 index++; 1552 } 1553 1554 return result; 1555 } 1556 1557 public static boolean isLayerValid(Layer l) { 1558 if (l == null) 1559 return false; 1560 1561 if (!Main.isDisplayingMapView()) 1562 return false; 1563 1564 return Main.map.mapView.getAllLayersAsList().indexOf(l) >= 0; 1565 } 1566 1567 public static MultikeyInfo getLayerInfo(Layer l) { 1568 1569 if (l == null) 1570 return null; 1571 1572 if (!Main.isDisplayingMapView()) 1573 return null; 1574 1575 int index = Main.map.mapView.getAllLayersAsList().indexOf(l); 1576 if (index < 0) 1577 return null; 1578 1579 return new MultikeyInfo(index, l.getName()); 1580 } 1499 1581 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r4282 r4595 12 12 import java.awt.Point; 13 13 import java.awt.event.ActionEvent; 14 import java.awt.event.KeyEvent; 14 15 import java.awt.event.MouseAdapter; 15 16 import java.awt.event.MouseEvent; 16 17 import java.io.File; 18 import java.lang.ref.WeakReference; 17 19 import java.net.URL; 18 20 import java.util.ArrayList; … … 42 44 import org.openstreetmap.josm.tools.AudioPlayer; 43 45 import org.openstreetmap.josm.tools.ImageProvider; 46 import org.openstreetmap.josm.tools.MultikeyActionsHandler; 47 import org.openstreetmap.josm.tools.MultikeyShortcutAction; 48 import org.openstreetmap.josm.tools.Shortcut; 44 49 45 50 /** … … 59 64 * A list of markers. 60 65 */ 61 public final Collection<Marker> data;66 public final List<Marker> data; 62 67 private boolean mousePressed = false; 63 68 public GpxLayer fromLayer = null; 64 65 @SuppressWarnings("unchecked") 69 private Marker currentMarker; 70 66 71 public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer) { 67 72 … … 125 130 } 126 131 132 static { 133 MultikeyActionsHandler.getInstance().addAction(new JumpToNextMarker(null)); 134 MultikeyActionsHandler.getInstance().addAction(new JumpToPreviousMarker(null)); 135 } 136 137 127 138 /** 128 139 * Return a static icon. … … 200 211 components.add (new MoveAudio()); 201 212 } 213 components.add(new JumpToNextMarker(this)); 214 components.add(new JumpToPreviousMarker(this)); 202 215 components.add(new RenameLayerAction(getAssociatedFile(), this)); 203 216 components.add(SeparatorLayerAction.INSTANCE); … … 292 305 data.addAll(newData); 293 306 return ret; 307 } 308 309 public void jumpToNextMarker() { 310 if (currentMarker == null) { 311 currentMarker = data.get(0); 312 } else { 313 boolean foundCurrent = false; 314 for (Marker m: data) { 315 if (foundCurrent) { 316 currentMarker = m; 317 break; 318 } else if (currentMarker == m) { 319 foundCurrent = true; 320 } 321 } 322 } 323 Main.map.mapView.zoomTo(currentMarker.getEastNorth()); 324 } 325 326 public void jumpToPreviousMarker() { 327 if (currentMarker == null) { 328 currentMarker = data.get(data.size() - 1); 329 } else { 330 boolean foundCurrent = false; 331 for (int i=data.size() - 1; i>=0; i--) { 332 Marker m = data.get(i); 333 if (foundCurrent) { 334 currentMarker = m; 335 break; 336 } else if (currentMarker == m) { 337 foundCurrent = true; 338 } 339 } 340 } 341 Main.map.mapView.zoomTo(currentMarker.getEastNorth()); 294 342 } 295 343 … … 393 441 } 394 442 443 public static final class JumpToNextMarker extends AbstractAction implements MultikeyShortcutAction { 444 445 private final MarkerLayer layer; 446 private WeakReference<MarkerLayer> lastLayer; 447 448 public JumpToNextMarker(MarkerLayer layer) { 449 putValue(ACCELERATOR_KEY, Shortcut.registerShortcut("core_multikey:nextMarker", "", 'J', Shortcut.GROUP_DIRECT, KeyEvent.ALT_DOWN_MASK + KeyEvent.CTRL_DOWN_MASK).getKeyStroke()); 450 putValue(SHORT_DESCRIPTION, tr("Jump to next marker")); 451 putValue(NAME, tr("Jump to next marker")); 452 453 this.layer = layer; 454 } 455 456 @Override 457 public void actionPerformed(ActionEvent e) { 458 execute(layer); 459 } 460 461 @Override 462 public void executeMultikeyAction(int index) { 463 Layer l = LayerListDialog.getLayerForIndex(index); 464 if (l != null && l instanceof MarkerLayer) { 465 execute((MarkerLayer) l); 466 } 467 } 468 469 @Override 470 public void repeateLastMultikeyAction() { 471 if (lastLayer != null) { 472 MarkerLayer l = lastLayer.get(); 473 if (LayerListDialog.isLayerValid(l)) { 474 execute(l); 475 } 476 } 477 } 478 479 private void execute(MarkerLayer l) { 480 l.jumpToNextMarker(); 481 lastLayer = new WeakReference<MarkerLayer>(l); 482 } 483 484 @Override 485 public List<MultikeyInfo> getMultikeyCombinations() { 486 return LayerListDialog.getLayerInfoByClass(MarkerLayer.class); 487 } 488 489 @Override 490 public MultikeyInfo getLastMultikeyAction() { 491 if (lastLayer != null) 492 return LayerListDialog.getLayerInfo(lastLayer.get()); 493 else 494 return null; 495 } 496 497 } 498 499 public static final class JumpToPreviousMarker extends AbstractAction implements MultikeyShortcutAction { 500 501 private WeakReference<MarkerLayer> lastLayer; 502 private final MarkerLayer layer; 503 504 public JumpToPreviousMarker(MarkerLayer layer) { 505 this.layer = layer; 506 507 putValue(ACCELERATOR_KEY, Shortcut.registerShortcut("core_multikey:previousMarker", "", 'P', Shortcut.GROUP_DIRECT, KeyEvent.ALT_DOWN_MASK + KeyEvent.CTRL_DOWN_MASK).getKeyStroke()); 508 putValue(SHORT_DESCRIPTION, tr("Jump to previous marker")); 509 putValue(NAME, tr("Jump to previous marker")); 510 } 511 512 @Override 513 public void actionPerformed(ActionEvent e) { 514 execute(layer); 515 } 516 517 @Override 518 public void executeMultikeyAction(int index) { 519 Layer l = LayerListDialog.getLayerForIndex(index); 520 if (l != null && l instanceof MarkerLayer) { 521 execute((MarkerLayer) l); 522 } 523 } 524 525 @Override 526 public void repeateLastMultikeyAction() { 527 if (lastLayer != null) { 528 MarkerLayer l = lastLayer.get(); 529 if (LayerListDialog.isLayerValid(l)) { 530 execute(l); 531 } 532 } 533 } 534 535 private void execute(MarkerLayer l) { 536 l.jumpToPreviousMarker(); 537 lastLayer = new WeakReference<MarkerLayer>(l); 538 } 539 540 @Override 541 public List<MultikeyInfo> getMultikeyCombinations() { 542 return LayerListDialog.getLayerInfoByClass(MarkerLayer.class); 543 } 544 545 @Override 546 public MultikeyInfo getLastMultikeyAction() { 547 if (lastLayer != null) 548 return LayerListDialog.getLayerInfo(lastLayer.get()); 549 else 550 return null; 551 } 552 553 } 554 395 555 private class SynchronizeAudio extends AbstractAction { 396 556 … … 455 615 } 456 616 } 617 457 618 } -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r4418 r4595 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.Menu;5 4 import static org.openstreetmap.josm.tools.I18n.tr; 6 5 … … 209 208 } 210 209 210 @Override 211 public String toString() { 212 return getKeyText(); 213 } 214 211 215 /////////////////////////////// 212 216 // everything's static below // … … 504 508 : 505 509 tr("Using the shortcut ''{0}'' instead.\n\n", potentialShortcut.getKeyText()) 506 )+507 tr("(Hint: You can edit the shortcuts in the preferences.)"),508 tr("Error"),509 JOptionPane.ERROR_MESSAGE510 );510 )+ 511 tr("(Hint: You can edit the shortcuts in the preferences.)"), 512 tr("Error"), 513 JOptionPane.ERROR_MESSAGE 514 ); 511 515 } 512 516
Note:
See TracChangeset
for help on using the changeset viewer.