Example usage for java.awt BasicStroke CAP_SQUARE

List of usage examples for java.awt BasicStroke CAP_SQUARE

Introduction

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

Prototype

int CAP_SQUARE

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

Click Source Link

Document

Ends unclosed subpaths and dash segments with a square projection that extends beyond the end of the segment to a distance equal to half of the line width.

Usage

From source file:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Returns the AWT line cap corresponding to the specified SWT line cap.
 *
 * @param swtLineCap  the SWT line cap./*from   ww  w  . ja v  a  2s  .c  o  m*/
 *
 * @return The AWT line cap.
 */
private int toAwtLineCap(int swtLineCap) {
    if (swtLineCap == SWT.CAP_FLAT) {
        return BasicStroke.CAP_BUTT;
    } else if (swtLineCap == SWT.CAP_ROUND) {
        return BasicStroke.CAP_ROUND;
    } else if (swtLineCap == SWT.CAP_SQUARE) {
        return BasicStroke.CAP_SQUARE;
    } else {
        throw new IllegalArgumentException("SWT LineCap " + swtLineCap + " not recognised");
    }
}

From source file:org.jfree.experimental.swt.SWTGraphics2D.java

/**
 * Returns the SWT line cap corresponding to the specified AWT line cap.
 *
 * @param awtLineCap  the AWT line cap.//ww w  . j a v a 2 s  . c  o m
 *
 * @return The SWT line cap.
 */
private int toSwtLineCap(int awtLineCap) {
    if (awtLineCap == BasicStroke.CAP_BUTT) {
        return SWT.CAP_FLAT;
    } else if (awtLineCap == BasicStroke.CAP_ROUND) {
        return SWT.CAP_ROUND;
    } else if (awtLineCap == BasicStroke.CAP_SQUARE) {
        return SWT.CAP_SQUARE;
    } else {
        throw new IllegalArgumentException("AWT LineCap " + awtLineCap + " not recognised");
    }
}

From source file:eu.udig.style.advanced.utils.Utilities.java

/**
 * Convert a sld line cap definition to the java awt value. 
 * //from w w  w . jav a2 s.com
 * @param sldCap the sld cap string.
 * @return the awt value.
 */
public static int sld2awtCap(String sldCap) {
    if (sldCap.equals("") || sldCap.equals(lineCapNames[1])) {
        return BasicStroke.CAP_BUTT;
    } else if (sldCap.equals(lineCapNames[2])) {
        return BasicStroke.CAP_ROUND;
    } else if (sldCap.equals(lineCapNames[3])) {
        return BasicStroke.CAP_SQUARE;
    } else {
        throw new IllegalArgumentException("unsupported line cap");
    }
}

From source file:spinworld.gui.RadarPlot.java

/**
 * Draws a radar plot polygon./*from  w ww .  j a va2 s  .co m*/
 *
 * @param g2 the graphics device.
 * @param plotArea the area we are plotting in (already adjusted).
 * @param centre the centre point of the radar axes
 * @param info chart rendering info.
 * @param series the series within the dataset we are plotting
 * @param catCount the number of categories per radar plot
 * @param headH the data point height
 * @param headW the data point width
 */
protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info,
        int series, int catCount, double headH, double headW) {

    Polygon polygon = new Polygon();

    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    // plot the data...
    for (int cat = 0; cat < catCount; cat++) {

        Number dataValue = getPlotValue(series, cat);

        if (dataValue != null) {
            double value = dataValue.doubleValue();

            // Finds our starting angle from the centre for this axis

            double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount);

            // The following angle calc will ensure there isn't a top
            // vertical axis - this may be useful if you don't want any
            // given criteria to 'appear' move important than the
            // others..
            //  + (getDirection().getFactor()
            //        * (cat + 0.5) * 360 / catCount);

            // find the point at the appropriate distance end point
            // along the axis/angle identified above and add it to the
            // polygon

            double _maxValue = getMaxValue(cat).doubleValue();
            double _origin = getOrigin(cat).doubleValue();
            double lowerBound = Math.min(_origin, _maxValue);
            double upperBound = Math.max(_origin, _maxValue);
            boolean lesser = value < lowerBound;
            boolean greater = value > upperBound;
            if ((lesser || greater) && !drawOutOfRangePoints) {
                continue;
            }
            if (lesser) {
                value = lowerBound;
            }
            if (greater) {
                value = upperBound;
            }
            double length = _maxValue == _origin ? 0 : (value - lowerBound) / (upperBound - lowerBound);
            if (_maxValue < _origin) { // inversed
                length = 1 - length;
            }
            Point2D point = getWebPoint(plotArea, angle, length);
            polygon.addPoint((int) point.getX(), (int) point.getY());

            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);

            double px = point.getX();
            double py = point.getY();
            g2.setPaint(paint);
            if (lesser || greater) {
                // user crosshair for out-of-range data points distinguish
                g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL));
                double delta = 3;
                g2.draw(new Line2D.Double(px - delta, py, px + delta, py));
                g2.draw(new Line2D.Double(px, py - delta, px, py + delta));
            } else {
                // put an elipse at the point being plotted..
                Ellipse2D head = new Ellipse2D.Double(px - headW / 2, py - headH / 2, headW, headH);
                g2.fill(head);
                g2.setStroke(getHeadOutlineStroke(series));
                g2.setPaint(outlinePaint);
                g2.draw(head);
            }

            if (entities != null) {
                int row = 0;
                int col = 0;
                if (this.dataExtractOrder == TableOrder.BY_ROW) {
                    row = series;
                    col = cat;
                } else {
                    row = cat;
                    col = series;
                }
                String tip = null;
                if (this.toolTipGenerator != null) {
                    tip = this.toolTipGenerator.generateToolTip(this.dataset, row, col);
                }

                String url = null;
                if (this.urlGenerator != null) {
                    url = this.urlGenerator.generateURL(this.dataset, row, col);
                }

                Shape area = new Rectangle((int) (point.getX() - headW), (int) (point.getY() - headH),
                        (int) (headW * 2), (int) (headH * 2));
                CategoryItemEntity entity = new CategoryItemEntity(area, tip, url, this.dataset,
                        this.dataset.getRowKey(row), this.dataset.getColumnKey(col));
                entities.add(entity);
            }
        }
    }
    // Plot the polygon

    Paint paint = getSeriesPaint(series);
    g2.setPaint(paint);
    g2.setStroke(getSeriesOutlineStroke(series));
    g2.draw(polygon);

    // Lastly, fill the web polygon if this is required

    if (this.webFilled) {
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        g2.fill(polygon);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    }
}

From source file:net.sqs2.omr.session.logic.PageImageRenderer.java

private static void drawFormAreas(int pageIndex, float densityThreshold, FormMaster master,
        PageTaskResult pageTaskResult, Graphics2D g, MarkRecognitionConfig markRecognizationConfig,
        DeskewedImageSource pageSource, int focusedColumnIndex, Rectangle scope) {
    int formAreaIndexInPage = 0;

    int minX = Integer.MAX_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int maxY = Integer.MIN_VALUE;

    for (FormArea formArea : master.getFormAreaListByPageIndex(pageIndex)) {
        FormAreaResult result = (FormAreaResult) pageTaskResult.getPageAreaResultList()
                .get(formAreaIndexInPage);
        if (formArea.isMarkArea()) {
            if (focusedColumnIndex == formArea.getQuestionIndex()) {

                Rectangle rect = formArea.getRect();

                Point2D p1 = pageSource.getPoint((int) rect.getX(), (int) rect.getY());
                Point2D p2 = pageSource.getPoint((int) (rect.getX() + rect.getWidth()),
                        (int) (rect.getY() + rect.getHeight()));

                minX = Math.min(minX, (int) p1.getX());
                minY = Math.min(minY, (int) p1.getY());
                maxX = Math.max(maxX, (int) p2.getX());
                maxY = Math.max(maxY, (int) p2.getY());

                if (result.getDensity() < densityThreshold) {
                    g.setColor(FOCUSED_MARKED_COLOR);
                } else {
                    g.setColor(FOCUSED_NO_MARKED_COLOR);
                }//w ww . jav  a  2s  .c o m

            } else {
                if (result.getDensity() < densityThreshold) {
                    g.setColor(MARKED_COLOR);
                } else {
                    g.setColor(NO_MARKED_COLOR);
                }
            }

            g.fillPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin(),
                            markRecognizationConfig.getVerticalMargin())));
            g.drawPolygon(pageSource.createRectPolygon(
                    getExtendedRectangle(formArea.getRect(), markRecognizationConfig.getHorizontalMargin() + 3,
                            markRecognizationConfig.getVerticalMargin() + 3)));

        } else {
            g.setColor(TEXTAREA_COLOR);
            g.fillPolygon(pageSource.createRectPolygon(formArea.getRect()));
        }
        formAreaIndexInPage++;
    }

    if (scope != null) {
        int borderMarginX = 20;
        int borderMarginY = 3;
        int margin = 40;

        int x = minX - borderMarginX;
        int y = minY - borderMarginY;
        int width = maxX - minX + borderMarginX * 2;
        int height = maxY - minY + borderMarginY * 2;

        scope.x = minX - margin;
        scope.y = minY - margin;
        scope.width = maxX - minX + margin * 2;
        scope.height = maxY - minY + margin * 2;

        Stroke stroke = new BasicStroke(4.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 2.0f,
                new float[] { 4.0f, 8.0f }, 0.0f);
        g.setStroke(stroke);
        g.setColor(FOCUSED_SCOPE_COLOR);
        g.drawRoundRect(x, y, width, height, 20, 20);
    }

}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

/**
 * Reusable 'strokes' for rendering lines may be obtained from here
 * //w  w w  . j  a  v a 2s  . com
 * @param ls
 * @return stroke
 */
public final Stroke getCachedStroke(LineAttributes lia) {
    if (lia == null)
        return null;

    Stroke s = _htLineStyles.get(lia);
    if (s == null) {
        BasicStroke bs = null;
        int thickness = lia.getThickness();
        if (thickness == 0) {
            // Thickness can be zero, but dashed pattern can not be.
            thickness = 1;
        }
        if (lia.getStyle().getValue() == LineStyle.DASHED) {
            float[] faStyle = new float[] { 6 * thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.DOTTED) {
            float[] faStyle = new float[] { thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.DASH_DOTTED) {
            float[] faStyle = new float[] { 6 * thickness, 4 * thickness, thickness, 4 * thickness };
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, faStyle,
                    0);
        } else if (lia.getStyle().getValue() == LineStyle.SOLID) {
            bs = new BasicStroke(lia.getThickness(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);
        }
        if (bs != null) {
            _htLineStyles.put(lia, bs);
        }
        return bs;
    }
    return s;
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

/**
 * Adds stroke color and style information to the element passed in.
 * //ww w.  j a  va2  s  .c o  m
 * @param currentElement
 *            the element to add style information to.
 * @param isClipped
 *            boolean that determines whether to defer the clipping of the
 *            element
 */
protected void setStrokeStyle(Element currentElement, boolean deferClipped)

{
    Element element = currentElement;
    if (deferStrokColor != null) {
        // Need to get the parent element.
        element = deferStrokColor;
    }

    String style = element.getAttribute("style"); //$NON-NLS-1$
    if (style == null)
        style = ""; //$NON-NLS-1$
    if (color != null) {
        style += "stroke:" + serializeToString(color) + ";"; //$NON-NLS-1$ //$NON-NLS-2$
    }
    if ((stroke != null) && (stroke instanceof BasicStroke)) {
        BasicStroke bs = (BasicStroke) stroke;
        if (bs.getLineWidth() > 0)
            style += "stroke-width:" + bs.getLineWidth() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        if (bs.getDashArray() != null) {
            StringBuffer dashArrayStr = new StringBuffer();
            for (int x = 0; x < bs.getDashArray().length; x++) {
                dashArrayStr.append(" ").append(bs.getDashArray()[x]); //$NON-NLS-1$
            }
            if (!(dashArrayStr.toString().equals(""))) //$NON-NLS-1$
                style += "stroke-dasharray:" + dashArrayStr + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        }
        style += "stroke-miterlimit:" + bs.getMiterLimit() + ";"; //$NON-NLS-1$ //$NON-NLS-2$
        switch (bs.getLineJoin()) {
        case BasicStroke.JOIN_BEVEL:
            style += "stroke-linejoin:bevel;"; //$NON-NLS-1$
            break;
        case BasicStroke.JOIN_ROUND:
            style += "stroke-linejoin:round;"; //$NON-NLS-1$
            break;
        }
        switch (bs.getEndCap()) {
        case BasicStroke.CAP_ROUND:
            style += "stroke-linecap:round;"; //$NON-NLS-1$
            break;
        case BasicStroke.CAP_SQUARE:
            style += "stroke-linecap:square;"; //$NON-NLS-1$
            break;
        }

    }
    element.setAttribute("style", style); //$NON-NLS-1$
    if (styleClass != null)
        element.setAttribute("class", styleClass); //$NON-NLS-1$
    if (id != null)
        element.setAttribute("id", id); //$NON-NLS-1$
    if ((clip != null) && (!deferClipped))
        element.setAttribute("clip-path", "url(#clip" + clip.hashCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

private void setStrokeDiff(final Stroke newStroke, final Stroke oldStroke) {
    if (newStroke == oldStroke) {
        return;/*from ww  w .j a v  a  2  s. co m*/
    }
    if (!(newStroke instanceof BasicStroke)) {
        return;
    }
    final BasicStroke nStroke = (BasicStroke) newStroke;
    final boolean oldOk = (oldStroke instanceof BasicStroke);
    BasicStroke oStroke = null;
    if (oldOk) {
        oStroke = (BasicStroke) oldStroke;
    }
    if (!oldOk || nStroke.getLineWidth() != oStroke.getLineWidth()) {
        cb.setLineWidth(nStroke.getLineWidth());
    }
    if (!oldOk || nStroke.getEndCap() != oStroke.getEndCap()) {
        switch (nStroke.getEndCap()) {
        case BasicStroke.CAP_BUTT:
            cb.setLineCap(0);
            break;
        case BasicStroke.CAP_SQUARE:
            cb.setLineCap(2);
            break;
        default:
            cb.setLineCap(1);
        }
    }
    if (!oldOk || nStroke.getLineJoin() != oStroke.getLineJoin()) {
        switch (nStroke.getLineJoin()) {
        case BasicStroke.JOIN_MITER:
            cb.setLineJoin(0);
            break;
        case BasicStroke.JOIN_BEVEL:
            cb.setLineJoin(2);
            break;
        default:
            cb.setLineJoin(1);
        }
    }
    if (!oldOk || nStroke.getMiterLimit() != oStroke.getMiterLimit()) {
        cb.setMiterLimit(nStroke.getMiterLimit());
    }
    final boolean makeDash;
    if (oldOk) {
        if (nStroke.getDashArray() != null) {
            if (nStroke.getDashPhase() != oStroke.getDashPhase()) {
                makeDash = true;
            } else if (!Arrays.equals(nStroke.getDashArray(), oStroke.getDashArray())) {
                makeDash = true;
            } else {
                makeDash = false;
            }
        } else if (oStroke.getDashArray() != null) {
            makeDash = true;
        } else {
            makeDash = false;
        }
    } else {
        makeDash = true;
    }
    if (makeDash) {
        final float[] dash = nStroke.getDashArray();
        if (dash == null) {
            cb.setLiteral("[]0 d\n");
        } else {
            cb.setLiteral('[');
            final int lim = dash.length;
            for (int k = 0; k < lim; ++k) {
                cb.setLiteral(dash[k]);
                cb.setLiteral(' ');
            }
            cb.setLiteral(']');
            cb.setLiteral(nStroke.getDashPhase());
            cb.setLiteral(" d\n");
        }
    }
}

From source file:org.uva.itast.blended.omr.OMRUtils.java

public static void logFrame(PageImage pageImage, PagePoint topleft, PagePoint topright, PagePoint bottomleft,
        PagePoint bottomright, Color color, String label) {
    if (topleft == null || topright == null || bottomleft == null || bottomright == null)
        return;//from   www.  j ava2s.c  om

    Graphics2D g = pageImage.getReportingGraphics();
    AffineTransform t = g.getTransform();
    g.setColor(color);
    g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
            new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));

    // Point framePxUL=pageImage.toPixels(topleft.getX(), topleft.getY());
    // Point framePxUR=pageImage.toPixels(topright.getX(), topright.getY());
    // Point framePxBL=pageImage.toPixels(bottomleft.getX(),
    // bottomleft.getY());
    // Point framePxBR=pageImage.toPixels(bottomright.getX(),
    // bottomright.getY());

    g.drawLine(topleft.getXpx(), topleft.getYpx(), topright.getXpx(), topright.getYpx());
    g.drawLine(topleft.getXpx(), topleft.getYpx(), bottomleft.getXpx(), bottomleft.getYpx());
    g.drawLine(topright.getXpx(), topright.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    g.drawLine(bottomleft.getXpx(), bottomleft.getYpx(), bottomright.getXpx(), bottomright.getYpx());
    if (label != null) {
        g.drawString(label, topleft.getXpx(), topleft.getYpx());
    }
}

From source file:org.uva.itast.blended.omr.scanners.BarcodeScanner.java

/**
 * @param campo//from w ww.  j a  v  a 2  s  .c o  m
 */
public void markBarcode(Field campo) {
    try {
        //get bbox in pixels
        Rectangle rect = pageImage.toPixels(campo.getBBox());
        // expand the area for some tolerance
        Rectangle2D expandedArea = getExpandedArea(campo.getBBox(), (float) BARCODE_AREA_PERCENT);
        Rectangle expandedRect = pageImage.toPixels(expandedArea);

        Graphics2D g = pageImage.getReportingGraphics();
        AffineTransform t = g.getTransform();
        g.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1,
                new float[] { (float) (3 / t.getScaleX()), (float) (6 / t.getScaleY()) }, 0));
        if (lastResult != null)
            g.setColor(Color.BLUE);
        else
            g.setColor(Color.RED);

        g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 3, 3);
        g.drawRoundRect(expandedRect.x, expandedRect.y, expandedRect.width, expandedRect.height, 3, 3);

        g.setFont(new Font("Arial", Font.BOLD, (int) (12 / t.getScaleX())));
        String message;
        if (lastResult != null)
            message = ((Result) lastResult.getResult()).getBarcodeFormat().toString() + "="
                    + getParsedCode(lastResult);
        else
            message = "UNRECOGNIZED!";
        g.drawString(message, rect.x, rect.y);

    } catch (Exception e) {
        logger.error("Unexpected errr while logging the image:", e);
    }

}