Ejemplo n.º 1
0
  /**
   * Manages the selection of the default tool in a popup tool in the toolbar.
   *
   * <p>I.e. in a toolbar, you can have tools that can be opened, into a grid of tools. The last
   * used tool is remembered, and put at the top when the popup is closed, i.e. is the only tool
   * that remains visible. This remembering is persistent, hence stored in the configuration file,
   * under a certain key (i.e. name).
   *
   * @param actions the array of actions that make up the popup
   * @param key appendix for the key for the configuration file
   */
  public static void manageDefault(Object[] actions, String key) {
    Action defaultAction = null;
    ConfigurationKey k = Configuration.makeKey("default", "popupactions", key);
    String defaultName = Configuration.getString(k);
    PopupActionsListener listener = new PopupActionsListener(k);
    for (int i = 0; i < actions.length; ++i) {
      if (actions[i] instanceof Action) {
        Action a = (Action) actions[i];
        if (a.getValue(Action.NAME).equals(defaultName)) {
          defaultAction = a;
        }
        a.addPropertyChangeListener(listener);
      } else if (actions[i] instanceof Object[]) {
        Object[] actionRow = (Object[]) actions[i];
        for (int j = 0; j < actionRow.length; ++j) {
          Action a = (Action) actionRow[j];
          if (a.getValue(Action.NAME).equals(defaultName)) {
            defaultAction = a;
          }
          a.addPropertyChangeListener(listener);
        }
      }
    }

    if (defaultAction != null) {
      defaultAction.putValue("isDefault", Boolean.valueOf(true));
    }
  }
Ejemplo n.º 2
0
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
Ejemplo n.º 3
0
 /** Overridden for internal reasons, no API changes. */
 public void setAction(Action a) {
   Action oldAction = getAction();
   if (oldAction != null) {
     oldAction.removePropertyChangeListener(getListener());
   }
   super.setAction(a);
   setButtonFromAction(a);
   a.addPropertyChangeListener(getListener());
 }
Ejemplo n.º 4
0
 /** Configures a JCheckBoxMenuItem for an Action. */
 public static void configureJCheckBoxMenuItem(final JCheckBoxMenuItem mi, final Action a) {
   mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
   PropertyChangeListener propertyHandler =
       new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent evt) {
           if (evt.getPropertyName().equals(Actions.SELECTED_KEY)) {
             mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
           }
         }
       };
   a.addPropertyChangeListener(propertyHandler);
   mi.putClientProperty("actionPropertyHandler", propertyHandler);
 }
Ejemplo n.º 5
0
  /**
   * Creates an ActionAdapter
   *
   * @param action the Swing action to wrap
   * @param style the JFace action style
   * @see Action#Action(String, int)
   */
  public RcpActionAdapter(final javax.swing.Action action, int style) {
    super(null, style);

    if (action == null) throw new IllegalArgumentException();

    this.action = action;

    this.display = Display.getCurrent();
    if (this.display == null)
      throw new IllegalArgumentException(
          "ActionAdapter has to be created in display thread"); //$NON-NLS-1$

    action.addPropertyChangeListener(this);

    loadImage();
  }
Ejemplo n.º 6
0
 public void addAction(final Action action) {
   action.addPropertyChangeListener(this);
   final LinkLabel label =
       new LinkLabel(
           null,
           null,
           new LinkListener() {
             public void linkSelected(final LinkLabel aSource, final Object aLinkData) {
               action.actionPerformed(
                   new ActionEvent(
                       Banner.this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY));
             }
           });
   myActions.put(action, label);
   myActionsPanel.add(label);
   updateAction(action);
 }
Ejemplo n.º 7
0
 @Override
 public void resultChanged(LookupEvent ev) {
   Collection lcs = lcResult.allInstances();
   if (lcs.isEmpty()) {
     setEnabled(false);
   } else {
     // assuming that there'll be only one layercontroller in context
     LayerController lc = (LayerController) lcs.iterator().next();
     if (delegate != null) {
       delegate.removePropertyChangeListener(this);
     }
     ExplorerManager em = lc.getExplorerManager();
     delegate = ExplorerUtils.actionDelete(em, false);
     delegate.addPropertyChangeListener(this);
     setEnabled(delegate.isEnabled());
   }
 }
Ejemplo n.º 8
0
    public void editorActivated() {
      Action ea = getEditorAction();
      Action sa = getSystemAction();
      if (ea != null && sa != null) {
        if (updatePerformer) {
          if (ea.isEnabled() && sa instanceof CallbackSystemAction) {
            ((CallbackSystemAction) sa).setActionPerformer(this);
          }
        }

        if (syncEnabling) {
          if (enabledPropertySyncL == null) {
            enabledPropertySyncL = new EnabledPropertySyncListener(sa);
          }
          ea.addPropertyChangeListener(enabledPropertySyncL);
        }
      }
    }
Ejemplo n.º 9
0
  protected AbstractButton addButton(Action action) {
    boolean isToggle = action instanceof AbstractFXDToggleAction;
    Border buttonBorder = UIManager.getBorder("nb.tabbutton.border"); // NOI18N
    AbstractButton button;

    if (isToggle) {
      final JToggleButton tButton = new JToggleButton(action);
      action.addPropertyChangeListener(
          new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent evt) {
              if (AbstractFXDToggleAction.SELECTION_STATE.equals(evt.getPropertyName())) {
                tButton.setSelected(((Boolean) evt.getNewValue()).booleanValue());
                tButton.repaint();
              }
            }
          });
      Boolean state = (Boolean) action.getValue(AbstractFXDToggleAction.SELECTION_STATE);
      if (state != null) {
        tButton.setSelected(state.booleanValue());
      }
      button = tButton;
    } else {
      button = new JButton(action);
    }

    if (buttonBorder != null) {
      button.setBorder(buttonBorder);
    }
    GridBagConstraints constrains = new GridBagConstraints();
    constrains.anchor = GridBagConstraints.WEST;
    constrains.insets = new Insets(0, 3, 0, 2);

    button.setContentAreaFilled(true);
    button.setBorderPainted(true);
    if (button instanceof JButton) {
      button.addMouseListener(m_buttonListener);
    }
    // @inherited fix of issue #69642. Focus shouldn't stay in toolbar
    button.setFocusable(false);
    add(button, constrains);
    return button;
  }
Ejemplo n.º 10
0
 /**
  * Constructs a toolbar button for the given action and returns it.
  *
  * @param action The action to create a toolbar button for.
  * @param toggle If set to <code>true</code>, indicates that a <code>JToggleButton</code> shall be
  *     returned rather than a <code>JButton</code>.
  * @return The according <code>AbstractButton</code>.
  */
 public static AbstractButton createToolbarButton(Action action, boolean toggle) {
   AbstractButton butt = null;
   if (action instanceof ViewAction) {
     if (((ViewAction) action).getView().isMultipleInstancePerSessionElementAllowed()) {
       butt = new JButton(action);
     } else {
       butt = new JToggleButton(action);
     }
     butt.setText(null);
     ((ViewAction) action).addButton(butt);
   }
   if (butt == null) {
     if (toggle) {
       butt = new JButton(action);
     } else {
       butt = new JButton(action /*(Icon) action.getValue( Action.SMALL_ICON )*/);
     }
     butt.setText(null);
     action.putValue("button", butt);
     if (action instanceof ViewAction) {
       ((ViewAction) action).addButton(butt);
       butt.setDisabledIcon(SPACER);
     } else {
       action.addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
               if ("enabled".equals(e.getPropertyName())) {
                 ((AbstractButton) ((Action) e.getSource()).getValue("button"))
                     .setEnabled(((Boolean) e.getNewValue()).booleanValue());
               }
             }
           });
     }
   }
   // butt.addActionListener( action );
   butt.setEnabled(action.isEnabled());
   butt.setMaximumSize(new Dimension(22, 22));
   butt.setToolTipText((String) action.getValue("toolTipText"));
   butt.setMargin(new Insets(2, 2, 2, 2));
   butt.setFocusable(false);
   return butt;
 }
Ejemplo n.º 11
0
 private void fixIcon(Action action) {
   // need to listen for changes, so that putValue() that are called after the
   // SideButton is constructed get the proper icon size
   if (action != null) {
     action.addPropertyChangeListener(
         propertyChangeListener =
             new PropertyChangeListener() {
               @Override
               public void propertyChange(PropertyChangeEvent evt) {
                 if (evt.getPropertyName() == javax.swing.Action.SMALL_ICON) {
                   fixIcon(null);
                 }
               }
             });
   }
   Icon i = getIcon();
   if (i instanceof ImageIcon && i.getIconHeight() != iconHeight) {
     setIcon(getScaledImage(((ImageIcon) i).getImage()));
   }
 }
Ejemplo n.º 12
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }
Ejemplo n.º 13
0
  public BoundMenuCommandButton(
      CommandButtonKind kind,
      String text,
      String description,
      ResizableIcon icon,
      ResizableIcon disabledIcon,
      Action action) {
    super(text, icon);
    this.action = action;
    setCommandButtonKind(kind);
    setDisabledIcon(disabledIcon);
    addActionListener(action);

    RichTooltip tooltip = new RichTooltip();
    tooltip.setTitle(getText());
    tooltip.addDescriptionSection(
        description == null || description.length() == 0 ? " " : description);
    setActionRichTooltip(tooltip);
    setPopupRichTooltip(tooltip);

    PropertyChangeListener l =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if ("enabled".equals(evt.getPropertyName())) {
              updateState();
            }
            if (Action.SHORT_DESCRIPTION.equals(evt.getPropertyName())) {
              updateTooltip();
            }
          }
        };

    action.addPropertyChangeListener(l);

    updateState();
    updateTooltip();
  }
Ejemplo n.º 14
0
 public void addPropertyChangeListener(PropertyChangeListener listener) {
   delegate.addPropertyChangeListener(listener);
 }
Ejemplo n.º 15
0
 /**
  * Creates a new MenuActionObserver object.
  *
  * @param item TODO: DOCUMENT ME!
  * @param action TODO: DOCUMENT ME!
  */
 public MenuActionObserver(JMenuItem item, Action action) {
   this.item = item;
   action.addPropertyChangeListener(this);
 }
Ejemplo n.º 16
0
 /** {@inheritDoc} */
 @Override
 public void addPropertyChangeListener(java.beans.PropertyChangeListener listener) {
   delegate.addPropertyChangeListener(listener);
 }