示例#1
0
  private void onActiveLayerChanged(final Layer old) {
    fireActiveLayerChanged(old, activeLayer);

    /* This only makes the buttons look disabled. Disabling the actions as well requires
     * the user to re-select the tool after i.e. moving a layer. While testing I found
     * that I switch layers and actions at the same time and it was annoying to mind the
     * order. This way it works as visual clue for new users */
    for (final AbstractButton b : Main.map.allMapModeButtons) {
      MapMode mode = (MapMode) b.getAction();
      final boolean activeLayerSupported = mode.layerIsSupported(activeLayer);
      if (activeLayerSupported) {
        Main.registerActionShortcut(mode, mode.getShortcut()); // fix #6876
      } else {
        Main.unregisterShortcut(mode.getShortcut());
      }
      GuiHelper.runInEDTAndWait(
          new Runnable() {
            @Override
            public void run() {
              b.setEnabled(activeLayerSupported);
            }
          });
    }
    AudioPlayer.reset();
    repaint();
  }
示例#2
0
  private JButton addButtonAndShortcut(ActionDefinition action) {
    Action act = action.getParametrizedAction();
    JButton b = control.add(act);

    Shortcut sc = null;
    if (action.getAction() instanceof JosmAction) {
      sc = ((JosmAction) action.getAction()).getShortcut();
      if (sc.getAssignedKey() == KeyEvent.CHAR_UNDEFINED) {
        sc = null;
      }
    }

    long paramCode = 0;
    if (action.hasParameters()) {
      paramCode = action.parameters.hashCode();
    }

    String tt = action.getDisplayTooltip();
    if (tt == null) {
      tt = "";
    }

    if (sc == null || paramCode != 0) {
      String name = (String) action.getAction().getValue("toolbar");
      if (name == null) {
        name = action.getDisplayName();
      }
      if (paramCode != 0) {
        name = name + paramCode;
      }
      String desc =
          action.getDisplayName() + ((paramCode == 0) ? "" : action.parameters.toString());
      sc =
          Shortcut.registerShortcut(
              "toolbar:" + name, tr("Toolbar: {0}", desc), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE);
      Main.unregisterShortcut(sc);
      Main.registerActionShortcut(act, sc);

      // add shortcut info to the tooltip if needed
      if (sc.getAssignedUser()) {
        if (tt.startsWith("<html>") && tt.endsWith("</html>")) {
          tt = tt.substring(6, tt.length() - 6);
        }
        tt = Main.platform.makeTooltip(tt, sc);
      }
    }

    if (!tt.isEmpty()) {
      b.setToolTipText(tt);
    }
    return b;
  }
 /**
  * Constructs a new <code>RecentRelationsAction</code>.
  *
  * @param editButton edit button
  */
 public RecentRelationsAction(SideButton editButton) {
   this.editButton = editButton;
   arrow = editButton.createArrow(this);
   arrow.setToolTipText(tr("List of recent relations"));
   Main.main.undoRedo.addCommandQueueListener(this);
   Main.getLayerManager().addLayerChangeListener(this);
   Main.getLayerManager().addActiveLayerChangeListener(this);
   enableArrow();
   shortcut =
       Shortcut.registerShortcut(
           "relationeditor:editrecentrelation",
           tr("Relation Editor: {0}", tr("Open recent relation")),
           KeyEvent.VK_ESCAPE,
           Shortcut.SHIFT);
   Main.registerActionShortcut(new LaunchEditorAction(), shortcut);
 }
示例#4
0
 /**
  * Constructs a new <code>RecentRelationsAction</code>.
  *
  * @param editButton edit button
  */
 public RecentRelationsAction(SideButton editButton) {
   this.editButton = editButton;
   arrow = editButton.createArrow(this);
   arrow.setToolTipText(tr("List of recent relations"));
   Main.main.undoRedo.addCommandQueueListener(this);
   MapView.addLayerChangeListener(this);
   enableArrow();
   shortcut =
       Shortcut.registerShortcut(
           "relationeditor:editrecentrelation",
           tr("Relation Editor: {0}", tr("Open recent relation")),
           KeyEvent.VK_ESCAPE,
           Shortcut.SHIFT);
   Main.registerActionShortcut(
       new AbstractAction() {
         @Override
         public void actionPerformed(ActionEvent e) {
           EditRelationAction.launchEditor(getLastRelation());
         }
       },
       shortcut);
 }