Search in sources :

Example 41 with Composite

use of java.awt.Composite in project chordatlas by twak.

the class MiniFacade method paint.

@Override
public void paint(Graphics2D g, PanMouseAdaptor ma) {
    if (PAINT_IMAGE && imageFeatures != null) {
        Composite oldC = g.getComposite();
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
        paintImage(g, ma, left, -height, left + width, 0);
        g.setComposite(oldC);
    }
    g.setStroke(new BasicStroke(2f));
    if (width < 5)
        return;
    for (Feature f : Feature.values()) if (f != Feature.GRID)
        for (FRect w : rects.get(f)) {
            if (w.outer == null) {
                g.setColor(f.color);
                // if (w.width < 10)
                g.drawRect(ma.toX(w.x), ma.toY(-w.y - w.height), ma.toZoom(w.width), ma.toZoom(w.height));
                g.setColor(Color.black);
                if (w.id >= 0)
                    g.drawString(w.id + "", ma.toX(w.x) + 3, ma.toY(-w.y - w.height) + 13);
            // try {
            // g.drawString(
            // w.attachedHeight.get( Feature.CORNICE ).d +", " +
            // w.attachedHeight.get( Feature.BALCONY ).d +", "+
            // w.attachedHeight.get( Feature.SILL ).d + ", ",
            // ma.toX( w.x ) + 3, ma.toY( -w.y - w.height ) + 13  );
            // } catch (NullPointerException e) {}
            }
            for (Dir dir : Dir.values()) {
                FRect n = w.getAdj(dir);
                if (n != null) {
                    g.setColor(Rainbow.getColour(dir.ordinal()));
                    Point2d s = getRectPoint(w, dir), e = getRectPoint(n, dir.opposite);
                    s.y = -s.y;
                    e.y = -e.y;
                    Line l = new Line(s, e);
                    PaintThing.paint(l, g, ma);
                    PaintThing.drawArrow(g, ma, l, 3);
                // if ( dir == Dir.L || dir == Dir.U ) {
                // Point2d label = l.fromPPram( 0.5 );
                // g.drawString( w.distanceToAdjacent( dir ) + "", ma.toX( label.x ), ma.toY( label.y ) );
                // }
                }
            }
        }
    if (false && grid != null) {
        g.setColor(new Color(100, 100, 255, 200));
        // for ( DRectangle w : grid.dows )
        // g.fillRect( ma.toX( w.x ), ma.toY( -w.y - w.height ), ma.toZoom( w.width ), ma.toZoom( w.height ) );
        g.setColor(new Color(100, 255, 10, 200));
        if (false)
            for (int x = 0; x < grid.cols; x++) for (int y = 0; y < grid.rows; y++) {
                g.fillRect(ma.toX(x * grid.hspacing + grid.x), ma.toY(-y * grid.vspacing - grid.wHeight - grid.y), ma.toZoom(grid.wWidth), ma.toZoom(grid.wHeight));
            }
    }
    g.setColor(Color.black);
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left + width), ma.toY(0));
    g.setColor(Color.green);
    g.setColor(new Color(0, 170, 255));
    g.setStroke(new BasicStroke(softLeft ? 1 : 3));
    g.drawLine(ma.toX(left), ma.toY(0), ma.toX(left), ma.toY(-height));
    g.setStroke(new BasicStroke(softRight ? 1 : 3));
    g.drawLine(ma.toX(left + width), ma.toY(0), ma.toX(left + width), ma.toY(-height));
    g.setColor(Color.black);
    g.setStroke(new BasicStroke(1));
    g.drawLine(ma.toX(left), ma.toY(-height), ma.toX(left + width), ma.toY(-height));
    g.drawLine(ma.toX(left), ma.toY(-groundFloorHeight), ma.toX(left + width), ma.toY(-groundFloorHeight));
}
Also used : BasicStroke(java.awt.BasicStroke) Line(org.twak.utils.Line) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Point2d(javax.vecmath.Point2d) Color(java.awt.Color) ICanPaint(org.twak.utils.PaintThing.ICanPaint)

Example 42 with Composite

use of java.awt.Composite in project WorldPainter by Captain-Chaos.

the class WPTileSelectionViewer method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    super.paintComponent(g2);
    if (!selectedTiles.isEmpty()) {
        g2.setColor(Color.YELLOW);
        Composite previousComposite = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
        try {
            Rectangle clipBounds = g2.getClipBounds();
            for (Point selectedTile : selectedTiles) {
                Rectangle tileBounds = getTileBounds(selectedTile.x, selectedTile.y);
                if (tileBounds.intersects(clipBounds)) {
                    g2.fillRect(tileBounds.x, tileBounds.y, tileBounds.width, tileBounds.height);
                }
            }
        } finally {
            g2.setComposite(previousComposite);
        }
    }
    if ((selectedRectangleCorner1 != null) && (selectedRectangleCorner2 != null)) {
        g2.setColor(Color.CYAN);
        Rectangle rectangleBounds = getTileRectangleCoordinates(selectedRectangleCorner1, selectedRectangleCorner2);
        g2.drawRect(rectangleBounds.x, rectangleBounds.y, rectangleBounds.width - 1, rectangleBounds.height - 1);
    }
    if (highlightedTileLocation != null) {
        Rectangle rect = getTileBounds(highlightedTileLocation.x, highlightedTileLocation.y);
        g2.setColor(Color.RED);
        g2.drawRect(rect.x, rect.y, rect.width - 1, rect.height - 1);
    }
    int zoom = getZoom();
    g2.drawImage(SCALE_BAR, 10, getHeight() - 10 - SCALE_BAR.getHeight(), this);
    g2.setColor(Color.BLACK);
    String str = ((zoom < 0) ? (100 << -zoom) : (100 >> zoom)) + " blocks";
    g2.drawString(str, 15 + SCALE_BAR.getWidth() + 1, getHeight() - 9);
    g2.setColor(Color.WHITE);
    g2.drawString(str, 15 + SCALE_BAR.getWidth(), getHeight() - 10);
    int middleX = getWidth() / 2;
    int middleY = getHeight() / 2;
    g2.setColor(Color.BLACK);
    str = getViewX() + ", " + getViewY();
    g2.drawString(str, middleX + 3, middleY - 1);
    g2.setColor(Color.WHITE);
    g2.drawString(str, middleX + 2, middleY - 2);
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 43 with Composite

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

the class GeoreferencedImageLayerRenderer method renderAlpha.

public static void renderAlpha(final Viewport2D viewport, final Graphics2D graphics, final GeoreferencedImage image, final boolean useTransform, final double alpha, Object interpolationMethod) {
    final Composite composite = graphics.getComposite();
    try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, false)) {
        AlphaComposite alphaComposite = AlphaComposite.SrcOver;
        if (alpha < 1) {
            alphaComposite = alphaComposite.derive((float) alpha);
        }
        graphics.setComposite(alphaComposite);
        render(viewport, graphics, image, useTransform, interpolationMethod);
    } finally {
        graphics.setComposite(composite);
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) AlphaComposite(java.awt.AlphaComposite)

Example 44 with Composite

use of java.awt.Composite in project JSettlers2 by jdmonin.

the class SOCBoardPanel method drawBoard_SC_FTRI_placePort.

/**
 * Scenario game option {@link SOCGameOptionSet#K_SC_FTRI _SC_FTRI}: In board mode {@link #SC_FTRI_PLACE_PORT},
 * draw the possible coastal edges where the port can be placed, and if the {@link #hilight} cursor is at
 * such an edge, draw the port semi-transparently and a solid hilight line at the edge.
 * @since 2.0.00
 */
private final void drawBoard_SC_FTRI_placePort(Graphics g) {
    drawSeaEdgeLines(g, Color.WHITE, player.getPortMovePotentialLocations(true));
    if (hilight == 0)
        return;
    // Draw the placing port semi-transparently if graphics support it.
    // Draw hilight line with some thickness if possible.
    int edge = hilight;
    if (edge == -1)
        edge = 0;
    final SOCInventoryItem portItem = game.getPlacingItem();
    if (portItem != null) {
        // draw the port; similar code to drawPorts_largeBoard
        final int landFacing = ((SOCBoardLarge) board).getPortFacingFromEdge(edge);
        final int landHexCoord = board.getAdjacentHexToEdge(edge, landFacing);
        int px = halfdeltaX * ((landHexCoord & 0xFF) - 1);
        int py = halfdeltaY * (landHexCoord >> 8);
        // now move 1 hex "backwards" from that hex's upper-left corner
        px -= DELTAX_FACING[landFacing];
        py -= DELTAY_FACING[landFacing];
        final Composite prevComposite;
        if (g instanceof Graphics2D) {
            prevComposite = ((Graphics2D) g).getComposite();
            ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
        } else {
            prevComposite = null;
        }
        drawHex(g, px, py, -portItem.itype, landFacing, -1);
        if (prevComposite != null)
            ((Graphics2D) g).setComposite(prevComposite);
    }
    final Stroke prevStroke;
    if (g instanceof Graphics2D) {
        prevStroke = ((Graphics2D) g).getStroke();
        ((Graphics2D) g).setStroke(new BasicStroke(2.5f));
    } else {
        prevStroke = null;
    }
    g.setColor(Color.WHITE);
    drawSeaEdgeLine(g, edge);
    if (prevStroke != null)
        ((Graphics2D) g).setStroke(prevStroke);
}
Also used : BasicStroke(java.awt.BasicStroke) SOCBoardLarge(soc.game.SOCBoardLarge) SOCInventoryItem(soc.game.SOCInventoryItem) BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Graphics2D(java.awt.Graphics2D)

Example 45 with Composite

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

the class ArbitraryGraphicsCanvas method clearImage.

/**
 * Utility function to clean the background of the image,
 * using m_backgroundColor
 *
 * image2D Graphics2D
 */
private void clearImage(Graphics2D image2D) {
    if (img != null) {
        // set color alpha based on opacity setting
        int alpha = (m_isOpaque) ? 255 : 0;
        Color backgroundColor = new Color(m_backgroundColor.getRed(), m_backgroundColor.getGreen(), m_backgroundColor.getBlue(), alpha);
        // set the alpha composite on the image, and clear its area
        Composite origComposite = image2D.getComposite();
        image2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
        image2D.setPaint(backgroundColor);
        image2D.fillRect(0, 0, img.getWidth(null), img.getHeight(null));
        image2D.setComposite(origComposite);
    }
}
Also used : Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Color(java.awt.Color) Point(java.awt.Point)

Aggregations

Composite (java.awt.Composite)294 AlphaComposite (java.awt.AlphaComposite)279 Graphics2D (java.awt.Graphics2D)134 Paint (java.awt.Paint)103 Rectangle2D (java.awt.geom.Rectangle2D)103 Color (java.awt.Color)81 Shape (java.awt.Shape)80 BasicStroke (java.awt.BasicStroke)55 Stroke (java.awt.Stroke)52 BufferedImage (java.awt.image.BufferedImage)51 AffineTransform (java.awt.geom.AffineTransform)39 Line2D (java.awt.geom.Line2D)38 Point (java.awt.Point)36 Rectangle (java.awt.Rectangle)36 Font (java.awt.Font)33 Point2D (java.awt.geom.Point2D)31 GradientPaint (java.awt.GradientPaint)27 Iterator (java.util.Iterator)26 PlotOrientation (org.jfree.chart.plot.PlotOrientation)25 GeneralPath (java.awt.geom.GeneralPath)24