Search in sources :

Example 61 with AlphaComposite

use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.

the class BaseToggleButtonUI method paint.

/**
 * {@inheritDoc}
 */
@Override
public void paint(final Graphics g, final JComponent c) {
    Graphics2D g2D = (Graphics2D) g;
    AbstractButton b = (AbstractButton) c;
    g.setFont(b.getFont());
    FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
    Insets insets = c.getInsets();
    viewRect.x = insets.left;
    viewRect.y = insets.top;
    viewRect.width = b.getWidth() - (insets.right + viewRect.x);
    viewRect.height = b.getHeight() - (insets.bottom + viewRect.y);
    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
    int iconTextGap = b.getIconTextGap();
    String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : iconTextGap);
    paintBackground(g, b);
    if (b.getIcon() != null) {
        if (!b.isEnabled()) {
            Composite savedComposite = g2D.getComposite();
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
            g2D.setComposite(alpha);
            paintIcon(g, c, iconRect);
            g2D.setComposite(savedComposite);
        } else {
            paintIcon(g, c, iconRect);
        }
    }
    if (text != null && !text.equals("") && textRect != null) {
        View v = (View) c.getClientProperty(BasicHTML.propertyKey);
        if (v != null) {
            Object savedRenderingHint = null;
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
            }
            v.paint(g, textRect);
            if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
                g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
            }
        } else {
            paintText(g, b, textRect, text);
        }
    }
    if (b.isFocusPainted() && b.hasFocus()) {
        paintFocus(g, b, viewRect, textRect, iconRect);
    }
}
Also used : AbstractButton(javax.swing.AbstractButton) Insets(java.awt.Insets) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) AlphaComposite(java.awt.AlphaComposite) View(javax.swing.text.View) Graphics2D(java.awt.Graphics2D)

Example 62 with AlphaComposite

use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.

the class AluminiumButtonUI method paintBackground.

/**
 * {@inheritDoc}
 */
@Override
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 savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color[] colors;
    if (model.isEnabled()) {
        Color background = b.getBackground();
        if (background instanceof ColorUIResource) {
            if (model.isPressed() && model.isArmed()) {
                colors = AbstractLookAndFeel.getTheme().getPressedColors();
            } else {
                if (b.isRolloverEnabled() && model.isRollover()) {
                    colors = AbstractLookAndFeel.getTheme().getRolloverColors();
                } else if (b.getRootPane() != null && b.equals(b.getRootPane().getDefaultButton())) {
                    colors = AbstractLookAndFeel.getTheme().getSelectedColors();
                } else {
                    colors = AbstractLookAndFeel.getTheme().getButtonColors();
                }
            }
        } else {
            if (model.isPressed() && model.isArmed()) {
                colors = ColorHelper.createColorArr(ColorHelper.darker(background, 30), ColorHelper.darker(background, 10), 20);
            } else {
                if (b.isRolloverEnabled() && model.isRollover()) {
                    colors = ColorHelper.createColorArr(ColorHelper.brighter(background, 50), ColorHelper.brighter(background, 10), 20);
                } else {
                    colors = ColorHelper.createColorArr(ColorHelper.brighter(background, 30), ColorHelper.darker(background, 10), 20);
                }
            }
        }
    } else {
        colors = AbstractLookAndFeel.getTheme().getDisabledColors();
    }
    if (AbstractLookAndFeel.getTheme().doDrawSquareButtons() || (width < 64 || height < 16) && (b.getText() == null || b.getText().length() == 0)) {
        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 {
        int d = height - 2;
        Shape savedClip = g.getClip();
        Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d));
        if (savedClip != null) {
            clipArea.intersect(new Area(savedClip));
        }
        g2D.setClip(clipArea);
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1);
        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, savedRenderingHint);
    g2D.setComposite(composite);
}
Also used : Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) ColorUIResource(javax.swing.plaf.ColorUIResource) ColorUIResource(javax.swing.plaf.ColorUIResource) UIResource(javax.swing.plaf.UIResource) Graphics2D(java.awt.Graphics2D) Area(java.awt.geom.Area) ButtonModel(javax.swing.ButtonModel) JMenuBar(javax.swing.JMenuBar)

Example 63 with AlphaComposite

use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.

the class XPScrollBarUI method paintThumb.

/**
 * {@inheritDoc}
 */
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    if (!c.isEnabled()) {
        return;
    }
    Graphics2D g2D = (Graphics2D) g;
    Composite savedComposite = g2D.getComposite();
    int x = thumbBounds.x;
    int y = thumbBounds.y;
    int width = thumbBounds.width;
    int height = thumbBounds.height;
    g.translate(x, y);
    Color[] colors = getThumbColors();
    if (scrollbar.getOrientation() == Adjustable.VERTICAL) {
        JTattooUtilities.fillVerGradient(g, colors, 0, 0, width, height);
        if (!AbstractLookAndFeel.getTheme().isMacStyleScrollBarOn()) {
            int dx = 6;
            int dy = height / 2 - 3;
            int dw = width - 13;
            Color c1 = ColorHelper.brighter(colors[0], 60);
            Color c2 = ColorHelper.darker(colors[0], 30);
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
            g2D.setComposite(alpha);
            for (int i = 0; i < 4; i++) {
                g.setColor(c1);
                g.drawLine(dx, dy, dx + dw, dy);
                dy++;
                g.setColor(c2);
                g.drawLine(dx, dy, dx + dw, dy);
                dy++;
            }
        }
    } else {
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height);
        if (!AbstractLookAndFeel.getTheme().isMacStyleScrollBarOn()) {
            int dx = width / 2 - 3;
            int dy = 6;
            int dh = height - 13;
            Color c1 = ColorHelper.brighter(colors[0], 60);
            Color c2 = ColorHelper.darker(colors[0], 30);
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f);
            g2D.setComposite(alpha);
            for (int i = 0; i < 4; i++) {
                g.setColor(c1);
                g.drawLine(dx, dy, dx, dy + dh);
                dx++;
                g.setColor(c2);
                g.drawLine(dx, dy, dx, dy + dh);
                dx++;
            }
        }
    }
    g.setColor(getFrameColor());
    g.drawLine(1, 1, width - 2, 1);
    g.drawLine(1, 2, 1, height - 3);
    g.drawLine(width - 2, 2, width - 2, height - 3);
    g.drawLine(2, height - 2, width - 3, height - 2);
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
    g2D.setComposite(alpha);
    Color fc = colors[colors.length - 1];
    g2D.setColor(fc);
    g.drawLine(2, 2, width - 3, 2);
    g.drawLine(2, 3, 2, height - 3);
    g.setColor(ColorHelper.darker(fc, 40));
    g.drawLine(width - 1, 2, width - 1, height - 3);
    g.drawLine(3, height - 1, width - 3, height - 1);
    alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
    g2D.setComposite(alpha);
    g.drawLine(1, height - 2, 2, height - 1);
    g.drawLine(width - 1, height - 2, width - 2, height - 1);
    g.translate(-x, -y);
    g2D.setComposite(savedComposite);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 64 with AlphaComposite

use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.

the class McWinButtonUI method paintBackground.

/**
 * {@inheritDoc}
 */
@Override
protected void paintBackground(Graphics g, AbstractButton b) {
    if (b.getParent() instanceof JToolBar) {
        b.setContentAreaFilled(true);
    }
    if (!b.isContentAreaFilled() || b.getParent() instanceof JMenuBar) {
        return;
    }
    int width = b.getWidth();
    int height = b.getHeight();
    if (!(b.isBorderPainted() && b.getBorder() instanceof UIResource) || b.getParent() instanceof JToolBar) {
        super.paintBackground(g, b);
        if (b.getParent() instanceof JToolBar) {
            g.setColor(Color.lightGray);
            g.drawRect(0, 0, width - 2, height - 1);
            g.setColor(AbstractLookAndFeel.getTheme().getToolbarBackgroundColor());
            g.drawLine(width - 1, 0, width - 1, height - 1);
        }
        return;
    }
    ButtonModel model = b.getModel();
    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    Object savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color[] colors = AbstractLookAndFeel.getTheme().getButtonColors();
    if (b.isEnabled()) {
        Color background = b.getBackground();
        if (background instanceof ColorUIResource) {
            if (model.isPressed() && model.isArmed()) {
                colors = AbstractLookAndFeel.getTheme().getPressedColors();
            } else if (b.isRolloverEnabled() && model.isRollover()) {
                colors = AbstractLookAndFeel.getTheme().getRolloverColors();
            } else {
                if (b.getRootPane() != null && b.equals(b.getRootPane().getDefaultButton())) {
                    if (JTattooUtilities.isFrameActive(b)) {
                        if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && b.hasFocus()) {
                            colors = AbstractLookAndFeel.getTheme().getFocusColors();
                        } else {
                            if (AbstractLookAndFeel.getTheme().isBrightMode()) {
                                colors = new Color[AbstractLookAndFeel.getTheme().getSelectedColors().length];
                                for (int i = 0; i < colors.length; i++) {
                                    colors[i] = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getSelectedColors()[i], 50);
                                }
                            } else {
                                colors = AbstractLookAndFeel.getTheme().getSelectedColors();
                            }
                        }
                    }
                } else {
                    if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && b.hasFocus()) {
                        colors = AbstractLookAndFeel.getTheme().getFocusColors();
                    }
                }
            }
        } else {
            // backgound != ColorUIResource
            if (model.isPressed() && model.isArmed()) {
                colors = ColorHelper.createColorArr(ColorHelper.darker(background, 30), ColorHelper.darker(background, 10), 20);
            } else {
                if (b.isRolloverEnabled() && model.isRollover()) {
                    colors = ColorHelper.createColorArr(ColorHelper.brighter(background, 50), ColorHelper.brighter(background, 10), 20);
                } else {
                    colors = ColorHelper.createColorArr(ColorHelper.brighter(background, 30), ColorHelper.darker(background, 10), 20);
                }
            }
        }
    } else {
        // disabled
        colors = AbstractLookAndFeel.getTheme().getDisabledColors();
    }
    if (AbstractLookAndFeel.getTheme().doDrawSquareButtons() || (width < 64 || height < 16) && (b.getText() == null || b.getText().length() == 0)) {
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1);
        Color frameColor = colors[colors.length / 2];
        g2D.setColor(ColorHelper.darker(frameColor, 25));
        g2D.drawRect(0, 0, width - 1, height - 1);
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
        g2D.setComposite(alpha);
        g2D.setColor(Color.white);
        g2D.drawRect(1, 1, width - 3, height - 3);
    } else {
        int d = height - 2;
        Color frameColor = colors[colors.length / 2];
        Shape savedClip = g.getClip();
        Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d));
        if (savedClip != null) {
            clipArea.intersect(new Area(savedClip));
        }
        g2D.setClip(clipArea);
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1);
        g2D.setClip(savedClip);
        g2D.setColor(ColorHelper.darker(frameColor, 25));
        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, savedRenderingHint);
    g2D.setComposite(composite);
}
Also used : Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) RoundRectangle2D(java.awt.geom.RoundRectangle2D) JToolBar(javax.swing.JToolBar) ColorUIResource(javax.swing.plaf.ColorUIResource) ColorUIResource(javax.swing.plaf.ColorUIResource) UIResource(javax.swing.plaf.UIResource) Graphics2D(java.awt.Graphics2D) Area(java.awt.geom.Area) ButtonModel(javax.swing.ButtonModel) JMenuBar(javax.swing.JMenuBar)

Example 65 with AlphaComposite

use of java.awt.AlphaComposite in project LoboEvolution by LoboEvolution.

the class McWinToggleButtonUI method paintBackground.

/**
 * {@inheritDoc}
 */
@Override
protected void paintBackground(Graphics g, AbstractButton b) {
    if (!b.isContentAreaFilled() || b.getParent() instanceof JMenuBar) {
        return;
    }
    super.paintBackground(g, b);
    int width = b.getWidth();
    int height = b.getHeight();
    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    g2D.setColor(Color.lightGray);
    g2D.drawRect(0, 0, width - 2, height - 1);
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
    g2D.setComposite(alpha);
    g2D.setColor(Color.white);
    g2D.drawLine(width - 1, 0, width - 1, height - 1);
    g2D.setComposite(composite);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) JMenuBar(javax.swing.JMenuBar) Graphics2D(java.awt.Graphics2D)

Aggregations

AlphaComposite (java.awt.AlphaComposite)80 Composite (java.awt.Composite)56 Graphics2D (java.awt.Graphics2D)56 Color (java.awt.Color)24 Paint (java.awt.Paint)10 ButtonModel (javax.swing.ButtonModel)10 FontMetrics (java.awt.FontMetrics)9 BufferedImage (java.awt.image.BufferedImage)9 ColorUIResource (javax.swing.plaf.ColorUIResource)9 UIResource (javax.swing.plaf.UIResource)8 GradientPaint (java.awt.GradientPaint)6 Shape (java.awt.Shape)6 Area (java.awt.geom.Area)6 Rectangle2D (java.awt.geom.Rectangle2D)6 Point (java.awt.Point)5 RoundRectangle2D (java.awt.geom.RoundRectangle2D)5 Icon (javax.swing.Icon)5 JMenuBar (javax.swing.JMenuBar)5 LinearGradientPaint (java.awt.LinearGradientPaint)4 AffineTransform (java.awt.geom.AffineTransform)4