Example #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();
  }
Example #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;
  }