示例#1
0
  void updateStyle(AbstractButton b) {
    SynthContext context = getContext(b, SynthConstants.ENABLED);
    SynthStyle oldStyle = style;
    style = SynthLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
      if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
        Insets margin = (Insets) style.get(context, getPropertyPrefix() + "margin");

        if (margin == null) {
          // Some places assume margins are non-null.
          margin = SynthLookAndFeel.EMPTY_UIRESOURCE_INSETS;
        }
        b.setMargin(margin);
      }

      Object value = style.get(context, getPropertyPrefix() + "iconTextGap");
      if (value != null) {
        LookAndFeel.installProperty(b, "iconTextGap", value);
      }

      value = style.get(context, getPropertyPrefix() + "contentAreaFilled");
      LookAndFeel.installProperty(b, "contentAreaFilled", value != null ? value : Boolean.TRUE);

      if (oldStyle != null) {
        uninstallKeyboardActions(b);
        installKeyboardActions(b);
      }
    }
  }
示例#2
0
  protected void installDefaults(AbstractButton b) {
    // load shared instance defaults
    String pp = getPropertyPrefix();

    defaultTextShiftOffset = UIManager.getInt(pp + "textShiftOffset");

    // set the following defaults on the button
    if (b.isContentAreaFilled()) {
      LookAndFeel.installProperty(b, "opaque", Boolean.TRUE);
    } else {
      LookAndFeel.installProperty(b, "opaque", Boolean.FALSE);
    }

    if (b.getMargin() == null || (b.getMargin() instanceof UIResource)) {
      b.setMargin(UIManager.getInsets(pp + "margin"));
    }

    LookAndFeel.installColorsAndFont(b, pp + "background", pp + "foreground", pp + "font");
    LookAndFeel.installBorder(b, pp + "border");

    Object rollover = UIManager.get(pp + "rollover");
    if (rollover != null) {
      LookAndFeel.installProperty(b, "rolloverEnabled", rollover);
    }

    LookAndFeel.installProperty(b, "iconTextGap", new Integer(4));
  }
示例#3
0
  private AbstractButton createButton() {
    final String action = getAction();

    final AbstractButton button;
    if (toggleButton) {
      button = new CToggleButton(this);
      button.setSelectedIcon(iconPressed);
    } else {
      final CButton cbutton = new CButton(this);
      if (buttonDefaultCapable != null) {
        cbutton.setDefaultCapable(buttonDefaultCapable);
      }
      button = cbutton;
    }

    button.setName(action);
    button.setIcon(icon);
    button.setText(buttonText);

    button.setActionCommand(action);
    button.setMargin(buttonInsets);
    button.setSize(BUTTON_SIZE);

    //
    // Action
    button.getActionMap().put(action, this);

    //
    // Update button state from this action
    updateButtonPressedState(button);
    replaceAcceleratorKey(button, getAccelerator(), null);

    return button;
  }
 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);
 }
示例#5
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;
  }
  /**
   * GUI setup method can be quite lengthy and repetitive so it helps to create helper methods that
   * can do a bunch of things at once. This method creates a button with a bunch of premade values.
   * Note that we are using Java reflection here, to make an object based on what class type it has.
   *
   * @param imageFile The image to use for the button.
   * @param parent The container inside which to put the button.
   * @param tracker This makes sure our button fully loads.
   * @param id A unique id for the button so the tracker knows it's there.
   * @param buttonType The type of button, we'll use reflection for making it.
   * @param bg Some buttons will go into groups where only one may be selected at a time.
   * @param tooltip The mouse-over text for the button.
   * @return A fully constructed and initialized button with all the data provided to it as
   *     arguments.
   */
  private AbstractButton initButton(
      String imageFile,
      Container parent,
      MediaTracker tracker,
      int id,
      Class buttonType,
      ButtonGroup bg,
      String tooltip) {

    try {
      // LOAD THE IMAGE AND MAKE AN ICON
      Image img = batchLoadImage(imageFile, tracker, id);
      ImageIcon ii = new ImageIcon(img);

      // HERE'S REFLECTION MAKING OUR OBJECT USING IT'S CLASS
      // NOTE THAT DOING IT LIKE THIS CALLS THE buttonType
      // CLASS' DEFAULT CONSTRUCTOR, SO WE MUST MAKE SURE IT HAS ONE
      AbstractButton createdButton;
      createdButton = (AbstractButton) buttonType.newInstance();

      // NOW SETUP OUR BUTTON FOR USE
      createdButton.setIcon(ii);
      createdButton.setToolTipText(tooltip);
      parent.add(createdButton);

      // INSETS ARE SPACING INSIDE THE BUTTON,
      // TOP LEFT RIGHT BOTTOM
      Insets buttonMargin = new Insets(2, 2, 2, 2);
      createdButton.setMargin(buttonMargin);

      // ADD IT TO ITS BUTTON GROUP IF IT'S IN ONE
      if (bg != null) {
        bg.add(createdButton);
      }

      // AND RETURN THE SETUP BUTTON
      return createdButton;
    } catch (InstantiationException | IllegalAccessException ex) {
      // WE SHOULD NEVER GET THIS ERROR, BUT WE HAVE TO PUT
      // A TRY CATCH BECAUSE WE'RE USING REFLECTION TO DYNAMICALLY
      // CONSTRUCT OUR BUTTONS BY CLASS NAME
      Logger.getLogger(PoseurGUI.class.getName()).log(Level.SEVERE, null, ex);
    }
    // THIS WOULD MEAN A FAILURE OF SOME SORT OCCURED
    return null;
  }
示例#7
0
  /**
   * Descripción de Método
   *
   * @param button
   * @param cmd
   * @param file
   */
  private void setButton(AbstractButton button, String cmd, String file) {
    String text = Msg.getMsg(m_ctx, cmd);

    button.setToolTipText(text);
    button.setActionCommand(cmd);

    //

    ImageIcon ii24 = Env.getImageIcon(file + "24.gif");

    if (ii24 != null) {
      button.setIcon(ii24);
    }

    button.setMargin(AppsAction.BUTTON_INSETS);
    button.setPreferredSize(AppsAction.BUTTON_SIZE);
    button.addActionListener(this);
  } // setButton
  public void setUseFlatUI(boolean b) {
    main.setContentAreaFilled(!b);
    main.setFocusPainted(!b);
    main.setBorderPainted(!b);
    main.setMargin(new Insets(1, 1, 1, 1));

    popper.setContentAreaFilled(!b);
    popper.setFocusPainted(!b);
    popper.setBorderPainted(!b);
    popper.setMargin(new Insets(1, 1, 1, 1));

    setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    setOpaque(false);

    MouseAdapter ma =
        new MouseAdapter() {
          public void mouseEntered(MouseEvent e) {
            main.setContentAreaFilled(true);
            main.setBackground(new Color(216, 240, 254));
            // m.getMainButton().setForeground( Color.black );
            setBorder(new LineBorder(new Color(200, 200, 200), 1));
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

            popper.setBackground(new Color(242, 242, 242));
            popper.setContentAreaFilled(true);
            popper.setBorder(menu.getBorder());
          }

          public void mouseExited(MouseEvent e) {
            main.setContentAreaFilled(false);
            //	c.setForeground( Color.black );
            setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
            setCursor(Cursor.getDefaultCursor());

            popper.setContentAreaFilled(false);
            popper.setBorder(null);
          }
        };

    main.addMouseListener(ma);
    popper.addMouseListener(ma);
  }
  public void createButtons(String text, Icon icon) {
    if (main == null) {
      main = new JButton(text, icon);

      if (text == null) {
        main.setMargin(new Insets(0, 0, 0, 0));
      }
    }

    // main.setFont( new Font("Verdana", Font.PLAIN, 11) );
    ImageIcon img = new ImageIcon("resources/images/popicon.gif");
    popper =
        new JButton(/*img*/ ) {

          public void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2 = (Graphics2D) g;
            int width = getWidth(), height = getHeight();
            int midWidth = width / 2, midHeight = height / 2;

            int[] xpoints = {midWidth - 4, midWidth, midWidth + 4};
            int[] ypoints = {midHeight - 1, midHeight + 3, midHeight - 1};

            if (ARROW_DIRECTION == FORWARD) {
              xpoints = new int[] {midWidth - 3, midWidth - 3, midWidth + 2};
              ypoints = new int[] {midHeight - 4, midHeight + 4, midHeight};
            }

            g2.setColor(getPopperArrowColor());
            g2.fill(new Polygon(xpoints, ypoints, 3));
          }
        };

    // popper.setPreferredSize( new Dimension(img.getImage().getWidth(this) + 10,

    popper.addActionListener(this);

    setBorder(null);
    // setLayout( new BoxLayout(this, BoxLayout.X_AXIS) );
    layoutComponents();
  }
示例#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;
 }
示例#11
0
  /**
   * Adds the given NamedMediaType.
   *
   * <p>Marks the 'Any Type' as selected.
   */
  private void addMediaType(NamedMediaType type, String toolTip) {
    Icon icon = type.getIcon();
    Icon disabledIcon = null;
    Icon rolloverIcon = null;
    AbstractButton button = new JRadioButton(type.getName());
    button.putClientProperty(MEDIA, type);
    button.putClientProperty(SELECTED, icon);
    if (icon != null) {
      disabledIcon = ImageManipulator.darken(icon);
      rolloverIcon = ImageManipulator.brighten(icon);
    }
    button.putClientProperty(DESELECTED, disabledIcon);
    button.setIcon(disabledIcon);
    button.setRolloverIcon(rolloverIcon);
    button.addItemListener(HIGHLIGHTER);
    button.setBorderPainted(false);
    button.setFocusPainted(false);
    button.setContentAreaFilled(false);
    button.setMargin(new Insets(0, 0, 0, 0));
    button.setOpaque(false);
    button.addMouseListener(CLICK_FORWARDER);
    button.setPreferredSize(new Dimension(100, 22));
    if (toolTip != null) {
      button.setToolTipText(toolTip);
    }
    GROUP.add(button);

    DitherPanel panel = new DitherPanel(DITHERER);
    panel.setDithering(false);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT, 7, 1));
    panel.add(button);
    panel.addMouseListener(CLICK_FORWARDER);
    panel.setBackground(UIManager.getColor("TabbedPane.background"));
    SCHEMAS.add(panel);

    if (type.getMediaType() == MediaType.getAnyTypeMediaType()) button.setSelected(true);
    else button.setSelected(false);
  }
示例#12
0
文件: WtoolBar.java 项目: av4n/Weasis
 /**
  * Install custom UI for this button : a light rollover effet and a custom rounded/shaded border.
  *
  * <p>This method can be overriden to replace the provided "look and feel" which uses the follwing
  * configuration :
  *
  * <ul>
  *   <li>install a VLButtonUI
  *   <li>set 2 pixels margins
  *   <li>set a ToolBarButtonBorder.
  * </ul>
  */
 public static void installButtonUI(AbstractButton button) {
   button.setMargin(new Insets(2, 2, 2, 2));
   button.setUI(new VLButtonUI());
   button.setBorder(new ToolBarButtonBorder());
 }