示例#1
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;
 }
示例#2
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);
 }
示例#3
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);
 }
示例#4
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;
 }
示例#5
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();
  }