Search in sources :

Example 66 with AlphaComposite

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

the class SmartInternalFrameTitlePane method paintPalette.

/**
 * {@inheritDoc}
 */
@Override
public void paintPalette(Graphics g) {
    int width = getWidth();
    int height = getHeight();
    Color backColor;
    Color frameColor;
    if (JTattooUtilities.isFrameActive(this)) {
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowTitleColors(), 0, 0, width, height);
        backColor = AbstractLookAndFeel.getTheme().getWindowTitleColors()[10];
        frameColor = ColorHelper.darker(AbstractLookAndFeel.getWindowTitleColorDark(), 15);
    } else {
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors(), 0, 0, width, height);
        backColor = AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors()[10];
        frameColor = ColorHelper.darker(AbstractLookAndFeel.getWindowInactiveTitleColorDark(), 15);
    }
    g.setColor(frameColor);
    g.drawLine(0, height - 1, width, height - 1);
    int dx = 8;
    int dy = 2;
    int dw = width - buttonsWidth - 2 * 8;
    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
    g2D.setComposite(alpha);
    float dc1 = 50.0f;
    float dc2 = 5.0f;
    Color c1 = ColorHelper.brighter(backColor, dc1);
    Color c2;
    while (dy + 2 < height) {
        c2 = ColorHelper.darker(backColor, dc2);
        dc2 += 5.0f;
        g.setColor(c1);
        g.drawLine(dx, dy, dx + dw, dy);
        dy++;
        g.setColor(c2);
        g.drawLine(dx, dy, dx + dw, dy);
        dy += 2;
    }
    g2D.setComposite(composite);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 67 with AlphaComposite

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

the class SmartTitlePane method paintBackground.

/**
 * {@inheritDoc}
 */
@Override
public void paintBackground(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    int width = getWidth();
    int height = getHeight();
    Color backColor;
    Color frameColor;
    if (JTattooUtilities.isActive(this)) {
        backColor = AbstractLookAndFeel.getTheme().getWindowTitleColors()[10];
        frameColor = AbstractLookAndFeel.getTheme().getFrameColor();
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowTitleColors(), 0, 0, width, height);
    } else {
        backColor = AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors()[10];
        frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40);
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors(), 0, 0, width, height);
    }
    int iconWidth = 0;
    if (menuBar != null) {
        iconWidth = menuBar.getWidth() + 5;
    }
    int titleWidth = 0;
    String frameTitle = getTitle();
    if (frameTitle != null) {
        Font f = getFont();
        g.setFont(f);
        FontMetrics fm = g.getFontMetrics();
        titleWidth = fm.stringWidth(JTattooUtilities.getClippedText(getTitle(), fm, getWidth() - iconWidth - buttonsWidth - 15)) + 10;
        if (getWindow() instanceof JDialog) {
            Image image = getFrameIconImage();
            if (image != null) {
                titleWidth += getHeight();
            }
        }
    }
    int dx;
    int dw;
    boolean leftToRight = isLeftToRight();
    int xOffset = leftToRight ? iconWidth + 10 + titleWidth : width - 10 - iconWidth - titleWidth;
    if (leftToRight) {
        dw = width - buttonsWidth - xOffset - 10;
        dx = xOffset;
    } else {
        dw = xOffset - buttonsWidth - 10;
        dx = buttonsWidth + 10;
    }
    int dy = 3;
    if (!AbstractLookAndFeel.getTheme().isMacStyleWindowDecorationOn() && !AbstractLookAndFeel.getTheme().isCenterWindowTitleOn() && dw > 0) {
        Composite composite = g2D.getComposite();
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
        g2D.setComposite(alpha);
        float dc1 = 50.0f;
        float dc2 = 5.0f;
        Color c1 = ColorHelper.brighter(backColor, dc1);
        Color c2;
        while (dy + 5 < height) {
            c2 = ColorHelper.darker(backColor, dc2);
            dc2 += 5.0f;
            g.setColor(c1);
            g.drawLine(dx, dy, dx + dw, dy);
            dy++;
            g.setColor(c2);
            g.drawLine(dx, dy, dx + dw, dy);
            dy += 3;
        }
        g2D.setComposite(composite);
    }
    g.setColor(frameColor);
    g.drawLine(0, height - 1, width, height - 1);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Image(java.awt.Image) Font(java.awt.Font) JDialog(javax.swing.JDialog) Graphics2D(java.awt.Graphics2D)

Example 68 with AlphaComposite

use of java.awt.AlphaComposite in project hutool by dromara.

the class GifCaptcha method graphicsImage.

/**
 * 画随机码图
 *
 * @param fontColor 随机字体颜色
 * @param words     字符数组
 * @param flag      透明度使用
 * @return BufferedImage
 */
private BufferedImage graphicsImage(char[] chars, Color[] fontColor, char[] words, int flag) {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    // 或得图形上下文
    Graphics2D g2d = image.createGraphics();
    // 利用指定颜色填充背景
    g2d.setColor(ObjectUtil.defaultIfNull(this.background, Color.WHITE));
    g2d.fillRect(0, 0, width, height);
    AlphaComposite ac;
    // 字符的y坐标
    float y = (height >> 1) + (font.getSize() >> 1);
    float m = 1.0f * (width - (chars.length * font.getSize())) / chars.length;
    // 字符的x坐标
    float x = Math.max(m / 2.0f, 2);
    g2d.setFont(font);
    // 指定透明度
    if (null != this.textAlpha) {
        g2d.setComposite(this.textAlpha);
    }
    for (int i = 0; i < chars.length; i++) {
        ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(chars.length, flag, i));
        g2d.setComposite(ac);
        g2d.setColor(fontColor[i]);
        g2d.drawOval(RandomUtil.randomInt(width), RandomUtil.randomInt(height), RandomUtil.randomInt(5, 30), 5 + RandomUtil.randomInt(5, 30));
        // 绘制椭圆边框
        g2d.drawString(words[i] + "", x + (font.getSize() + m) * i, y);
    }
    g2d.dispose();
    return image;
}
Also used : AlphaComposite(java.awt.AlphaComposite) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 69 with AlphaComposite

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

the class AluminiumSplitPaneDivider method paint.

/**
 * {@inheritDoc}
 */
@Override
public void paint(final Graphics g) {
    if (JTattooUtilities.isMac() || !AbstractLookAndFeel.getTheme().isBackgroundPatternOn()) {
        super.paint(g);
    } else {
        AluminiumUtils.fillComponent(g, this);
        Graphics2D g2D = (Graphics2D) g;
        Composite composite = g2D.getComposite();
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
        g2D.setComposite(alpha);
        super.paint(g);
        g2D.setComposite(composite);
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Graphics2D(java.awt.Graphics2D)

Example 70 with AlphaComposite

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

the class AluminiumToggleButtonUI 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 (b.isEnabled()) {
        Color background = b.getBackground();
        if (background instanceof ColorUIResource) {
            if (b.isRolloverEnabled() && model.isRollover()) {
                colors = AbstractLookAndFeel.getTheme().getRolloverColors();
            } else if (model.isPressed() && model.isArmed() || model.isSelected()) {
                colors = AbstractLookAndFeel.getTheme().getPressedColors();
            } else {
                if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && b.hasFocus()) {
                    colors = AbstractLookAndFeel.getTheme().getFocusColors();
                } 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()) {
                if (model.isSelected()) {
                    colors = ColorHelper.createColorArr(ColorHelper.darker(background, 20), background, 20);
                } else {
                    colors = ColorHelper.createColorArr(ColorHelper.brighter(background, 50), ColorHelper.brighter(background, 10), 20);
                }
            } else if (model.isSelected()) {
                colors = ColorHelper.createColorArr(ColorHelper.darker(background, 40), ColorHelper.darker(background, 20), 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);
        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)

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