public void addAction(JXFrame frame, Action action) {
   JToolBar toolbar = frame.getRootPaneExt().getToolBar();
   if (toolbar != null) {
     AbstractButton button = toolbar.add(action);
     button.setFocusable(false);
   }
 }
 private void processButton(AbstractButton button) {
   removeButtonContentAreaAndBorder(button);
   button.setMargin(BUTTON_INSETS);
   if (button instanceof AbstractButton) {
     button.addMouseListener(sharedMouseListener);
   }
   // fix of issue #69642. Focus shouldn't stay in toolbar
   button.setFocusable(false);
 }
  @Override
  protected void installDefaults(AbstractButton b) {
    super.installDefaults(b);

    String pp = getPropertyPrefix();
    // b.setOpaque(QuaquaManager.getBoolean(pp+"opaque"));
    QuaquaUtilities.installProperty(b, "opaque", UIManager.get(pp + "opaque"));
    b.setRequestFocusEnabled(UIManager.getBoolean(pp + "requestFocusEnabled"));
    b.setFocusable(UIManager.getBoolean(pp + "focusable"));
  }
示例#4
0
文件: KToolbar.java 项目: kikonen/KUI
  private JComponent addItem(
      final Component pComponent, final KToolbarImpl pToolbar, final Action pAction) {
    JComponent item = null;
    final String key = (String) pAction.getValue(Action.NAME);

    if (pAction instanceof KMenu) {
      final KMenu actionMenu = (KMenu) pAction;
      item = actionMenu.create(pComponent);
      pToolbar.add(item);
    } else if (pAction == KAction.SEPARATOR) {
      pToolbar.addSeparator();
    } else if (pAction instanceof KComponentAction) {
      item = ((KComponentAction) pAction).getComponent();
      pToolbar.add(item);
    } else {
      AbstractButton button;
      ActionGroup group = (ActionGroup) pAction.getValue(KAction.KEY_GROUP);
      if (group != null) {
        button = new JToggleButton(pAction);
        ((JToggleButton) button).setSelected(group.getSelected() == pAction);
        ButtonGroup bg = group.getButtonGroup(ResKey.TOOLBAR);
        bg.add(button);
      } else {
        button = new JButton(pAction);
      }
      item = button;

      final WidgetResources wr = ResourceAdapter.getInstance().getWidget(key, ResKey.TOOLBAR);
      Icon icon = wr.getIcon();
      if (icon == null) {
        icon = DEF_ICON;
      }
      button.setIcon(icon);
      button.setToolTipText(wr.getToolTip());
      button.setMargin(ZERO_INSETS);
      button.setRequestFocusEnabled(false);
      button.setFocusable(false);

      if (false) {
        button.setText(wr.getText());
        button.setMnemonic(wr.getMnenomnic());
        button.setDisplayedMnemonicIndex(wr.getMnenomnicIndex());
      } else {
        button.setText(null);
      }
    }

    if (item != null) {
      pToolbar.add(item);
    }
    return item;
  }
示例#5
0
 public static AbstractButton makeToolBarButton(Command cmd) {
   AbstractButton b;
   if (cmd instanceof ToggleCommand) {
     b = new JToggleButton(cmd);
     b.setSelected(((ToggleCommand) cmd).isSelected());
   } else {
     b = new JButton(cmd);
   }
   b.setFocusable(false);
   b.setText(null);
   // b.setMargin(new Insets(2, 2, 2, 2));
   b.setBorderPainted(false);
   cmd.bind(b);
   return b;
 }
示例#6
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;
  }
示例#7
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;
 }
示例#8
0
  @Override
  public void installUI(JComponent c) {
    AbstractButton button = (AbstractButton) c;

    ButtonInfo info = new ButtonInfo(button, this);
    button.putClientProperty(BUTTON_INFO_KEY, info);

    button.addMouseListener(info.basicListener);
    button.addMouseMotionListener(info.basicListener);
    button.addFocusListener(info.basicListener);
    button.addPropertyChangeListener(info.basicListener);
    button.addChangeListener(info.basicListener);
    button.addKeyListener(focusArrowListener);
    button.addComponentListener(componentListener);
    button.addKeyListener(keyArmingListener);
    button.setRequestFocusEnabled(false);
    button.setFocusable(true);
    button.addPropertyChangeListener(positionAndShapeListener);
    button.setOpaque(false);
    button.setRolloverEnabled(true);

    if (button.getIcon() != null) {
      Font font = UIManager.getFont("IconButton.font");
      if (font != null) button.setFont(font); // miniature-ish
    }

    super.installUI(c);

    updateLayout(button, info);

    if (button.getFont() == null) {
      Font font = UIManager.getFont("Button.font");
      if (font == null) {
        font = new Font("Default", 0, 13);
      }
      button.setFont(font);
    }
  }