Example usage for java.awt BasicStroke getLineJoin

List of usage examples for java.awt BasicStroke getLineJoin

Introduction

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

Prototype

public int getLineJoin() 

Source Link

Document

Returns the line join style.

Usage

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

private void updateGraph() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Collection<Stairs> loadProfileEnities = transform(
            filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()),
            new LoadProfileEntityToStairsFunction());
    GraphPointsCalculator calc = new GraphPointsCalculator();
    Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities);

    for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) {
        final XYSeries series = new XYSeries(entry.getKey());
        for (Point point : entry.getValue()) {
            series.add(point.getX(), point.getY());
        }/*w w  w  . ja v a  2  s  .  com*/
        dataset.addSeries(series);
    }

    String name = txtName.getText();
    chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    double maxX = 0;

    for (OneTime oneTime : getOneTimes()) {
        String key = oneTime.operation.getName();
        XYSeries series;
        try {
            // We need the series in order to retrieve paint and stroke
            series = dataset.getSeries(key);
        } catch (UnknownKeyException ex) {
            series = new XYSeries(key);
            dataset.addSeries(series);
        }

        int index = dataset.getSeriesIndex(key);
        BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index);
        stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(),
                stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase());
        Color paint = (Color) renderer.lookupSeriesPaint(index);
        paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160);

        double height = rangeAxis.getUpperBound() * .05; // five percent of range
        double width = domainAxis.getUpperBound() * .01; // one percent of range
        double center = oneTime.t0;
        double left = center - width / 2;
        double right = center + width / 2;

        // We only add annotations for one times, but nothing to the series
        plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke,
                paint, paint));

        maxX = max(maxX, right);
    }

    for (Marker marker : getMarkers()) {
        IntervalMarker im = new IntervalMarker(marker.left, marker.right);
        im.setLabel(marker.name);
        im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1));
        im.setLabelAnchor(RectangleAnchor.TOP);
        im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
        im.setLabelPaint(Color.BLACK);
        im.setAlpha(.3f);
        im.setPaint(Color.WHITE);
        im.setOutlinePaint(Color.BLACK);
        im.setOutlineStroke(new BasicStroke(1.0f));
        plot.addDomainMarker(im, Layer.BACKGROUND);

        maxX = max(maxX, marker.right);
    }

    if (domainAxis.getUpperBound() < maxX) {
        domainAxis.setUpperBound(maxX * 1.05);
    }
    chartPanel.setChart(chart);
}

From source file:org.apache.pdfbox.util.operator.pagedrawer.StrokePath.java

/**
 * S stroke the path.//from ww w.  j a v a 2 s.  com
 * @param operator The operator that is being executed.
 * @param arguments List
 *
 * @throws IOException If an error occurs while processing the font.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    ///dwilson 3/19/07 refactor
    try {
        PageDrawer drawer = (PageDrawer) context;

        float lineWidth = (float) context.getGraphicsState().getLineWidth();
        Matrix ctm = context.getGraphicsState().getCurrentTransformationMatrix();
        if (ctm != null && ctm.getXScale() > 0) {
            lineWidth = lineWidth * ctm.getXScale();
        }

        BasicStroke stroke = (BasicStroke) drawer.getStroke();
        if (stroke == null) {
            drawer.setStroke(new BasicStroke(lineWidth));
        } else {
            drawer.setStroke(new BasicStroke(lineWidth, stroke.getEndCap(), stroke.getLineJoin(),
                    stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase()));
        }
        drawer.strokePath();
    } catch (Exception exception) {
        log.warn(exception, exception);
    }
}

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

/**
 * Adds stroke color and style information to the element passed in.
 * /* www. ja va2 s  . co  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 Stroke transformStroke(final Stroke stroke) {
    if (!(stroke instanceof BasicStroke)) {
        return stroke;
    }//  w w w .j  av a  2 s .  c o  m
    final BasicStroke st = (BasicStroke) stroke;
    final float scale = (float) Math.sqrt(Math.abs(transform.getDeterminant()));
    final float[] dash = st.getDashArray();
    if (dash != null) {
        final int dashLength = dash.length;
        for (int k = 0; k < dashLength; ++k) {
            dash[k] *= scale;
        }
    }
    return new BasicStroke(st.getLineWidth() * scale, st.getEndCap(), st.getLineJoin(), st.getMiterLimit(),
            dash, st.getDashPhase() * scale);
}

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 w  w 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");
        }
    }
}