/**
   * Paint the component, which is an {@link AbstractButton}, according to its current state.
   *
   * @param g The graphics context to paint with
   * @param c The component to paint the state of
   */
  public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;

    Rectangle tr = new Rectangle();
    Rectangle ir = new Rectangle();
    Rectangle vr = new Rectangle();

    Font f = c.getFont();

    g.setFont(f);

    if (b.isBorderPainted()) SwingUtilities.calculateInnerArea(b, vr);
    else vr = SwingUtilities.getLocalBounds(b);
    String text =
        SwingUtilities.layoutCompoundLabel(
            c,
            g.getFontMetrics(f),
            b.getText(),
            currentIcon(b),
            b.getVerticalAlignment(),
            b.getHorizontalAlignment(),
            b.getVerticalTextPosition(),
            b.getHorizontalTextPosition(),
            vr,
            ir,
            tr,
            b.getIconTextGap() + defaultTextShiftOffset);

    if ((b.getModel().isArmed() && b.getModel().isPressed()) || b.isSelected())
      paintButtonPressed(g, b);

    paintIcon(g, b, ir);
    if (text != null) paintText(g, b, tr, text);
    if (b.isFocusOwner() && b.isFocusPainted()) paintFocus(g, b, vr, tr, ir);
  }
Esempio n. 2
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      Graphics2D g2D = (Graphics2D) g;
      Color frameColor = AbstractLookAndFeel.getTheme().getFrameColor();
      if (!JTattooUtilities.isFrameActive(button)) {
        frameColor = ColorHelper.brighter(frameColor, 40);
      }

      if (AbstractLookAndFeel.getTheme().doDrawSquareButtons()) {
        g2D.setColor(Color.white);
        g2D.drawRect(x, y, w - 1, h - 1);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())
            && !button.hasFocus()) {
          g2D.setColor(ColorHelper.darker(frameColor, 20));
          g2D.drawRect(x, y, w - 1, h - 2);
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRect(x + 1, y + 1, w - 3, h - 4);
            g2D.setColor(defaultColorLo);
            g2D.drawRect(x + 2, y + 2, w - 5, h - 6);
          }
        } else {
          g2D.setColor(frameColor);
          g2D.drawRect(x, y, w - 2, h - 2);
        }
      } else {
        Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if (button.getRootPane() != null
            && button.equals(button.getRootPane().getDefaultButton())) {
          if (!button.getModel().isRollover()) {
            g2D.setColor(defaultColorHi);
            g2D.drawRoundRect(x + 1, y + 1, w - 4, h - 2, 6, 6);
            g2D.setColor(defaultColorLo);
            g2D.drawRoundRect(x + 2, y + 2, w - 6, h - 6, 6, 6);
          }
        }

        g2D.setColor(Color.white);
        g2D.drawRoundRect(x, y, w - 1, h - 1, 6, 6);

        g2D.setColor(frameColor);
        g2D.drawRoundRect(x, y, w - 2, h - 2, 6, 6);

        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
      }
    }
Esempio n. 3
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      if (MetalLookAndFeel.usingOcean()) {
        paintOceanBorder(c, g, x, y, w, h);
        return;
      }
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();

      if (model.isEnabled()) {
        boolean isPressed = model.isPressed() && model.isArmed();
        boolean isDefault = (button instanceof JButton && ((JButton) button).isDefaultButton());

        if (isPressed && isDefault) {
          MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
        } else if (isPressed) {
          MetalUtils.drawPressed3DBorder(g, x, y, w, h);
        } else if (isDefault) {
          MetalUtils.drawDefaultButtonBorder(g, x, y, w, h, false);
        } else {
          MetalUtils.drawButtonBorder(g, x, y, w, h, false);
        }
      } else { // disabled state
        MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
      }
    }
Esempio n. 4
0
  @Override
  protected void paintText(
      final Graphics g, final JComponent c, final Rectangle textRect, final String text) {
    final AbstractButton b = (AbstractButton) c;
    final ButtonModel model = b.getModel();
    final FontMetrics fm = SwingUtils.getFontMetrics(c, g);
    final int mnemonicIndex = b.getDisplayedMnemonicIndex();

    // Drawing text
    if (model.isEnabled()) {
      // Normal text
      g.setColor(b.getForeground());
      SwingUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
      // Disabled text
      g.setColor(b.getBackground().brighter());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
      g.setColor(b.getBackground().darker());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
Esempio n. 5
0
  public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());

    clearTextShiftOffset();

    // perform UI specific press action, e.g. Windows L&F shifts text
    if (model.isArmed() && model.isPressed()) {
      paintButtonPressed(g, b);
    }

    // Paint the Icon
    if (b.getIcon() != null) {
      paintIcon(g, c, iconRect);
    }

    if (text != null && !text.equals("")) {
      View v = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        v.paint(g, textRect);
      } else {
        paintText(g, b, textRect, text);
      }
    }

    if (b.isFocusPainted() && b.hasFocus()) {
      // paint UI specific focus
      paintFocus(g, b, viewRect, textRect, iconRect);
    }
  }
Esempio n. 6
0
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;

    if (icon == null) {
      return;
    }

    Icon selectedIcon = null;

    /* the fallback icon should be based on the selected state */
    if (model.isSelected()) {
      selectedIcon = (Icon) b.getSelectedIcon();
      if (selectedIcon != null) {
        icon = selectedIcon;
      }
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
Esempio n. 7
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   AbstractButton abstractButton = (AbstractButton) c;
   ButtonModel buttonModel = abstractButton.getModel();
   int w = getIconWidth();
   int h = getIconHeight();
   if (g instanceof Graphics2D) {
     Graphics2D g2 = (Graphics2D) g;
     RenderingHints rh =
         new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g2.setRenderingHints(rh);
     float s = SizeHelper.getMinimalStrockWidth();
     g2.setStroke(new BasicStroke(s));
   }
   g.setColor(Color.WHITE);
   g.fillOval(x, y, w - 1, h - 1);
   if (buttonModel.isEnabled()) {
     g.setColor(Color.BLACK);
   } else {
     g.setColor(Color.GRAY);
   }
   g.drawOval(x, y, w - 1, h - 1);
   if (buttonModel.isSelected()) {
     int dx = (int) Math.round(0.25 * w);
     int dy = (int) Math.round(0.25 * h);
     g.fillOval(x + dx, y + dy, w - 2 * dx, h - 2 * dy);
   }
 }
Esempio n. 8
0
  /**
   * As of Java 2 platform v 1.4 this method should not be used or overriden. Use the paintText
   * method which takes the AbstractButton argument.
   */
  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 mnemonicIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
      /** * paint the text disabled ** */
      g.setColor(b.getBackground().brighter());
      SwingUtilities2.drawStringUnderlineCharAt(
          c, g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
      g.setColor(b.getBackground().darker());
      SwingUtilities2.drawStringUnderlineCharAt(
          c, g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
 @Override
 public void focusLost(FocusEvent e) {
   super.focusLost(e);
   AbstractButton b = (AbstractButton) e.getSource();
   b.getModel().setArmed(false);
   b.repaint();
 }
  @Override
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;
    Icon shadowIcon = null;
    boolean borderHasPressedCue = borderHasPressedCue(b);

    if (icon == null) {
      return;
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
      } else {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) {
        // Create an icon on the fly.
        // Note: This is only needed for borderless buttons, which
        //       have no other way to provide feedback about the pressed
        //       state.
        tmpIcon =
            new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage()));
        shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage()));
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = b.getSelectedIcon();
        }
      } else {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    } else if (model.isSelected()) {
      tmpIcon = b.getSelectedIcon();
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      if (shadowIcon != null) {
        shadowIcon.paintIcon(
            c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1);
      }
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
  /**
   * Method which renders the text of the current button.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   * @since 1.4
   */
  @Override
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1);
    boolean borderHasPressedCue = borderHasPressedCue(b);

    /* Draw the Text */
    if (model.isPressed() && model.isArmed() && !borderHasPressedCue) {
      g.setColor(new Color(0xa0000000, true));
      QuaquaUtilities.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset() + 1);
    }

    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground");
      g.setColor((c != null) ? c : b.getForeground());
    }
    QuaquaUtilities.drawStringUnderlineCharAt(
        g,
        text,
        mnemonicIndex,
        textRect.x + getTextShiftOffset(),
        textRect.y + fm.getAscent() + getTextShiftOffset());
  }
  @Override
  public void paint(Graphics g, JComponent c) {
    Graphics2D g2 = (Graphics2D) g;
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    initShape(b);
    // ContentArea
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (model.isArmed()) {
      g2.setColor(ac);
      g2.fill(shape);
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      paintFocusAndRollover(g2, c, rc);
    } else if (b.hasFocus()) {
      paintFocusAndRollover(g2, c, fc);
    } else {
      g2.setColor(c.getBackground());
      g2.fill(shape);
    }
    // Border
    g2.setPaint(c.getForeground());
    g2.draw(shape);

    g2.setColor(c.getBackground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    super.paint(g2, c);
  }
Esempio n. 13
0
    protected void refreshTransformers() {
      if (model != null) {
        // Select the right transformer
        int index = 0;
        for (String elmtType : AppearanceUIController.ELEMENT_CLASSES) {
          for (TransformerCategory c : controller.getCategories(elmtType)) {
            ButtonGroup g = buttonGroups.get(index);

            boolean active =
                model.getSelectedElementClass().equals(elmtType)
                    && model.getSelectedCategory().equals(c);
            g.clearSelection();
            TransformerUI t = model.getSelectedTransformerUI();

            for (Enumeration<AbstractButton> btns = g.getElements(); btns.hasMoreElements(); ) {
              AbstractButton btn = btns.nextElement();
              btn.setVisible(active);
              if (t != null && btn.getName().equals(t.getDisplayName())) {
                g.setSelected(btn.getModel(), true);
              }
            }
            index++;
          }
        }
      }
    }
Esempio n. 14
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;
    }

    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;
  }
Esempio n. 15
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton b = (AbstractButton) c;
      ButtonModel model = b.getModel();

      if (model.isRollover() && !(model.isPressed() && !model.isArmed())) {
        super.paintBorder(c, g, x, y, w, h);
      }
    }
Esempio n. 16
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;
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent
  * )
  */
 @Override
 public void actionPerformed(ActionEvent e) {
   AbstractButton src = (AbstractButton) e.getSource();
   ButtonModel model = src.getModel();
   model.setArmed(false);
   model.setPressed(false);
   model.setRollover(false);
   model.setSelected(false);
 }
Esempio n. 18
0
 @Override
 public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y) {
   if (c instanceof javax.swing.AbstractButton) {
     javax.swing.AbstractButton button = (javax.swing.AbstractButton) c;
     javax.swing.ButtonModel buttonModel = button.getModel();
     javax.swing.Icon icon = buttonModel.isSelected() ? this.selectedIcon : this.unselectedIcon;
     icon.paintIcon(c, g, x, y);
   } else {
     g.setColor(java.awt.Color.RED);
     g.fillRect(x, y, c.getWidth(), c.getHeight());
   }
 }
Esempio n. 19
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   AbstractButton button = (AbstractButton) c;
   ButtonModel model = button.getModel();
   Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
   Color frameHiColor = ColorHelper.brighter(frameColor, 10);
   Color frameLoColor = ColorHelper.darker(frameColor, 30);
   JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h);
   if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
     JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
   } else {
     JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
     JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2);
   }
 }
  /**
   * Renders a text String in Windows without the mnemonic. This is here because the WindowsUI
   * hiearchy doesn't match the Component heirarchy. All the overriden paintText methods of the
   * ButtonUI delegates will call this static method.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   */
  public static void paintText(
      Graphics g, AbstractButton b, Rectangle textRect, String text, int textShiftOffset) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();

    int mnemIndex = b.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
      mnemIndex = -1;
    }

    /* Draw the Text */
    Color color = b.getForeground();
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemIndex,
          textRect.x + textShiftOffset,
          textRect.y + fm.getAscent() + textShiftOffset);
    } else {
        /** * paint the text disabled ** */
      color = UIManager.getColor("Button.disabledForeground");
      Color shadow = UIManager.getColor("Button.disabledShadow");

      XPStyle xp = XPStyle.getXP();
      if (xp != null) {
        color = xp.getColor("button.pushbutton(disabled).textcolor", color);
      } else {
        // Paint shadow only if not XP
        if (shadow == null) {
          shadow = b.getBackground().darker();
        }
        g.setColor(shadow);
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
      }
      if (color == null) {
        color = b.getBackground().brighter();
      }
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
Esempio n. 21
0
  public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
      if (!isDisabled) {
        changeToDisabledColors(c);
      }
    } else if (model.isRollover() || isMouseOver(b)) {
      if (!isRollover) {
        changeToRolloverColors(c);
      }
    } else if (isDisabled || isRollover) {
      changeToOriginalColors(c);
    }
    super.paint(g, c);
  }
Esempio n. 22
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      if (model.isEnabled()) {
        if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
          Color frameColor =
              ColorHelper.darker(AbstractLookAndFeel.getToolbarBackgroundColor(), 30);
          g.setColor(frameColor);
          g.drawRect(x, y, w - 1, h - 1);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
          g2D.setComposite(alpha);
          g.setColor(Color.black);
          g.fillRect(x + 1, y + 1, w - 2, h - 2);
          g2D.setComposite(composite);
        } else if (model.isRollover()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = ColorHelper.darker(frameColor, 5);
          Color frameLoColor = ColorHelper.darker(frameColor, 20);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h);
          frameHiColor = Color.white;
          frameLoColor = ColorHelper.brighter(frameLoColor, 60);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
          g2D.setComposite(alpha);
          g.setColor(Color.white);
          g.fillRect(x + 2, y + 2, w - 4, h - 4);
          g2D.setComposite(composite);

          g.setColor(AbstractLookAndFeel.getFocusColor());
          g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
          g.drawLine(x + 1, y + 2, x + w - 2, y + 2);
        } else if (model.isSelected()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = Color.white;
          Color frameLoColor = ColorHelper.darker(frameColor, 30);
          JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
        }
      }
    }
Esempio n. 23
0
  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton button = (AbstractButton) c;
    ButtonModel model = button.getModel();
    Color fg = button.getForeground();
    if (fg instanceof UIResource
        && button instanceof JButton
        && ((JButton) button).isDefaultButton()) {
      final Color selectedFg = UIManager.getColor("Button.darcula.selectedButtonForeground");
      if (selectedFg != null) {
        fg = selectedFg;
      }
    }
    g.setColor(fg);

    FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g);
    int mnemonicIndex = button.getDisplayedMnemonicIndex();
    if (model.isEnabled()) {

      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + metrics.getAscent() + getTextShiftOffset());
    } else {
      g.setColor(UIManager.getColor("Button.darcula.disabledText.shadow"));
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          -1,
          textRect.x + getTextShiftOffset() + 1,
          textRect.y + metrics.getAscent() + getTextShiftOffset() + 1);
      g.setColor(UIManager.getColor("Button.disabledText"));
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          -1,
          textRect.x + getTextShiftOffset(),
          textRect.y + metrics.getAscent() + getTextShiftOffset());
    }
  }
Esempio n. 24
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;
 }
Esempio n. 25
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;
 }
Esempio n. 26
0
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
    int mnemIndex;
    if (JTattooUtilities.getJavaVersion() >= 1.4) {
      mnemIndex = b.getDisplayedMnemonicIndex();
    } else {
      mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
    }
    int offs = 0;
    if (model.isArmed() && model.isPressed()) {
      offs = 1;
    }

    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
    g2D.setComposite(alpha);
    Color foreground = b.getForeground();
    Color background = b.getBackground();
    if (background instanceof ColorUIResource) {
      if (model.isPressed() && model.isArmed()) {
        foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor();
      } else if (model.isRollover()) {
        foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor();
      }
    }
    if (!model.isEnabled()) {
      foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
    }
    if (ColorHelper.getGrayValue(foreground) > 64) {
      g2D.setColor(Color.black);
    } else {
      g2D.setColor(Color.white);
    }
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1);
    g2D.setComposite(composite);
    g2D.setColor(foreground);
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent());
  }
Esempio n. 27
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;
  }
Esempio n. 28
0
  public void paintIcon(Graphics2D g, ButtonInfo info) {
    AbstractButton button = info.button;
    Icon icon = button.getIcon();
    ButtonModel model = button.getModel();

    if (model.isRollover() && button.getRolloverIcon() != null) icon = button.getRolloverIcon();
    if (model.isPressed() && button.getPressedIcon() != null) icon = button.getPressedIcon();
    if (model.isSelected() && button.getSelectedIcon() != null) icon = button.getSelectedIcon();
    if (model.isRollover() && model.isSelected() && button.getRolloverSelectedIcon() != null)
      icon = button.getRolloverSelectedIcon();
    if (isEnabled(button) == false && button.getDisabledIcon() != null)
      icon = button.getDisabledIcon();
    if (isEnabled(button) == false && model.isSelected() && button.getDisabledIcon() != null)
      icon = button.getDisabledSelectedIcon();

    if (icon != null) {
      g.setComposite(isEnabled(button) ? AlphaComposite.SrcOver : SRC_OVER_TRANSLUCENT);
      icon.paintIcon(button, g, info.iconRect.x, info.iconRect.y);
    }
  }
Esempio n. 29
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);
 }
 protected void paintText(Graphics g, JComponent c, String text, Rectangle textRect) {
   View v = (View) c.getClientProperty(BasicHTML.propertyKey);
   if (v != null) {
     v.paint(g, textRect);
   } else {
     AbstractButton b = (AbstractButton) c;
     ButtonModel model = b.getModel();
     int mnemIndex = -1;
     if (JTattooUtilities.getJavaVersion() >= 1.4) {
       mnemIndex = b.getDisplayedMnemonicIndex();
     } else {
       mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
     }
     Font f = c.getFont();
     g.setFont(f);
     FontMetrics fm = g.getFontMetrics();
     if (model.isEnabled()) {
       Color fc = b.getForeground();
       if (AbstractLookAndFeel.getTheme().isTextShadowOn() && ColorHelper.getGrayValue(fc) > 128) {
         g.setColor(Color.black);
         JTattooUtilities.drawStringUnderlineCharAt(
             c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent());
       }
       g.setColor(fc);
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
     } else {
       g.setColor(Color.black);
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent());
       g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
     }
   }
 }