Example #1
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);
      }
    }
  /** 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;
  }
Example #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);
      }
    }
Example #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);
    }
  }
Example #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);
    }
  }
  @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());
  }
Example #8
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);
    }
  }
Example #9
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);
    }
  }
Example #10
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   AbstractButton b = (AbstractButton) c;
   ButtonModel model = b.getModel();
   if (b.isSelected() == true) {
     g.fillRoundRect(x + 3, y + 3, getIconWidth() - 6, getIconHeight() - 6, 4, 4);
   }
 }
Example #11
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);
      }
    }
Example #12
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);
 }
Example #14
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      boolean isPressed = false;
      boolean hasFocus = false;
      boolean canBeDefault = false;
      boolean isDefault = false;

      if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) || (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
          canBeDefault = ((JButton) b).isDefaultCapable();
          isDefault = ((JButton) b).isDefaultButton();
        }
      }
      int bx1 = x + 1;
      int by1 = y + 1;
      int bx2 = x + w - 2;
      int by2 = y + h - 2;

      if (canBeDefault) {
        if (isDefault) {
          g.setColor(shadow);
          g.drawLine(x + 3, y + 3, x + 3, y + h - 4);
          g.drawLine(x + 3, y + 3, x + w - 4, y + 3);

          g.setColor(highlight);
          g.drawLine(x + 4, y + h - 4, x + w - 4, y + h - 4);
          g.drawLine(x + w - 4, y + 3, x + w - 4, y + h - 4);
        }
        bx1 += 6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
      }

      if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
          g.drawRect(x, y, w - 1, h - 1);
        } else {
          g.drawRect(bx1 - 1, by1 - 1, bx2 - bx1 + 2, by2 - by1 + 2);
        }
      }

      g.setColor(isPressed ? shadow : highlight);
      g.drawLine(bx1, by1, bx2, by1);
      g.drawLine(bx1, by1, bx1, by2);

      g.setColor(isPressed ? highlight : shadow);
      g.drawLine(bx2, by1 + 1, bx2, by2);
      g.drawLine(bx1 + 1, by2, bx2, by2);
    }
Example #15
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);
    }
  }
Example #17
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   AbstractButton b = (AbstractButton) c;
   ButtonModel model = b.getModel();
   boolean isSelected = model.isSelected();
   if (isSelected) {
     y = y - getIconHeight() / 2;
     g.drawLine(x + 9, y + 3, x + 9, y + 3);
     g.drawLine(x + 8, y + 4, x + 9, y + 4);
     g.drawLine(x + 7, y + 5, x + 9, y + 5);
     g.drawLine(x + 6, y + 6, x + 8, y + 6);
     g.drawLine(x + 3, y + 7, x + 7, y + 7);
     g.drawLine(x + 4, y + 8, x + 6, y + 8);
     g.drawLine(x + 5, y + 9, x + 5, y + 9);
     g.drawLine(x + 3, y + 5, x + 3, y + 5);
     g.drawLine(x + 3, y + 6, x + 4, y + 6);
   }
 }
Example #18
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);
        }
      }
    }
Example #19
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());
    }
  }
Example #20
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;
 }
Example #21
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;
 }
  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());
  }
Example #23
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);
    }
  }
Example #24
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;
  }
Example #25
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);
 }
Example #26
0
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          drawBezel(
              g,
              x,
              y,
              width,
              height,
              (model.isPressed() || model.isSelected()),
              b.isFocusPainted() && b.hasFocus(),
              shadow,
              highlight,
              darkShadow,
              focus);
        } else {
          drawBezel(
              g,
              x,
              y,
              width,
              height,
              false,
              b.isFocusPainted() && b.hasFocus(),
              shadow,
              highlight,
              darkShadow,
              focus);
        }
      } else {
        drawBezel(g, x, y, width, height, false, false, shadow, highlight, darkShadow, focus);
      }
    }
Example #27
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 (MetalLookAndFeel.usingOcean()) {
     if (model.isArmed() || !button.isEnabled()) {
       super.paintBorder(c, g, x, y, w, h);
     } else {
       g.setColor(MetalLookAndFeel.getControlDarkShadow());
       g.drawRect(0, 0, w - 1, h - 1);
     }
     return;
   }
   if (!c.isEnabled()) {
     MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
   } else {
     if (model.isPressed() && model.isArmed()) {
       MetalUtils.drawPressed3DBorder(g, x, y, w, h);
     } else if (model.isSelected()) {
       MetalUtils.drawDark3DBorder(g, x, y, w, h);
     } else {
       MetalUtils.drawFlush3DBorder(g, x, y, w, h);
     }
   }
 }
 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());
     }
   }
 }
Example #29
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      AbstractButton b = (AbstractButton) c;
      ButtonModel model = b.getModel();
      XPStyle xp = XPStyle.getXP();

      if (xp != null) {
        Part part = Part.BP_RADIOBUTTON;
        Skin skin = xp.getSkin(b, part);
        State state;
        int index = 0;
        if (model.isSelected()) {
          state = State.CHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.CHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.CHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.CHECKEDHOT;
          }
        } else {
          state = State.UNCHECKEDNORMAL;
          if (!model.isEnabled()) {
            state = State.UNCHECKEDDISABLED;
          } else if (model.isPressed() && model.isArmed()) {
            state = State.UNCHECKEDPRESSED;
          } else if (model.isRollover()) {
            state = State.UNCHECKEDHOT;
          }
        }
        skin.paintSkin(g, x, y, state);
      } else {
        // fill interior
        if ((model.isPressed() && model.isArmed()) || !model.isEnabled()) {
          g.setColor(UIManager.getColor("RadioButton.background"));
        } else {
          g.setColor(UIManager.getColor("RadioButton.interiorBackground"));
        }
        g.fillRect(x + 2, y + 2, 8, 8);

        // outter left arc
        g.setColor(UIManager.getColor("RadioButton.shadow"));
        g.drawLine(x + 4, y + 0, x + 7, y + 0);
        g.drawLine(x + 2, y + 1, x + 3, y + 1);
        g.drawLine(x + 8, y + 1, x + 9, y + 1);
        g.drawLine(x + 1, y + 2, x + 1, y + 3);
        g.drawLine(x + 0, y + 4, x + 0, y + 7);
        g.drawLine(x + 1, y + 8, x + 1, y + 9);

        // outter right arc
        g.setColor(UIManager.getColor("RadioButton.highlight"));
        g.drawLine(x + 2, y + 10, x + 3, y + 10);
        g.drawLine(x + 4, y + 11, x + 7, y + 11);
        g.drawLine(x + 8, y + 10, x + 9, y + 10);
        g.drawLine(x + 10, y + 9, x + 10, y + 8);
        g.drawLine(x + 11, y + 7, x + 11, y + 4);
        g.drawLine(x + 10, y + 3, x + 10, y + 2);

        // inner left arc
        g.setColor(UIManager.getColor("RadioButton.darkShadow"));
        g.drawLine(x + 4, y + 1, x + 7, y + 1);
        g.drawLine(x + 2, y + 2, x + 3, y + 2);
        g.drawLine(x + 8, y + 2, x + 9, y + 2);
        g.drawLine(x + 2, y + 3, x + 2, y + 3);
        g.drawLine(x + 1, y + 4, x + 1, y + 7);
        g.drawLine(x + 2, y + 8, x + 2, y + 8);

        // inner right arc
        g.setColor(UIManager.getColor("RadioButton.light"));
        g.drawLine(x + 2, y + 9, x + 3, y + 9);
        g.drawLine(x + 4, y + 10, x + 7, y + 10);
        g.drawLine(x + 8, y + 9, x + 9, y + 9);
        g.drawLine(x + 9, y + 8, x + 9, y + 8);
        g.drawLine(x + 10, y + 7, x + 10, y + 4);
        g.drawLine(x + 9, y + 3, x + 9, y + 3);

        // indicate whether selected or not
        if (model.isSelected()) {
          if (model.isEnabled()) {
            g.setColor(UIManager.getColor("RadioButton.foreground"));
          } else {
            g.setColor(UIManager.getColor("RadioButton.shadow"));
          }
          g.fillRect(x + 4, y + 5, 4, 2);
          g.fillRect(x + 5, y + 4, 2, 4);
        }
      }
    }
Example #30
0
    public void paintIcon(Component c, Graphics g, int x0, int y0) {
      int width = getIconWidth();
      int height = getIconHeight();

      XPStyle xp = XPStyle.getXP();
      if (xp != null) {
        Skin skin = xp.getSkin(c, part);
        AbstractButton b = (AbstractButton) c;
        ButtonModel model = b.getModel();

        // Find out if frame is inactive
        JInternalFrame jif =
            (JInternalFrame) SwingUtilities.getAncestorOfClass(JInternalFrame.class, b);
        boolean jifSelected = (jif != null && jif.isSelected());

        State state;
        if (jifSelected) {
          if (!model.isEnabled()) {
            state = State.DISABLED;
          } else if (model.isArmed() && model.isPressed()) {
            state = State.PUSHED;
          } else if (model.isRollover()) {
            state = State.HOT;
          } else {
            state = State.NORMAL;
          }
        } else {
          if (!model.isEnabled()) {
            state = State.INACTIVEDISABLED;
          } else if (model.isArmed() && model.isPressed()) {
            state = State.INACTIVEPUSHED;
          } else if (model.isRollover()) {
            state = State.INACTIVEHOT;
          } else {
            state = State.INACTIVENORMAL;
          }
        }
        skin.paintSkin(g, 0, 0, width, height, state);
      } else {
        g.setColor(Color.black);
        int x = width / 12 + 2;
        int y = height / 5;
        int h = height - y * 2 - 1;
        int w = width * 3 / 4 - 3;
        int thickness2 = Math.max(height / 8, 2);
        int thickness = Math.max(width / 15, 1);
        if (part == Part.WP_CLOSEBUTTON) {
          int lineWidth;
          if (width > 47) lineWidth = 6;
          else if (width > 37) lineWidth = 5;
          else if (width > 26) lineWidth = 4;
          else if (width > 16) lineWidth = 3;
          else if (width > 12) lineWidth = 2;
          else lineWidth = 1;
          y = height / 12 + 2;
          if (lineWidth == 1) {
            if (w % 2 == 1) {
              x++;
              w++;
            }
            g.drawLine(x, y, x + w - 2, y + w - 2);
            g.drawLine(x + w - 2, y, x, y + w - 2);
          } else if (lineWidth == 2) {
            if (w > 6) {
              x++;
              w--;
            }
            g.drawLine(x, y, x + w - 2, y + w - 2);
            g.drawLine(x + w - 2, y, x, y + w - 2);
            g.drawLine(x + 1, y, x + w - 1, y + w - 2);
            g.drawLine(x + w - 1, y, x + 1, y + w - 2);
          } else {
            x += 2;
            y++;
            w -= 2;
            g.drawLine(x, y, x + w - 1, y + w - 1);
            g.drawLine(x + w - 1, y, x, y + w - 1);
            g.drawLine(x + 1, y, x + w - 1, y + w - 2);
            g.drawLine(x + w - 2, y, x, y + w - 2);
            g.drawLine(x, y + 1, x + w - 2, y + w - 1);
            g.drawLine(x + w - 1, y + 1, x + 1, y + w - 1);
            for (int i = 4; i <= lineWidth; i++) {
              g.drawLine(x + i - 2, y, x + w - 1, y + w - i + 1);
              g.drawLine(x, y + i - 2, x + w - i + 1, y + w - 1);
              g.drawLine(x + w - i + 1, y, x, y + w - i + 1);
              g.drawLine(x + w - 1, y + i - 2, x + i - 2, y + w - 1);
            }
          }
        } else if (part == Part.WP_MINBUTTON) {
          g.fillRect(x, y + h - thickness2, w - w / 3, thickness2);
        } else if (part == Part.WP_MAXBUTTON) {
          g.fillRect(x, y, w, thickness2);
          g.fillRect(x, y, thickness, h);
          g.fillRect(x + w - thickness, y, thickness, h);
          g.fillRect(x, y + h - thickness, w, thickness);
        } else if (part == Part.WP_RESTOREBUTTON) {
          g.fillRect(x + w / 3, y, w - w / 3, thickness2);
          g.fillRect(x + w / 3, y, thickness, h / 3);
          g.fillRect(x + w - thickness, y, thickness, h - h / 3);
          g.fillRect(x + w - w / 3, y + h - h / 3 - thickness, w / 3, thickness);

          g.fillRect(x, y + h / 3, w - w / 3, thickness2);
          g.fillRect(x, y + h / 3, thickness, h - h / 3);
          g.fillRect(x + w - w / 3 - thickness, y + h / 3, thickness, h - h / 3);
          g.fillRect(x, y + h - thickness, w - w / 3, thickness);
        }
      }
    }