Exemple #1
0
  /** Returns the current state of the passed in <code>AbstractButton</code>. */
  private int getComponentState(JComponent c) {
    int state = ENABLED;

    if (!c.isEnabled()) {
      state = DISABLED;
    }
    if (SynthLookAndFeel.getSelectedUI() == this) {
      return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED;
    }
    AbstractButton button = (AbstractButton) c;
    ButtonModel model = button.getModel();

    if (model.isPressed()) {
      if (model.isArmed()) {
        state = PRESSED;
      } else {
        state = MOUSE_OVER;
      }
    }
    if (model.isRollover()) {
      state |= MOUSE_OVER;
    }
    if (model.isSelected()) {
      state |= SELECTED;
    }
    if (c.isFocusOwner() && button.isFocusPainted()) {
      state |= FOCUSED;
    }
    if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
      state |= DEFAULT;
    }
    return state;
  }
Exemple #2
0
  /** Returns the amount to shift the text/icon when painting. */
  private int getTextShiftOffset(SynthContext state) {
    AbstractButton button = (AbstractButton) state.getComponent();
    ButtonModel model = button.getModel();

    if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) {
      return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0);
    }
    return 0;
  }
Exemple #3
0
 public void actionPerformed(ActionEvent e) {
   if (owner != null && SwingUtilities.getRootPane(owner) == root) {
     ButtonModel model = owner.getModel();
     if (press) {
       model.setArmed(true);
       model.setPressed(true);
     } else {
       model.setPressed(false);
     }
   }
 }
Exemple #4
0
  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
    int mnemIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      /** * paint the text disabled ** */
      g.setColor(getDisabledTextColor());
    }
    SwingUtilities2.drawStringUnderlineCharAt(
        c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
  }
Exemple #5
0
 private Icon getSynthDisabledIcon(AbstractButton b, Icon defaultIcon) {
   ButtonModel model = b.getModel();
   Icon icon = null;
   if (model.isSelected()) {
     icon =
         getIcon(
             b,
             b.getDisabledSelectedIcon(),
             null,
             SynthConstants.DISABLED | SynthConstants.SELECTED);
     if (icon == null) {
       icon = getIcon(b, b.getSelectedIcon(), null, SynthConstants.SELECTED);
     }
   }
   if (icon == null) {
     icon = getIcon(b, b.getDisabledIcon(), defaultIcon, SynthConstants.DISABLED);
   }
   return icon;
 }
Exemple #6
0
 private Icon getRolloverIcon(AbstractButton b, Icon defaultIcon) {
   ButtonModel model = b.getModel();
   Icon icon = null;
   if (model.isSelected()) {
     icon =
         getIcon(
             b,
             b.getRolloverSelectedIcon(),
             null,
             SynthConstants.MOUSE_OVER | SynthConstants.SELECTED);
     if (icon == null) {
       icon = getIcon(b, b.getSelectedIcon(), null, SynthConstants.SELECTED);
     }
   }
   if (icon == null) {
     icon = getIcon(b, b.getRolloverIcon(), defaultIcon, SynthConstants.MOUSE_OVER);
   }
   return icon;
 }
Exemple #7
0
 /**
  * If necessary paints the background of the component, then invokes <code>paint</code>.
  *
  * @param g Graphics to paint to
  * @param c JComponent painting on
  * @throws NullPointerException if <code>g</code> or <code>c</code> is null
  * @see javax.swing.plaf.ComponentUI#update
  * @see javax.swing.plaf.ComponentUI#paint
  * @since 1.5
  */
 public void update(Graphics g, JComponent c) {
   AbstractButton button = (AbstractButton) c;
   if ((c.getBackground() instanceof UIResource)
       && button.isContentAreaFilled()
       && c.isEnabled()) {
     ButtonModel model = button.getModel();
     if (!MetalUtils.isToolBarButton(c)) {
       if (!model.isArmed()
           && !model.isPressed()
           && MetalUtils.drawGradient(
               c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
         paint(g, c);
         return;
       }
     } else if (model.isRollover()
         && MetalUtils.drawGradient(
             c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
       paint(g, c);
       return;
     }
   }
   super.update(g, c);
 }
Exemple #8
0
  /**
   * Returns the Icon to use for painting the button. The icon is chosen with respect to the current
   * state of the button.
   *
   * @param b button the icon is associated with
   * @return an icon
   */
  protected Icon getIcon(AbstractButton b) {
    Icon icon = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
      icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
      icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
      icon = getSelectedIcon(b, icon);
    } else {
      icon = getEnabledIcon(b, icon);
    }
    if (icon == null) {
      return getDefaultIcon(b);
    }
    return icon;
  }