Example usage for java.awt BasicStroke CAP_ROUND

List of usage examples for java.awt BasicStroke CAP_ROUND

Introduction

In this page you can find the example usage for java.awt BasicStroke CAP_ROUND.

Prototype

int CAP_ROUND

To view the source code for java.awt BasicStroke CAP_ROUND.

Click Source Link

Document

Ends unclosed subpaths and dash segments with a round decoration that has a radius equal to half of the width of the pen.

Usage

From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java

private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) {
    //      log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint);

    final int fromX = sourcePoint.x;
    final int fromY = sourcePoint.y;
    final int toX = sinkPoint.x;
    final int toY = sinkPoint.y;

    float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f;
    f1 = fromX;//from ww  w.  java2 s  .  co m
    f2 = fromY;
    f3 = fromX;
    f4 = fromY + WIRE_DIP_PIXELS;
    f5 = toX;
    f6 = toY + WIRE_DIP_PIXELS;
    f7 = toX;
    f8 = toY;
    final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);
    final Rectangle cubicCurveBounds = cubicCurve.getBounds();

    final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS;
    //      int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS;
    int imageHeightToUse = cubicCurveBounds.height;
    // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip"
    if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) {
        imageHeightToUse += (WIRE_DIP_PIXELS / 2);
    }

    //      bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB );
    try {
        tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource,
                allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB,
                imageWidthToUse, imageHeightToUse);

        bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage();
        final Graphics2D g2d = bufferedImage.createGraphics();

        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse);

        g2d.setComposite(AlphaComposite.SrcOver);

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;

        final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);

        // Draw the highlight and shadow
        if (DRAW_HIGHTLIGHT_AND_SHADOW) {
            final Graphics2D sG2d = (Graphics2D) g2d.create();
            sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET);
            sG2d.setColor(Color.BLUE.darker());
            sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            sG2d.draw(offSetCubicCurve);

            final Graphics2D hG2d = (Graphics2D) g2d.create();
            hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET);
            hG2d.setColor(Color.WHITE);
            hG2d.setStroke(
                    new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            hG2d.draw(offSetCubicCurve);
        }

        g2d.setColor(Color.BLACK);
        g2d.setStroke(wireStroke);
        g2d.draw(offSetCubicCurve);

        g2d.setColor(Color.BLUE);
        g2d.setStroke(wireBodyStroke);
        g2d.draw(offSetCubicCurve);

        // For debugging, draw a green line around the outside of this image.
        if (DRAW_WIRE_BOUNDING_BOX) {
            g2d.setStroke(basicStrokeOfOne);
            g2d.setColor(Color.GREEN);
            g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1);
        }

        rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.width = imageWidthToUse;
        rectangle.height = imageHeightToUse;
    } catch (final Exception e) {
        final String msg = "Exception caught allocating buffered image: " + e.toString();
        log.error(msg, e);
    }
}

From source file:VASSAL.build.module.map.MapShader.java

protected void buildStroke(double zoom) {
    stroke = new BasicStroke((float) Math.min(borderWidth * zoom, 1.0), BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND);
}