/**
  * Fill the specified tool bar with the elements that have the given URI as their parent.
  *
  * <p>Existing elements on the tool bar will be removed.
  *
  * @param toolbar The {@link JToolBar} to update
  * @param id The {@link URI} of the tool bar
  */
 protected void populateToolBar(JToolBar toolbar, URI id) {
   toolbar.removeAll();
   MenuComponent toolbarDef = uriToMenuElement.get(id);
   if (toolbarDef == null) throw new IllegalArgumentException("Unknown toolBar " + id);
   if (!toolbarDef.getType().equals(MenuType.toolBar))
     throw new IllegalArgumentException(
         "Element " + id + " is not a toolBar, but a " + toolbarDef.getType());
   if (toolbarDef.getAction() != null) {
     String name = (String) toolbarDef.getAction().getValue(Action.NAME);
     toolbar.setName(name);
   } else toolbar.setName("");
   MenuOptions menuOptions = new MenuOptions();
   menuOptions.setToolbar(true);
   for (Component component : makeComponents(id, menuOptions)) {
     if (component == null) {
       toolbar.addSeparator();
       continue;
     }
     if (component instanceof JButton) {
       JButton toolbarButton = (JButton) component;
       toolbarButton.putClientProperty("hideActionText", true);
     }
     toolbar.add(component);
   }
 }
Ejemplo n.º 2
0
  /**
   * Parse the toolbar preference setting and construct the toolbar GUI control.
   *
   * <p>Call this, if anything has changed in the toolbar settings and you want to refresh the
   * toolbar content (e.g. after registering actions in a plugin)
   */
  public void refreshToolbarControl() {
    control.removeAll();
    buttonActions.clear();
    boolean unregisterTab = Shortcut.findShortcut(KeyEvent.VK_TAB, 0) != null;

    for (ActionDefinition action : getDefinedActions()) {
      if (action.isSeparator()) {
        control.addSeparator();
      } else {
        final JButton b = addButtonAndShortcut(action);
        buttonActions.put(b, action);

        Icon i = action.getDisplayIcon();
        if (i != null) {
          b.setIcon(i);
        } else {
          // hide action text if an icon is set later (necessary for delayed/background image
          // loading)
          action
              .getParametrizedAction()
              .addPropertyChangeListener(
                  new PropertyChangeListener() {

                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                      if (Action.SMALL_ICON.equals(evt.getPropertyName())) {
                        b.setHideActionText(evt.getNewValue() != null);
                      }
                    }
                  });
        }
        b.setInheritsPopupMenu(true);
        b.setFocusTraversalKeysEnabled(!unregisterTab);
      }
    }
    control.setFocusTraversalKeysEnabled(!unregisterTab);
    control.setVisible(control.getComponentCount() != 0);
  }
Ejemplo n.º 3
0
 public void removeAll() {
   super.removeAll();
   addGrip();
 }