Search in sources :

Example 21 with AlphaComposite

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

the class SVGSVGElementImpl method draw.

/**
 * {@inheritDoc}
 */
@Override
public void draw(final Graphics2D graphics) {
    recalculateViewboxToViewportTransform();
    boolean display = getDisplay();
    float opacity = getOpacity();
    if (display && opacity > 0) {
        AffineTransform oldGraphicsTransform = graphics.getTransform();
        Shape oldClip = graphics.getClip();
        graphics.translate(viewport.getX(), viewport.getY());
        if (opacity < 1) {
            SVGSVGElement root = this;
            float currentScale = root.getCurrentScale();
            // create buffer to draw on
            Shape shape = createShape(null);
            AffineTransform screenCTM = getScreenCTM().getAffineTransform();
            Shape transformedShape = screenCTM.createTransformedShape(shape);
            Rectangle2D bounds = transformedShape.getBounds2D();
            double xInc = bounds.getWidth() / 5;
            double yInc = bounds.getHeight() / 5;
            bounds.setRect(bounds.getX() - xInc, bounds.getY() - yInc, bounds.getWidth() + 2 * xInc, bounds.getHeight() + 2 * yInc);
            int imageWidth = (int) (bounds.getWidth() * currentScale);
            int imageHeight = (int) (bounds.getHeight() * currentScale);
            if (imageWidth > 0 && imageHeight > 0) {
                BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_4BYTE_ABGR);
                Graphics2D offGraphics = (Graphics2D) image.getGraphics();
                RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                offGraphics.setRenderingHints(hints);
                if (currentScale != 1) {
                    offGraphics.scale(currentScale, currentScale);
                }
                offGraphics.translate(-bounds.getX(), -bounds.getY());
                offGraphics.transform(screenCTM);
                drawChildren(offGraphics);
                Composite oldComposite = graphics.getComposite();
                AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
                graphics.setComposite(ac);
                AffineTransform imageTransform = AffineTransform.getTranslateInstance(bounds.getX(), bounds.getY());
                imageTransform.scale(1 / currentScale, 1 / currentScale);
                try {
                    imageTransform.preConcatenate(screenCTM.createInverse());
                } catch (NoninvertibleTransformException e) {
                }
                graphics.drawImage(image, imageTransform, null);
                graphics.setComposite(oldComposite);
                image.flush();
            }
        } else {
            drawChildren(graphics);
        }
        graphics.setTransform(oldGraphicsTransform);
        graphics.setClip(oldClip);
    }
}
Also used : Shape(java.awt.Shape) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Rectangle2D(java.awt.geom.Rectangle2D) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AffineTransform(java.awt.geom.AffineTransform)

Example 22 with AlphaComposite

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

the class GraphiteMenuUI method paintBackground.

/**
 * {@inheritDoc}
 */
@Override
protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
    JMenuItem b = (JMenuItem) c;
    ButtonModel model = b.getModel();
    if (c.getParent() instanceof JMenuBar) {
        if (model.isRollover() || model.isArmed() || c instanceof JMenu && model.isSelected()) {
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getMenuSelectionColors(), x, y, w, h);
        }
        if (model.isRollover() && !model.isSelected()) {
            Color[] colArr = AbstractLookAndFeel.getTheme().getMenuSelectionColors();
            Color frameColor = ColorHelper.darker(colArr[colArr.length - 1], 5);
            g.setColor(frameColor);
            g.drawRect(x, y, w - 1, h - 1);
        }
    } else {
        if (model.isArmed() || c instanceof JMenu && model.isSelected()) {
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getMenuSelectionColors(), x, y, w, h);
        } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
            Graphics2D g2D = (Graphics2D) g;
            Composite composite = g2D.getComposite();
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
            g2D.setComposite(alpha);
            g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
            g.fillRect(x, y, w, h);
            g2D.setComposite(composite);
        } else {
            g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
            g.fillRect(x, y, w, h);
        }
    }
    if (menuItem.isSelected() && menuItem.isArmed()) {
        g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
    } else {
        g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) JMenuItem(javax.swing.JMenuItem) ButtonModel(javax.swing.ButtonModel) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) Graphics2D(java.awt.Graphics2D)

Example 23 with AlphaComposite

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

the class HiFiToggleButtonUI method paintText.

/**
 * {@inheritDoc}
 */
@Override
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 = b.getDisplayedMnemonicIndex();
    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 (model.isPressed() && model.isArmed() || model.isSelected()) {
        if (foreground instanceof ColorUIResource && background instanceof ColorUIResource) {
            foreground = AbstractLookAndFeel.getTheme().getPressedForegroundColor();
        }
    }
    if (!model.isEnabled()) {
        foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
    }
    if (ColorHelper.getGrayValue(foreground) > 128) {
        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());
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) FontMetrics(java.awt.FontMetrics) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) ButtonModel(javax.swing.ButtonModel) ColorUIResource(javax.swing.plaf.ColorUIResource) Graphics2D(java.awt.Graphics2D)

Example 24 with AlphaComposite

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

the class HiFiTabbedPaneUI method paintText.

/**
 * {@inheritDoc}
 */
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title, Rectangle textRect, boolean isSelected) {
    Color backColor = tabPane.getBackgroundAt(tabIndex);
    if (!(backColor instanceof UIResource)) {
        super.paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
        return;
    }
    g.setFont(font);
    View v = getTextViewForTab(tabIndex);
    if (v != null) {
        // html
        Graphics2D g2D = (Graphics2D) g;
        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 {
        // plain text
        int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
        Graphics2D g2D = (Graphics2D) g;
        Composite composite = g2D.getComposite();
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
        g2D.setComposite(alpha);
        Color fc = tabPane.getForegroundAt(tabIndex);
        if (isSelected) {
            fc = AbstractLookAndFeel.getTheme().getTabSelectionForegroundColor();
        }
        if (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex)) {
            fc = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
        }
        if (ColorHelper.getGrayValue(fc) > 128) {
            g2D.setColor(Color.black);
        } else {
            g2D.setColor(Color.white);
        }
        JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x + 1, textRect.y + 1 + metrics.getAscent());
        g2D.setComposite(composite);
        g2D.setColor(fc);
        JTattooUtilities.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) View(javax.swing.text.View) UIResource(javax.swing.plaf.UIResource) Graphics2D(java.awt.Graphics2D)

Example 25 with AlphaComposite

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

the class CanvasRenderingImpl method setGlobalAlpha.

/**
 * {@inheritDoc}
 */
@Override
public void setGlobalAlpha(Double globalAlpha) {
    if (globalAlpha >= 0 && globalAlpha <= 1) {
        Graphics2D graphics = createGraphics();
        final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, globalAlpha.floatValue());
        graphics.setComposite(composite);
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) 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