Ejemplo n.º 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);
      }
    }
Ejemplo n.º 2
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);
        }
      }
    }
Ejemplo n.º 3
0
 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());
     }
   }
 }
Ejemplo n.º 4
0
 protected void paintFocus(
     Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
   Graphics2D g2D = (Graphics2D) g;
   int width = b.getWidth();
   int height = b.getHeight();
   if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) {
     g.setColor(AbstractLookAndFeel.getFocusColor());
     BasicGraphicsUtils.drawDashedRect(g, 4, 3, width - 8, height - 6);
   } else {
     Object savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
     g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     g2D.setColor(AbstractLookAndFeel.getFocusColor());
     int d = b.getHeight() - 4;
     g2D.drawRoundRect(2, 2, b.getWidth() - 5, b.getHeight() - 5, d, d);
     g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRenderingHint);
   }
 }
Ejemplo n.º 5
0
 protected void paintBackground(Graphics g, AbstractButton b) {
   if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) {
     return;
   }
   int width = b.getWidth();
   int height = b.getHeight();
   Graphics2D g2D = (Graphics2D) g;
   Shape savedClip = g.getClip();
   if ((b.getBorder() != null) && b.isBorderPainted() && (b.getBorder() instanceof UIResource)) {
     Area clipArea = new Area(new Rectangle2D.Double(1, 1, width - 2, height - 2));
     if (savedClip != null) {
       clipArea.intersect(new Area(savedClip));
     }
     g2D.setClip(clipArea);
   }
   super.paintBackground(g, b);
   g2D.setClip(savedClip);
 }
Ejemplo n.º 6
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());
  }
Ejemplo n.º 7
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      if (!JTattooUtilities.isLeftToRight(c)) {
        x += GAP;
      }
      int w = getIconWidth() - GAP;
      int h = getIconHeight();

      Graphics2D g2D = (Graphics2D) g;
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      Color colors[];
      if (button.isEnabled()) {
        if ((button.isRolloverEnabled() && model.isRollover())
            || (model.isPressed() && model.isArmed())) {
          colors = AbstractLookAndFeel.getTheme().getRolloverColors();
        } else {
          if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) {
            colors = AbstractLookAndFeel.getTheme().getFocusColors();
          } else {
            colors = AbstractLookAndFeel.getTheme().getCheckBoxColors();
          }
        }
      } else {
        colors = AbstractLookAndFeel.getTheme().getDisabledColors();
      }

      Color frameColor =
          ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6);
      Shape savedClip = g.getClip();
      Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1));
      if (savedClip != null) {
        clipArea.intersect(new Area(savedClip));
      }
      g2D.setClip(clipArea);
      JTattooUtilities.fillHorGradient(g, colors, x, y, w, h);
      g2D.setClip(savedClip);

      Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(frameColor);
      g.drawOval(x, y, w, h);

      if (model.isSelected()) {
        if (model.isEnabled()) {
          Color fc = AbstractLookAndFeel.getForegroundColor();
          if (ColorHelper.getGrayValue(colors[0]) < 128) {
            if (ColorHelper.getGrayValue(fc) < 128) {
              g2D.setColor(Color.white);
            } else {
              g2D.setColor(fc);
            }
          } else {
            if (ColorHelper.getGrayValue(fc) > 128) {
              g2D.setColor(Color.black);
            } else {
              g2D.setColor(fc);
            }
          }
        } else {
          g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
        }
        if (AbstractLookAndFeel.getTheme().isSmallFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else {
          g2D.fillOval(x + 5, y + 5, w - 9, h - 9);
        }
      }
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
    }
Ejemplo n.º 8
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      if (!JTattooUtilities.isLeftToRight(c)) {
        x += GAP;
      }
      int w = getIconWidth() - GAP;
      int h = getIconHeight();
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      Graphics2D g2D = (Graphics2D) g;
      if (button.isEnabled()) {
        if ((button.isRolloverEnabled() && model.isRollover())) {
          JTattooUtilities.fillHorGradient(
              g, AbstractLookAndFeel.getTheme().getRolloverColors(), x + 1, y + 1, w - 1, h - 1);
        } else {
          if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) {
            JTattooUtilities.fillHorGradient(
                g, AbstractLookAndFeel.getTheme().getFocusColors(), x + 1, y + 1, w - 1, h - 1);
          } else {
            JTattooUtilities.fillHorGradient(
                g, AbstractLookAndFeel.getTheme().getCheckBoxColors(), x + 1, y + 1, w - 1, h - 1);
          }
        }
      } else {
        JTattooUtilities.fillHorGradient(
            g, AbstractLookAndFeel.getTheme().getDisabledColors(), x + 1, y + 1, w - 1, h - 1);
      }

      Color frameColor =
          ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6);
      Color loFrameColor =
          ColorHelper.darker(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 50);

      g.setColor(frameColor);
      g.drawRect(x, y, w, h);
      Composite savedComposite = g2D.getComposite();
      AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
      g2D.setComposite(alpha);
      g.setColor(loFrameColor);
      g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
      g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
      g2D.setComposite(savedComposite);

      Icon checkIcon;
      Icon checkDisabledIcon;
      Icon checkInverseIcon;
      if (AbstractLookAndFeel.getTheme().isSmallFontSize()) {
        checkIcon = SMALL_CHECK_ICON;
        checkDisabledIcon = SMALL_CHECK_DISABLED_ICON;
        checkInverseIcon = SMALL_CHECK_INVERSE_ICON;
      } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) {
        checkIcon = MEDIUM_CHECK_ICON;
        checkDisabledIcon = MEDIUM_CHECK_DISABLED_ICON;
        checkInverseIcon = MEDIUM_CHECK_INVERSE_ICON;
      } else {
        checkIcon = LARGE_CHECK_ICON;
        checkDisabledIcon = LARGE_CHECK_DISABLED_ICON;
        checkInverseIcon = LARGE_CHECK_INVERSE_ICON;
      }
      int xi = x + ((w - checkIcon.getIconWidth()) / 2) + 1;
      int yi = y + ((h - checkIcon.getIconHeight()) / 2);
      int gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getButtonForegroundColor());
      if (model.isPressed() && model.isArmed()) {
        Color bc =
            gv > 128
                ? AbstractLookAndFeel.getTheme().getSelectionForegroundColor()
                : AbstractLookAndFeel.getTheme().getSelectionBackgroundColor();
        Color fc = gv > 128 ? ColorHelper.brighter(bc, 20) : ColorHelper.darker(bc, 40);
        g.setColor(fc);
        g.drawRect(x + 4, y + 4, w - 8, h - 8);
        g.setColor(bc);
        g.fillRect(x + 5, y + 5, w - 9, h - 9);
      } else if (model.isSelected()) {
        if (!model.isEnabled()) {
          checkDisabledIcon.paintIcon(c, g, xi + 1, yi);
        } else {
          if (gv > 128) {
            checkIcon.paintIcon(c, g, xi, yi);
          } else {
            checkInverseIcon.paintIcon(c, g, xi + 1, yi + 1);
          }
        }
      }
    }
Ejemplo n.º 9
0
  protected void paintBackground(Graphics g, AbstractButton b) {
    if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) {
      return;
    }

    if (!(b.isBorderPainted() && (b.getBorder() instanceof UIResource))) {
      super.paintBackground(g, b);
      return;
    }

    int width = b.getWidth();
    int height = b.getHeight();
    ButtonModel model = b.getModel();
    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) {
      if (model.isSelected()) {
        Color color = ColorHelper.darker(b.getBackground(), 20);
        g2D.setColor(color);
        g2D.fillRect(0, 0, width - 1, height - 1);
        if (model.isEnabled()) {
          g2D.setColor(AbstractLookAndFeel.getFrameColor());
        } else {
          g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
        }
        g2D.drawRect(0, 0, width - 1, height - 1);
      } else {
        Color[] colors = null;
        if (b.getBackground() instanceof ColorUIResource) {
          if (!model.isEnabled()) {
            colors = AbstractLookAndFeel.getTheme().getDisabledColors();
          } else if (b.isRolloverEnabled() && model.isRollover()) {
            colors = AbstractLookAndFeel.getTheme().getRolloverColors();
          } else {
            colors = AbstractLookAndFeel.getTheme().getButtonColors();
          }
        } else {
          colors =
              ColorHelper.createColorArr(
                  ColorHelper.brighter(b.getBackground(), 20),
                  ColorHelper.darker(b.getBackground(), 20),
                  20);
        }
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1);
        if (model.isEnabled()) {
          g2D.setColor(AbstractLookAndFeel.getFrameColor());
        } else {
          g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
        }
        g2D.drawRect(0, 0, width - 1, height - 1);
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
        g2D.setComposite(alpha);
        g2D.setColor(Color.white);
        g2D.drawRect(1, 1, width - 3, height - 3);
      }
    } else if (model.isPressed() && model.isArmed()) {
      int d = height - 2;
      Color color = AbstractLookAndFeel.getTheme().getSelectionBackgroundColor();
      g2D.setColor(color);
      g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d);

      g2D.setColor(ColorHelper.darker(color, 40));
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);
    } else if (model.isSelected()) {
      int d = height - 2;
      Color color = ColorHelper.darker(b.getBackground(), 20);
      g2D.setColor(color);
      g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d);

      if (model.isEnabled()) {
        g2D.setColor(AbstractLookAndFeel.getFrameColor());
      } else {
        g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
      }
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);
    } else {
      int d = height - 2;

      Color[] colors = null;
      if (b.getBackground() instanceof ColorUIResource) {
        if (!model.isEnabled()) {
          colors = AbstractLookAndFeel.getTheme().getDisabledColors();
        } else if (b.isRolloverEnabled() && model.isRollover()) {
          colors = AbstractLookAndFeel.getTheme().getRolloverColors();
        } else {
          colors = AbstractLookAndFeel.getTheme().getButtonColors();
        }
      } else {
        colors =
            ColorHelper.createColorArr(
                ColorHelper.brighter(b.getBackground(), 20),
                ColorHelper.darker(b.getBackground(), 20),
                20);
      }

      Shape savedClip = g.getClip();
      Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d));
      clipArea.intersect(new Area(savedClip));
      g2D.setClip(clipArea);
      JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height);
      g2D.setClip(savedClip);

      if (model.isEnabled()) {
        g2D.setColor(AbstractLookAndFeel.getFrameColor());
      } else {
        g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
      }
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);

      AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
      g2D.setComposite(alpha);
      g2D.setColor(Color.white);
      g2D.drawRoundRect(1, 1, width - 3, height - 3, d - 2, d - 2);
    }
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
    g2D.setComposite(composite);
  }