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.jstockchart.plot.TimeseriesPlot.java

private XYPlot createVolumePlot() {
    Font axisFont = new Font("Arial", 0, 12);
    Stroke stroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    VolumeArea volumeArea = timeseriesArea.getVolumeArea();
    LogicNumberAxis logicVolumeAxis = volumeArea.getLogicVolumeAxis();
    Color volumeColor = new Color(86, 126, 160);
    volumeArea.setVolumeColor(volumeColor);
    CFXNumberAxis volumeAxis = new CFXNumberAxis(logicVolumeAxis.getLogicTicks());
    volumeAxis.setAxisLineVisible(false);
    volumeAxis.setCustomTickCount(2);/*w ww .  j  av a  2s . c o  m*/
    volumeAxis.setTickLabelPaint(volumeColor);
    volumeAxis.setUpperBound(logicVolumeAxis.getUpperBound());
    volumeAxis.setTickLabelFont(axisFont);
    volumeAxis.setTickMarkStroke(stroke);
    volumeAxis.setLowerBound(logicVolumeAxis.getLowerBound());
    volumeAxis.setAutoRangeIncludesZero(true);
    XYAreaRenderer2 volumeRenderer = new XYAreaRenderer2();
    volumeRenderer.setSeriesPaint(0, volumeArea.getVolumeColor());
    //volumeRenderer.setShadowVisible(false);
    volumeRenderer.setSeriesStroke(0, stroke);
    volumeRenderer.setBaseStroke(stroke);
    XYPlot plot = new XYPlot(new TimeSeriesCollection(dataset.getVolumeTimeSeries()), null, volumeAxis,
            volumeRenderer);
    plot.setBackgroundPaint(volumeArea.getBackgroudColor());
    plot.setOrientation(volumeArea.getOrientation());
    plot.setRangeAxisLocation(volumeArea.getVolumeAxisLocation());
    plot.setRangeMinorGridlinesVisible(false);

    Stroke outLineStroke = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.CAP_SQUARE, 0.0f,
            new float[] { 1.0f, 1.0f }, 1.0f);
    Stroke gridLineStroke = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
            new float[] { 2.0f, 2.0f }, 1.0f);
    // plot.setBackgroundPaint(Color.RED);
    plot.setRangeGridlineStroke(gridLineStroke);
    plot.setDomainGridlineStroke(gridLineStroke);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setOutlineVisible(true);
    plot.setOutlineStroke(outLineStroke);
    plot.setOutlinePaint(Color.black);
    plot.setRangeZeroBaselineVisible(true);
    return plot;
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private XYItemRenderer getLineRenderer() throws KeyedException {
    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setDrawSeriesLineAsPath(true);
    lineRenderer.setSeriesStroke(0,//from www .  j a  va2s.co m
            new BasicStroke(getStrokeWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
    lineRenderer.setBaseShapesVisible(false);
    return lineRenderer;
}

From source file:Applet.EmbeddedChart.java

/**
 * Creates a chart.//from   w  ww. jav a 2  s.c o m
 * 
 * @param dataset
 *            the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset, String title, boolean gofr) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart
            // title
            "Radial Distance,  r/\u03c3", // x axis label
            title, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);

    // final StandardLegend legend = (StandardLegend) chart.getLegend();
    // legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    XYTitleAnnotation xyta = new XYTitleAnnotation(0.98, 0.98, chart.getLegend(), RectangleAnchor.TOP_RIGHT);
    chart.removeLegend();
    plot.addAnnotation(xyta);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

    for (int i = 0; i < 2; i++) {
        renderer.setSeriesPaint(i * 6 + 0, new Color(255, 0, 0));
        renderer.setSeriesPaint(i * 6 + 1, new Color(0, 0, 255));
        renderer.setSeriesPaint(i * 6 + 2, new Color(0, 139, 0));
        renderer.setSeriesPaint(i * 6 + 3, new Color(255, 165, 0));
        renderer.setSeriesPaint(i * 6 + 4, new Color(255, 0, 255));
        renderer.setSeriesPaint(i * 6 + 5, new Color(0, 0, 0));

        renderer.setSeriesStroke(i * 6 + 0, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 1, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 50.0f, 2.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 2, new BasicStroke(1.3f, BasicStroke.JOIN_ROUND,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 30.0f, 1.0f, 1.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 3, new BasicStroke(1.3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                10.0f, new float[] { 1.0f, 3.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 4, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 2.0f, 3.0f, 4.0f }, 0.0f));
        renderer.setSeriesStroke(i * 6 + 5, new BasicStroke(1.3f, BasicStroke.CAP_SQUARE,
                BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f, 1.0f, 20.0f, 1.0f }, 0.0f));
    }

    plot.setRenderer(renderer);

    return chart;

}

From source file:org.tsho.dmc2.core.chart.Bifurcation2DRenderer.java

public LegendItemCollection getLegendItems() {

    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    Shape shape = new Rectangle2D.Double(-3, -3, 6, 6);

    LegendItemCollection legendItems = new LegendItemCollection();

    for (int i = 0; i < period; i++) {
        legendItems.add(new LegendItem(Integer.toString(i + 1), "", shape, true,
                (DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]), stroke, Color.yellow, stroke));
    }/*from   w  ww  .ja v  a  2 s . c o  m*/

    legendItems.add(new LegendItem(">" + period, "", shape, true, Color.white, stroke, Color.yellow, stroke));

    legendItems.add(new LegendItem("infinity", "", shape, true, Color.black, stroke, Color.yellow, stroke));

    return legendItems;
}

From source file:SWTGraphics2D.java

/**
 * Sets the stroke for this graphics context.  For now, this implementation
 * only recognises the {@link BasicStroke} class.
 *
 * @param stroke  the stroke (<code>null</code> not permitted).
 *
 * @see #getStroke()//w  w  w . j  av a2s.com
 */
public void setStroke(Stroke stroke) {
    if (stroke instanceof BasicStroke) {
        BasicStroke bs = (BasicStroke) stroke;
        // linewidth
        this.gc.setLineWidth((int) bs.getLineWidth());

        // line join
        switch (bs.getLineJoin()) {
        case BasicStroke.JOIN_BEVEL:
            this.gc.setLineJoin(SWT.JOIN_BEVEL);
            break;
        case BasicStroke.JOIN_MITER:
            this.gc.setLineJoin(SWT.JOIN_MITER);
            break;
        case BasicStroke.JOIN_ROUND:
            this.gc.setLineJoin(SWT.JOIN_ROUND);
            break;
        }

        // line cap
        switch (bs.getEndCap()) {
        case BasicStroke.CAP_BUTT:
            this.gc.setLineCap(SWT.CAP_FLAT);
            break;
        case BasicStroke.CAP_ROUND:
            this.gc.setLineCap(SWT.CAP_ROUND);
            break;
        case BasicStroke.CAP_SQUARE:
            this.gc.setLineCap(SWT.CAP_SQUARE);
            break;
        }

        // set the line style to solid by default
        this.gc.setLineStyle(SWT.LINE_SOLID);

        // apply dash style if any
        float[] dashes = bs.getDashArray();
        if (dashes != null) {
            int[] swtDashes = new int[dashes.length];
            for (int i = 0; i < swtDashes.length; i++) {
                swtDashes[i] = (int) dashes[i];
            }
            this.gc.setLineDash(swtDashes);
        }
    } else {
        throw new RuntimeException("Can only handle 'Basic Stroke' at present.");
    }
}

From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java

public LegendItemCollection getLegendItems() {
    if (type != AREA)
        return null;

    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    Shape shape = new Rectangle2D.Double(-3, -3, 6, 6);

    LegendItemCollection legendItems = new LegendItemCollection();
    legendItems.add(new LegendItem("both zero", "", shape, true, Color.black, stroke, Color.yellow, stroke));

    legendItems.add(new LegendItem("zero, positive", "", shape, true, Color.red, stroke, Color.yellow, stroke));

    legendItems/*from w  w  w. j  a va 2 s  . c  o m*/
            .add(new LegendItem("zero, negative", "", shape, true, Color.blue, stroke, Color.yellow, stroke));

    legendItems.add(
            new LegendItem("positive, negative", "", shape, true, Color.green, stroke, Color.yellow, stroke));

    legendItems
            .add(new LegendItem("both positive", "", shape, true, Color.orange, stroke, Color.yellow, stroke));

    legendItems.add(new LegendItem("both negative", "", shape, true, Color.pink, stroke, Color.yellow, stroke));

    return legendItems;
}

From source file:edu.umn.ecology.populus.plot.BasicPlotInfo.java

private Stroke getLineStroke(int n) {
    JCChartStyle jccs = getChartStyle(n);
    return new BasicStroke((float) jccs.getLineWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f,
            getDashArray(jccs.getLinePattern()), 0.0f);
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Returns the stroke used to outline data items.  The default
 * implementation passes control to the/*from  www . j  a va 2 s. c  om*/
 * {@link #lookupSeriesOutlineStroke(int)} method. You can override this
 * method if you require different behaviour.
 *
 * @param row    the row (or series) index (zero-based).
 * @param column the column (or category) index (zero-based).
 * @return The stroke (never <code>null</code>).
 */
@Override
public Stroke getItemOutlineStroke(int row, int column) {
    Number z = dataset.getZ(row, column);

    BasicStroke stroke = DEFAULT_OUTLINE_STROKE;

    if (shouldHighlight(row, column)) {
        stroke = new BasicStroke(2.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    }

    if (z == null) {
        stroke = new BasicStroke(stroke.getLineWidth(), stroke.getEndCap(), stroke.getLineJoin(),
                stroke.getMiterLimit(), new float[] { 5.0f, 5.0f }, 0.0f);
    }

    return stroke;
}

From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java

public LegendItemCollection getLegendItems() {
    if (type != TYPE_AREA)
        return null;
    LegendItemCollection legendItems = new LegendItemCollection();

    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    Shape shape = new Rectangle2D.Double(-3, -3, 6, 6);

    Iterator i = signsSet.iterator();
    while (i.hasNext()) {
        ExpsSigns es = (ExpsSigns) i.next();
        Color color = lyapunovColors.getColor(es.zer, es.pos, es.neg, es.nan);
        legendItems.add(new LegendItem(es.toString(), "", shape, true, color, stroke, Color.yellow, stroke));
    }/*w w  w.j  av a  2s  .c  o m*/
    if (pass == 0) {
        signsSet.clear();
    }
    return legendItems;
}

From source file:lucee.runtime.img.Image.java

public void setDrawingStroke(Struct attr) throws PageException {

    // empty //from w ww.ja  v  a2s .  co  m
    if (attr == null || attr.size() == 0) {
        setDrawingStroke(new BasicStroke());
        return;
    }

    // width
    float width = Caster.toFloatValue(attr.get("width", new Float(1F)));
    if (width < 0)
        throw new ExpressionException("key [width] should be a none negativ number");

    // endcaps
    String strEndcaps = Caster.toString(attr.get("endcaps", "square"));
    strEndcaps = strEndcaps.trim().toLowerCase();
    int endcaps;
    if ("square".equals(strEndcaps))
        endcaps = BasicStroke.CAP_SQUARE;
    else if ("butt".equals(strEndcaps))
        endcaps = BasicStroke.CAP_BUTT;
    else if ("round".equals(strEndcaps))
        endcaps = BasicStroke.CAP_ROUND;
    else
        throw new ExpressionException("key [endcaps] has an invalid value [" + strEndcaps
                + "], valid values are [square,round,butt]");

    // linejoins
    String strLinejoins = Caster.toString(attr.get("linejoins", "miter"));
    strLinejoins = strLinejoins.trim().toLowerCase();
    int linejoins;
    if ("bevel".equals(strLinejoins))
        linejoins = BasicStroke.JOIN_BEVEL;
    else if ("miter".equals(strLinejoins))
        linejoins = BasicStroke.JOIN_MITER;
    else if ("round".equals(strLinejoins))
        linejoins = BasicStroke.JOIN_ROUND;
    else
        throw new ExpressionException("key [linejoins] has an invalid value [" + strLinejoins
                + "], valid values are [bevel,miter,round]");

    // miterlimit
    float miterlimit = 10.0F;
    if (linejoins == BasicStroke.JOIN_MITER) {
        miterlimit = Caster.toFloatValue(attr.get("miterlimit", new Float(10F)));
        if (miterlimit < 1F)
            throw new ExpressionException("key [miterlimit] should be greater or equal to 1");
    }

    // dashArray
    Object oDashArray = attr.get("dashArray", null);
    float[] dashArray = null;
    if (oDashArray != null) {
        dashArray = ArrayUtil.toFloatArray(oDashArray);
    }

    // dash_phase
    float dash_phase = Caster.toFloatValue(attr.get("dash_phase", new Float(0F)));

    setDrawingStroke(width, endcaps, linejoins, miterlimit, dashArray, dash_phase);
}