Search in sources :

Example 56 with AlphaComposite

use of java.awt.AlphaComposite in project cytoscape-impl by cytoscape.

the class ImageAnnotationImpl method drawAnnotation.

@Override
public void drawAnnotation(Graphics g, double x, double y, double scaleFactor) {
    super.drawAnnotation(g, x, y, scaleFactor);
    Graphics2D g2 = (Graphics2D) g;
    // Get the stroke
    int border = (int) Math.round(getBorderWidth() * scaleFactor);
    int width = (int) Math.round(shapeWidth * scaleFactor / getZoom()) - border * 2 + 1;
    int height = (int) Math.round(shapeHeight * scaleFactor / getZoom()) - border * 2 + 1;
    int xInt = (int) Math.round(x * scaleFactor) + border + 1;
    int yInt = (int) Math.round(y * scaleFactor) + border + 1;
    // System.out.println("ImageAnnotationImpl: drawAnnotation - width="+width+", height="+height+", border="+border);
    // System.out.println("ImageAnnotationImpl: drawAnnotation - x="+x+",y="+y+", xInt="+xInt+", yInt="+yInt);
    BufferedImage newImage = resizeImage(width, height);
    if (newImage == null)
        return;
    // boolean selected = isSelected();
    // setSelected(false);
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    g2.setComposite(ac);
    g2.drawImage(newImage, xInt, yInt, null);
// GraphicsUtilities.drawShape(g, 0, 0,
// getWidth()-1, getHeight()-1, this, false);
// setSelected(selected);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Paint(java.awt.Paint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 57 with AlphaComposite

use of java.awt.AlphaComposite in project mage by magefree.

the class MageScrollbarUI method paintTrack.

@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
        int width = trackBounds.width - 4 + ANTI_WIDTH;
        int height = trackBounds.height;
        g2.translate(trackBounds.x + 2, trackBounds.y);
        Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
        g2.setColor(Color.BLACK);
        float alpha = 0.5f;
        Composite composite = g2.getComposite();
        if (composite instanceof AlphaComposite) {
            alpha *= ((AlphaComposite) composite).getAlpha();
        }
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(casing);
        g2.setComposite(composite);
        g2.drawLine(-1, 0, -1, height);
        g2.drawLine(-2, 0, -2, height);
        g2.drawLine(width, 0, width, height);
        g2.drawLine(width + 1, 0, width + 1, height);
        RoundRectangle2D roundCasing = new RoundRectangle2D.Double(0, 2, width, height - 4, width, width);
        Area area = new Area(casing);
        area.subtract(new Area(roundCasing));
        g2.fill(area);
        g2.translate(-trackBounds.x - 2, -trackBounds.y);
    } else {
        int width = trackBounds.width;
        int height = trackBounds.height - 4 + ANTI_WIDTH;
        g2.translate(trackBounds.x, trackBounds.y + 2);
        Rectangle2D casing = new Rectangle2D.Double(0, 0, width, height);
        g2.setColor(Color.BLACK);
        float alpha = 0.5f;
        Composite composite = g2.getComposite();
        if (composite instanceof AlphaComposite) {
            alpha *= ((AlphaComposite) composite).getAlpha();
        }
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(casing);
        g2.setComposite(composite);
        g2.drawLine(0, -1, width, -1);
        g2.drawLine(0, -2, width, -2);
        g2.drawLine(0, height, width, height);
        g2.drawLine(0, height + 1, width, height + 1);
        RoundRectangle2D roundCasing = new RoundRectangle2D.Double(2, 0, width - 4, height, height, height);
        Area area = new Area(casing);
        area.subtract(new Area(roundCasing));
        g2.fill(area);
        g2.translate(-trackBounds.x, -trackBounds.y - 2);
    }
}
Also used : Area(java.awt.geom.Area) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 58 with AlphaComposite

use of java.awt.AlphaComposite in project com.revolsys.open by revolsys.

the class Graphics2DViewRenderer method drawImage.

@Override
public void drawImage(final GeoreferencedImage image, final boolean useTransform, final double alpha, final Object interpolationMethod) {
    if (image != null) {
        final Composite composite = this.graphics.getComposite();
        try {
            AlphaComposite alphaComposite = AlphaComposite.SrcOver;
            if (alpha < 1) {
                alphaComposite = alphaComposite.derive((float) alpha);
            }
            this.graphics.setComposite(alphaComposite);
            drawImage(image, useTransform, interpolationMethod);
        } finally {
            this.graphics.setComposite(composite);
        }
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite)

Example 59 with AlphaComposite

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

the class BaseTitlePane method paintBackground.

/**
 * <p>paintBackground.</p>
 *
 * @param g a {@link java.awt.Graphics} object.
 */
public void paintBackground(Graphics g) {
    if (isActive()) {
        Graphics2D g2D = (Graphics2D) g;
        Composite savedComposite = g2D.getComposite();
        if (backgroundImage != null) {
            g.drawImage(backgroundImage, 0, 0, null);
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaValue);
            g2D.setComposite(alpha);
        }
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowTitleColors(), 0, 0, getWidth(), getHeight());
        g2D.setComposite(savedComposite);
    } else {
        JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors(), 0, 0, getWidth(), getHeight());
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Graphics2D(java.awt.Graphics2D)

Example 60 with AlphaComposite

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

the class XPScrollButton method paint.

/**
 * {@inheritDoc}
 */
@Override
public void paint(final Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Composite savedComposite = g2D.getComposite();
    Paint savedPaint = g2D.getPaint();
    boolean isPressed = getModel().isPressed();
    boolean isRollover = getModel().isRollover();
    int width = getWidth();
    int height = getHeight();
    Color[] tc = AbstractLookAndFeel.getTheme().getThumbColors();
    Color c1 = tc[0];
    Color c2 = tc[tc.length - 1];
    if (isPressed) {
        c1 = ColorHelper.darker(c1, 5);
        c2 = ColorHelper.darker(c2, 5);
    } else if (isRollover) {
        c1 = ColorHelper.brighter(c1, 20);
        c2 = ColorHelper.brighter(c2, 20);
    }
    g2D.setPaint(new GradientPaint(0, 0, c1, width, height, c2));
    g.fillRect(0, 0, width, height);
    g2D.setPaint(savedPaint);
    g.setColor(getFrameColor());
    g.drawLine(1, 1, width - 2, 1);
    g.drawLine(1, 1, 1, height - 3);
    g.drawLine(width - 2, 1, 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);
    g2D.setColor(c2);
    g.drawLine(2, 2, width - 3, 2);
    g.drawLine(2, 3, 2, height - 3);
    g.setColor(ColorHelper.darker(c2, 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);
    g2D.setComposite(savedComposite);
    int x;
    int y;
    Icon icon;
    // paint the icon
    switch(getDirection()) {
        case NORTH:
            icon = getUpArrowIcon();
            x = width / 2 - icon.getIconWidth() / 2;
            y = height / 2 - icon.getIconHeight() / 2;
            break;
        case SOUTH:
            icon = getDownArrowIcon();
            x = width / 2 - icon.getIconWidth() / 2;
            y = height / 2 - icon.getIconHeight() / 2 + 1;
            break;
        case WEST:
            icon = getLeftArrowIcon();
            x = width / 2 - icon.getIconWidth() / 2;
            y = height / 2 - icon.getIconHeight() / 2;
            break;
        default:
            icon = getRightArrowIcon();
            x = width / 2 - icon.getIconWidth() / 2 + 1;
            y = height / 2 - icon.getIconHeight() / 2;
            break;
    }
    icon.paintIcon(this, g, x, y);
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Icon(javax.swing.Icon) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) 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