| | 425 | * The action to toggle visible state of the index-specified layer |
| | 426 | */ |
| | 427 | public final class ShowHideLayerNAction extends AbstractAction { |
| | 428 | private int n; |
| | 429 | |
| | 430 | /** |
| | 431 | * Creates a {@see ShowHideLayerNAction} which will toggle the visibility of |
| | 432 | * a index-specified layer |
| | 433 | * |
| | 434 | * @param n index of a layer |
| | 435 | */ |
| | 436 | public ShowHideLayerNAction(int n) { |
| | 437 | this.n = n; |
| | 438 | Main.registerActionShortcut(this, Shortcut.registerShortcut("layer:showhide." + n, |
| | 439 | tr("{0}: {1} {2}", tr("Layers"), tr("Show/Hide layer"), Integer.toString(n+1)), |
| | 440 | KeyEvent.VK_0 + ((n+1)%10), Shortcut.GROUP_NONE)); |
| | 441 | } |
| | 442 | |
| | 443 | public void actionPerformed(ActionEvent e) { |
| | 444 | Layer layer = model.getLayer(n); |
| | 445 | if (layer == null) { |
| | 446 | return; |
| | 447 | } |
| | 448 | layer.toggleVisible(); |
| | 449 | } |
| | 450 | |
| | 451 | @Override |
| | 452 | public boolean equals(Object obj) { |
| | 453 | if (!(obj instanceof ShowHideLayerNAction)) return false; |
| | 454 | ShowHideLayerNAction other = (ShowHideLayerNAction) obj; |
| | 455 | return (other.n == this.n); |
| | 456 | } |
| | 457 | |
| | 458 | @Override |
| | 459 | public int hashCode() { |
| | 460 | return getClass().hashCode(); |
| | 461 | } |
| | 462 | |
| | 463 | } |
| | 464 | |
| | 465 | /** |
| | 531 | * The action to activate the index-specified layer |
| | 532 | */ |
| | 533 | public final class ActivateLayerNAction extends AbstractAction { |
| | 534 | private int n; |
| | 535 | |
| | 536 | /** |
| | 537 | * Creates a {@see ActivateLayerNAction} which will activate |
| | 538 | * a index-specified layer |
| | 539 | * |
| | 540 | * @param n index of a layer |
| | 541 | */ |
| | 542 | public ActivateLayerNAction(int n) { |
| | 543 | this.n = n; |
| | 544 | Main.registerActionShortcut(this, Shortcut.registerShortcut("layer:activate." + n, |
| | 545 | tr("{0}: {1} {2}", tr("Layers"), tr("Activate layer"), Integer.toString(n+1)), |
| | 546 | KeyEvent.VK_0 + ((n+1)%10), Shortcut.GROUP_NONE)); |
| | 547 | } |
| | 548 | |
| | 549 | public void actionPerformed(ActionEvent e) { |
| | 550 | Layer layer = model.getLayer(n); |
| | 551 | if (layer == null) { |
| | 552 | return; |
| | 553 | } |
| | 554 | // model is going to be updated via LayerChangeListener |
| | 555 | // and PropertyChangeEvents |
| | 556 | Main.map.mapView.setActiveLayer(layer); |
| | 557 | layer.setVisible(true); |
| | 558 | } |
| | 559 | |
| | 560 | @Override |
| | 561 | public boolean equals(Object obj) { |
| | 562 | if (!(obj instanceof ActivateLayerNAction)) return false; |
| | 563 | ActivateLayerNAction other = (ActivateLayerNAction) obj; |
| | 564 | return (other.n == this.n); |
| | 565 | } |
| | 566 | |
| | 567 | @Override |
| | 568 | public int hashCode() { |
| | 569 | return getClass().hashCode(); |
| | 570 | } |
| | 571 | |
| | 572 | } |
| | 573 | |
| | 574 | /** |