Example usage for java.awt BasicStroke BasicStroke

List of usage examples for java.awt BasicStroke BasicStroke

Introduction

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

Prototype

public BasicStroke(float width) 

Source Link

Document

Constructs a solid BasicStroke with the specified line width and with default values for the cap and join styles.

Usage

From source file:org.jreserve.gui.calculations.factor.editor.AccidentFactorPlot.java

private Component createPlotComponent() {

    boolean legend = true;
    boolean tooltips = false;
    boolean urls = false;
    chart = ChartFactory.createLineChart(null, null, null, dataSet, PlotOrientation.VERTICAL, legend, tooltips,
            urls);//from  w ww . j ava 2  s. c  o  m

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.GRAY);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.WHITE);

    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    axis.setAutoRangeStickyZero(true);

    renderer = plot.getRenderer();
    if (renderer instanceof LineAndShapeRenderer) {
        LineAndShapeRenderer lasr = (LineAndShapeRenderer) renderer;
        lasr.setBaseShapesVisible(true);
        lasr.setDrawOutlines(true);
        lasr.setUseFillPaint(true);
        lasr.setBaseStroke(new BasicStroke(2));

        ColorGenerator colors = new DefaultColorGenerator();
        int count = dataSet.getRowCount();

        int r = 3;
        Shape circle = new Ellipse2D.Float(-r, -r, 2 * r, 2 * r);
        for (int i = 0; i < count; i++) {
            Paint color = colors.nextColor();
            lasr.setSeriesPaint(i, color);
            lasr.setSeriesFillPaint(i, color);
            lasr.setSeriesShape(i, circle);
        }

    }

    return new ChartPanel(chart);
}

From source file:org.jfree.chart.demo.OverlaidBarChartDemo2.java

/**
 * Creates a sample chart./*w w w  .j  ava  2s . c  o  m*/
 * 
 * @return A sample chart.
 */
private JFreeChart createChart() {

    // create the first dataset...
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(1.0, "S1", "Category 1");
    dataset1.addValue(4.0, "S1", "Category 2");
    dataset1.addValue(3.0, "S1", "Category 3");
    dataset1.addValue(5.0, "S1", "Category 4");
    dataset1.addValue(5.0, "S1", "Category 5");
    dataset1.addValue(5.0, "S2", "Category 1");
    dataset1.addValue(7.0, "S2", "Category 2");
    dataset1.addValue(6.0, "S2", "Category 3");
    dataset1.addValue(8.0, "S2", "Category 4");
    dataset1.addValue(4.0, "S2", "Category 5");

    // create the first plot...
    final CategoryItemRenderer renderer = new BarRenderer();
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new CategoryAxis("Category"));
    plot.setRangeAxis(new NumberAxis("Value"));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.addValue(6.0, "Prior 1", "Category 1");
    dataset2.addValue(7.0, "Prior 1", "Category 2");
    dataset2.addValue(2.0, "Prior 1", "Category 3");
    dataset2.addValue(6.0, "Prior 1", "Category 4");
    dataset2.addValue(6.0, "Prior 1", "Category 5");
    dataset2.addValue(4.0, "Prior 2", "Category 1");
    dataset2.addValue(2.0, "Prior 2", "Category 2");
    dataset2.addValue(1.0, "Prior 2", "Category 3");
    dataset2.addValue(3.0, "Prior 2", "Category 4");
    dataset2.addValue(2.0, "Prior 2", "Category 5");

    final CategoryItemRenderer renderer2 = new LevelRenderer();
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesStroke(1, new BasicStroke(2.0f));
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);

    final JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Overlaid Bar Chart");
    //        chart.setLegend(new StandardLegend());
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsQuantilesChart.java

public JFreeChart createChart() {
    XYPlot plot = new XYPlot();
    ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income");
    xAxis.setRange(0.0, 102.0);// w ww . j av  a 2  s .c  o  m
    ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]");
    yAxis.setRange(-0.05, 0.3);
    //      xAxis.setVisible(false);
    //      xAxis.setFixedAutoRange(1.0);
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    DgColorScheme colorScheme = new DgColorScheme();

    XYItemRenderer renderer2;
    renderer2 = new XYLineAndShapeRenderer(true, true);
    renderer2.setSeriesItemLabelsVisible(0, true);
    //      renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator);
    plot.setDataset(0, this.dataset);
    renderer2.setSeriesStroke(0, new BasicStroke(2.0f));
    renderer2.setSeriesOutlineStroke(0, new BasicStroke(3.0f));
    renderer2.setSeriesPaint(0, colorScheme.getColor(1, "a"));
    plot.setRenderer(0, renderer2);

    JFreeChart chart = new JFreeChart("", plot);
    chart.setBackgroundPaint(ChartColor.WHITE);
    chart.getLegend().setItemFont(this.axisBuilder.getAxisFont());
    chart.setTextAntiAlias(true);
    chart.removeLegend();
    return chart;
}

From source file:com.googlecode.jchav.chart.Chart.java

/**
 * Creates a PNG graphic for the given data as a thumbnail image.
 *
 * @param out the stream to write the PNG to.  The caller is responsible
 *  for closing the stream.//from   w ww .ja va  2s  . c  om
 * 
 * @throws IOException if there was a problem creating the chart.
 */
public void writeThumbnail(final OutputStream out) throws IOException {

    // Set up the transfomration:
    final AffineTransform xform = new AffineTransform();
    xform.scale(thumbnailScale, thumbnailScale);

    // Thanks to the almanac for this one:
    // http://javaalmanac.com/egs/java.awt.image/CreateTxImage.html?l=rel
    final AffineTransformOp op = new AffineTransformOp(xform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    // The thumbnail does not need so much chart chrome: you can't
    // read the axis and the title is given in the HTML, so removing
    // these elements means there's more space in the thumbnail for the data
    boolean thumbChrome = false;

    if (false == thumbChrome) {
        chart.setTitle((String) null);
        chart.clearSubtitles();
        chart.removeLegend();

        // Removing the axis completly looks just weird, so we just
        // remove the labels:

        chart.getCategoryPlot().getRangeAxis().setLabel(null);
        chart.getCategoryPlot().getRangeAxis().setTickLabelsVisible(true);
        chart.getCategoryPlot().getRangeAxis().setTickMarksVisible(true);
        chart.getCategoryPlot().getRangeAxis().setAxisLineVisible(true);

        //  To show up at a small scale, we need a good sized axis stroke:
        Stroke stroke = new BasicStroke(2f);
        chart.getCategoryPlot().getRangeAxis().setAxisLineStroke(stroke);
        chart.getCategoryPlot().getRangeAxis().setTickMarkStroke(stroke);

        chart.getCategoryPlot().getDomainAxis().setLabel(null);
        chart.getCategoryPlot().getDomainAxis().setTickLabelsVisible(false);
        chart.getCategoryPlot().getDomainAxis().setAxisLineVisible(true);
        chart.getCategoryPlot().getDomainAxis().setAxisLineStroke(stroke);
    }

    final BufferedImage fullsize = chart.createBufferedImage(width, height);

    Graphics2D g = fullsize.createGraphics();
    for (Decorator decorator : thumbnailDecorators) {
        decorator.decorate(g, this);
    }

    final BufferedImage thumbnail = op.filter(fullsize, null /*null means create the image for us*/);

    ChartUtilities.writeBufferedImageAsPNG(out, thumbnail);

}

From source file:com.xilinx.kintex7.PowerDial.java

public void createDial() {
    plot = new MeterPlot();
    dset = new DefaultValueDataset(0);
    plot.setUnits("Watts");
    plot.setRange(new Range(1, 10));
    plot.addInterval(new MeterInterval("Acceptable", new Range(1.0, 6.0), Color.lightGray,
            new BasicStroke(2.0f), Color.GREEN));
    plot.addInterval(new MeterInterval("Warning", new Range(6.0, 8.0), Color.lightGray, new BasicStroke(2.0f),
            Color.YELLOW));//from   w w w . j a  va 2  s.  co m
    plot.addInterval(new MeterInterval("Dangerous", new Range(8.0, 10.0), Color.lightGray,
            new BasicStroke(2.0f), Color.RED));

    //sets different marks
    for (int i = 0; i < 10; i += 1) {
        if (i == 0)
            plot.addInterval(
                    new MeterInterval("", new Range(1, 1), Color.lightGray, new BasicStroke(2.0f), null));
        else
            plot.addInterval(
                    new MeterInterval("", new Range(i, i), Color.lightGray, new BasicStroke(2.0f), null));
    }
    plot.setNeedlePaint(Color.darkGray);
    plot.setDialBackgroundPaint(Color.white);
    plot.setDialOutlinePaint(Color.gray);
    plot.setDialShape(DialShape.PIE);
    plot.setMeterAngle(180);
    plot.setTickLabelsVisible(true);
    plot.setTickLabelFont(new Font("Dialog", Font.BOLD, 10));
    plot.setTickLabelPaint(Color.DARK_GRAY);
    plot.setTickSize(10.0);
    plot.setTickPaint(Color.lightGray);
    plot.setValuePaint(Color.BLACK);
    plot.setDataset(dset);

    LegendItemCollection legendItemsOld = plot.getLegendItems();
    final LegendItemCollection legendItemsNew = new LegendItemCollection();

    for (int i = 0; i < 3; i++) {
        LegendItem item = legendItemsOld.get(i);
        item.setLabelPaint(Color.WHITE);
        legendItemsNew.add(item);
    }

    LegendItemSource source = new LegendItemSource() {
        LegendItemCollection lic = new LegendItemCollection();
        {
            lic.addAll(legendItemsNew);
        }

        @Override
        public LegendItemCollection getLegendItems() {
            return lic;
        }
    };

    chart = new JFreeChart(plot);
    chart.addLegend(new LegendTitle(source));
    chart.removeLegend();
    chart.setTitle("");
    //chart.setBackgroundPaint(new GradientPaint(0,0,new Color(139,137,137),0,height,Color.BLUE ));
    //
    chart.getTitle().setPaint(Color.white);
    plot.setValueFont(new Font("Dialog", Font.BOLD, 14));
    //chartpanel = new ChartPanel(chart);
}

From source file:com.newatlanta.bluedragon.CustomBarRenderer.java

/**
 * Returns a legend item for a series./*from  ww w .ja  v a2  s.  com*/
 * 
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    CategoryDataset dataset;
    dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
    }
    Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
    Paint paint = getSeriesPaint(series);
    Paint outlinePaint = getSeriesOutlinePaint(series);
    Stroke outlineStroke = getSeriesOutlineStroke(series);

    // This is the fix for bug #2695
    if (paint instanceof java.awt.GradientPaint) {
        // When the paintstyle is "shade" use the lighter
        // color while with "light" use the darker color
        // NOTE: if we take the lighter color (Color2) and make it darker
        // and it equals the darker color (Color1) then the paintstyle
        // is "shade".
        GradientPaint gp = ((GradientPaint) paint);
        if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
            paint = gp.getColor2(); // the lighter color
        else
            paint = gp.getColor1(); // the darker color
    }

    return new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint,
            isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f),
            Color.black);
}

From source file:org.jfree.graphics2d.demo.SVGChartWithAnnotationsDemo1.java

private static JFreeChart createPieChart() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Engineering", 43.2);
    dataset.setValue("Research", 13.2);
    dataset.setValue("Advertising", 20.9);
    PiePlot plot = new PiePlot(dataset);
    plot.setBackgroundPainter(null);/*from w  w  w  .j  a  v  a2  s .  c o  m*/
    plot.setBorderPainter(null);
    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));
    plot.setLabelFont(new Font("Dialog", Font.PLAIN, 18));
    plot.setMaximumLabelWidth(0.25);
    JFreeChart chart = new JFreeChart(plot);
    chart.setBackgroundPainter(null);
    chart.removeLegend();
    chart.setPadding(RectangleInsets.ZERO_INSETS);
    return chart;
}

From source file:org.optaplanner.benchmark.impl.statistic.movecountperstep.MoveCountPerStepProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Accepted/selected moves per step");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    DrawingSupplier drawingSupplier = new DefaultDrawingSupplier();
    plot.setOrientation(PlotOrientation.VERTICAL);

    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries acceptedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " accepted");
        XYSeries selectedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " selected");
        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
        if (singleBenchmarkResult.isSuccess()) {
            MoveCountPerStepSingleStatistic singleStatistic = (MoveCountPerStepSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (MoveCountPerStepStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long acceptedMoveCount = point.getMoveCountPerStepMeasurement().getAcceptedMoveCount();
                long selectedMoveCount = point.getMoveCountPerStepMeasurement().getSelectedMoveCount();
                acceptedSeries.add(timeMillisSpent, acceptedMoveCount);
                selectedSeries.add(timeMillisSpent, selectedMoveCount);
            }//from   www .j a  v  a2  s.  com
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(acceptedSeries);
        seriesCollection.addSeries(selectedSeries);
        plot.setDataset(seriesIndex, seriesCollection);

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        } else {
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        }
        // Render both lines in the same color
        Paint linePaint = drawingSupplier.getNextPaint();
        renderer.setSeriesPaint(0, linePaint);
        renderer.setSeriesPaint(1, linePaint);
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }

    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " move count per step statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MoveCountPerStepStatistic");
}

From source file:CustomStrokes.java

public Shape createStrokedShape(Shape shape) {
    // Start off by stroking the shape with a thin line. Store the
    // resulting shape in a GeneralPath object so we can add to it.
    GeneralPath strokedShape = new GeneralPath(new BasicStroke(1.0f).createStrokedShape(shape));

    // Use a PathIterator object to iterate through each of the line and
    // curve segments of the shape. For each one, mark the endpoint and
    // control points (if any) by adding a rectangle to the GeneralPath
    float[] coords = new float[6];
    for (PathIterator i = shape.getPathIterator(null); !i.isDone(); i.next()) {
        int type = i.currentSegment(coords);
        Shape s = null, s2 = null, s3 = null;
        switch (type) {
        case PathIterator.SEG_CUBICTO:
            markPoint(strokedShape, coords[4], coords[5]); // falls through
        case PathIterator.SEG_QUADTO:
            markPoint(strokedShape, coords[2], coords[3]); // falls through
        case PathIterator.SEG_MOVETO:
        case PathIterator.SEG_LINETO:
            markPoint(strokedShape, coords[0], coords[1]); // falls through
        case PathIterator.SEG_CLOSE:
            break;
        }//  www .j a  v a2s.co m
    }

    return strokedShape;
}

From source file:charts.PieChart3D.java

/**
 * Creates a chart./* w  ww  .java  2 s.  com*/
 *
 * @param dataset
 *            the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset, PieChartModel model) {

    JFreeChart chart = ChartFactory.createPieChart(model.getTitle(), // chart
            // title
            dataset, // data
            false, // no legend
            true, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(
            new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.04);
    plot.setOutlineVisible(false);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("FCA", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("FCH", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("FCS", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("FCG", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setSectionPaint("FCJ", createGradientPaint(new Color(200, 255, 200), Color.BLACK));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} ({2}) "));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);

    // add a subtitle giving the data source
    TextTitle source = new TextTitle(model.getSubTitle(), new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}