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:com.xilinx.kintex7.ThermoPlot.java

public void createPlot() {
    dset = new DefaultValueDataset(50);
    plot = new ThermometerPlot(dset);
    plot.setRange(0, 125);/*from   w w  w  . j av a2  s  .c  o m*/
    //plot.setFollowDataInSubranges(true);
    //plot.setUseSubrangePaint(false);
    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setSubrange(ThermometerPlot.NORMAL, 0, 60);
    plot.setSubrange(ThermometerPlot.WARNING, 60, 85);
    plot.setSubrange(ThermometerPlot.CRITICAL, 86, 125);

    plot.setThermometerPaint(Color.BLACK);
    plot.setOutlineVisible(false);
    plot.setBackgroundAlpha(0);
    plot.setMercuryPaint(Color.ORANGE);
    plot.setUnits(ThermometerPlot.UNITS_NONE);
    chart = new JFreeChart("", plot);
    TextTitle ttitle = new TextTitle("Temperature (\u2103)", new Font("Temperature (\u2103)", Font.BOLD, 15));
    ttitle.setPaint(Color.WHITE);
    chart.setTitle(ttitle);
    chart.setBackgroundPaint(new Color(133, 133, 133));
    //chart.setTitle("");
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.dialcharts.BulletGraph.java

public JFreeChart createChart(DatasetMap datasets) {

    logger.debug("IN");
    Dataset dataset = (Dataset) datasets.getDatasets().get("1");
    ValueDataset valDataSet = (ValueDataset) dataset;

    Number value = valDataSet.getValue();

    DefaultCategoryDataset datasetC = new DefaultCategoryDataset();
    datasetC.addValue(value, "", "");

    // customize a bar chart 
    JFreeChart chart = ChartFactory.createBarChart(null, null, null, datasetC, PlotOrientation.HORIZONTAL,
            false, false, false);//from   w w w  . jav  a 2 s. c  o m
    chart.setBorderVisible(false);

    chart.setBackgroundPaint(color);

    TextTitle title = setStyleTitle(name, styleTitle);
    chart.setTitle(title);
    if (subName != null && !subName.equals("")) {
        TextTitle subTitle = setStyleTitle(subName, styleSubTitle);
        chart.addSubtitle(subTitle);
    }

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setOutlineVisible(true);
    plot.setOutlinePaint(Color.BLACK);
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setBackgroundPaint(null);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setAnchorValue(value.doubleValue());

    // add the target marker 
    if (target != null) {
        ValueMarker marker = new ValueMarker(target.doubleValue(), Color.BLACK, new BasicStroke(2.0f));
        plot.addRangeMarker(marker, Layer.FOREGROUND);
    }

    //sets different marks
    for (Iterator iterator = intervals.iterator(); iterator.hasNext();) {
        KpiInterval interval = (KpiInterval) iterator.next();
        // add the marks 
        IntervalMarker marker = new IntervalMarker(interval.getMin(), interval.getMax(), interval.getColor());
        plot.addRangeMarker(marker, Layer.BACKGROUND);
        logger.debug("Added new interval to the plot");
    }

    // customize axes 
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setVisible(false);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(true);
    // calculate the upper limit 
    //double upperBound = target * upperFactor; 
    rangeAxis.setRange(new Range(lower, upper));
    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    // customize renderer 
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setMaximumBarWidth(0.18);
    renderer.setSeriesPaint(0, Color.BLACK);

    return chart;
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Draws an arrow from <code>(xCenter,yCenter)</code> to <code>(x,y)</code>.
 * Code stolen from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135.
 * //from  www .ja v  a  2 s  . c o  m
 * @param g the graphics context to draw in
 * @param headSize the size of the arrow head
 * @param xCenter the x-coord of the arrow tail
 * @param yCenter the y-coord of the arrow tail
 * @param x the x-coord of the arrow head's tip
 * @param y the y-coord of the arrow head's tip
 * @param stroke the <code>Stroke</code> to use
 */
public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y, int headSize, float stroke) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.addRenderingHints(hints);

    double aDir = Math.atan2(xCenter - x, yCenter - y);
    Stroke origStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(stroke)); // make the arrow head solid even if dash pattern has been specified
    g2d.drawLine(x, y, xCenter, yCenter);
    Polygon tmpPoly = new Polygon();
    int i1 = 2 * headSize + (int) stroke; //(stroke * 2);
    int i2 = headSize + (int) stroke; // make the arrow head the same size regardless of the length length
    tmpPoly.addPoint(x, y); // arrow tip
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);
    g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted
    g2d.setStroke(origStroke);
}

From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloTrendGraph.java

@Override
protected JFreeChart createGraph() {
    final JFreeChart chart = ChartFactory.createLineChart(null, // chart title
            null, // unused
            yLabel, // range axis label
            categoryDataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips
            false // urls
    );/*  w ww  .j av a 2  s  .co m*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    final LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);

    chart.setBackgroundPaint(Color.white);

    final CategoryPlot plot = chart.getCategoryPlot();

    // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerBound(0);
    rangeAxis.setAutoRange(true);

    final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    ColorPalette.apply(renderer);

    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0));

    return chart;
}

From source file:edu.gmu.cs.sim.util.media.chart.HistogramSeriesAttributes.java

public void rebuildGraphicsDefinitions() {
    XYBarRenderer renderer = (XYBarRenderer) (((XYPlot) getPlot()).getRenderer());

    if (thickness == 0.0) {
        renderer.setDrawBarOutline(false);
    } else {/*from ww w .  j a  va2s. c om*/
        renderer.setSeriesOutlineStroke(getSeriesIndex(), new BasicStroke(thickness));
        renderer.setDrawBarOutline(true);
    }

    renderer.setSeriesPaint(getSeriesIndex(), reviseColor(fillColor, fillOpacity));
    renderer.setSeriesOutlinePaint(getSeriesIndex(), reviseColor(strokeColor, lineOpacity));
    repaint();
}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialPointer.java

/**
 * Draws the pointer.//from  ww w .j  a  v a  2s.com
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    g2.setStroke(new BasicStroke(1.0f));
    Rectangle2D lengthRect = DialPlot.rectangleByRadius(frame, this.getRadius(), this.getRadius());
    Rectangle2D widthRect = DialPlot.rectangleByRadius(frame, this.getWidthRadius(), this.getWidthRadius());
    double value = ChartThemesUtilities.getScaledValue(plot.getValue(this.getDatasetIndex()), scale);
    DialScale scale = plot.getScaleForDataset(this.getDatasetIndex());
    double angle = scale.valueToAngle(value);

    Arc2D arc1 = new Arc2D.Double(lengthRect, angle, 0, Arc2D.OPEN);
    Point2D pt1 = arc1.getEndPoint();
    Arc2D arc2 = new Arc2D.Double(widthRect, angle - 90.0, 180.0, Arc2D.OPEN);
    Point2D pt2 = arc2.getStartPoint();
    Point2D pt3 = arc2.getEndPoint();
    Arc2D arc3 = new Arc2D.Double(widthRect, angle - 180.0, 0.0, Arc2D.OPEN);
    Point2D pt4 = arc3.getStartPoint();

    GeneralPath gp = new GeneralPath();
    gp.moveTo((float) pt1.getX(), (float) pt1.getY());
    gp.lineTo((float) pt2.getX(), (float) pt2.getY());
    gp.lineTo((float) pt4.getX(), (float) pt4.getY());
    gp.lineTo((float) pt3.getX(), (float) pt3.getY());
    gp.closePath();
    g2.setPaint(this.fillPaint);
    g2.fill(gp);

    g2.setPaint(this.getOutlinePaint());
    Line2D line = new Line2D.Double(frame.getCenterX(), frame.getCenterY(), pt1.getX(), pt1.getY());
    //      g2.draw(line);

    line.setLine(pt2, pt3);
    g2.draw(line);

    line.setLine(pt3, pt1);
    g2.draw(line);

    line.setLine(pt2, pt1);
    g2.draw(line);

    line.setLine(pt2, pt4);
    g2.draw(line);

    line.setLine(pt3, pt4);
    g2.draw(line);
}

From source file:org.osjava.reportrunner_plugins.renderers.jfreechart.creators.TexturedBarRenderer.java

public java.awt.Paint getSeriesPaint(int row) {
    BufferedImage bufferedImage = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bufferedImage.createGraphics();
    TexturePaint texture = null;/* w w w  . ja  va 2s  .co m*/
    int rowNum = row + 1;
    int patNum = 13;
    int formula = rowNum - ((rowNum / patNum) * patNum);

    if (formula == 0) {
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);

    } else if (formula == 1) {
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 2) {
        Color color = Color.blue;
        big.setColor(Color.white);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(0, 1, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 3) {
        Color color = Color.yellow;
        big.setColor(Color.orange);
        big.fillRect(0, 0, 5, 5);
        big.setColor(color);
        big.fillRect(1, 1, 4, 4);
        Rectangle r = new Rectangle(0, 0, 5, 5);

        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 4) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 5) {
        big.setColor(Color.magenta);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.pink);
        big.fillRect(0, 0, 4, 4);

        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 6) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);
        }

        big.setColor(new Color(226, 199, 252));
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.blue);
        big.setStroke(new BasicStroke(1.0f));

        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 7) {
        big.setColor(Color.lightGray);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.red);
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 8) {
        float[] x = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        float[] y = { .5f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f, 4.0f, 4.5f, 5.0f };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[0]);
        for (int j = 1; j < x.length; j++) {
            path.lineTo(x[j], y[j]);

        }
        big.setColor(Color.blue);
        big.fillRect(0, 0, 5, 5);
        big.setColor(Color.cyan);
        big.setStroke(new BasicStroke(2.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 9) {
        Color color = new Color(0xBBBBDD);
        big.setColor(color);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(199, 201, 230));
        big.fillRect(1, 0, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 10) {
        float[] x = { 1, 2, 3, 4, 5 };
        float[] y = { 1, 2, 3, 4, 5 };
        GeneralPath path = new GeneralPath();
        path.moveTo(x[0], y[1]);
        path.lineTo(x[1], y[0]);
        path.moveTo(x[0], y[2]);
        path.lineTo(x[2], y[0]);
        path.moveTo(x[0], y[3]);
        path.lineTo(x[3], y[0]);
        path.moveTo(x[0], y[4]);
        path.lineTo(x[4], y[0]);
        big.setColor(Color.red);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(242, 242, 193));
        big.setStroke(new BasicStroke(3.0f));
        big.draw(path);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 11) {
        big.setColor(new Color(252, 169, 171));
        big.fillOval(0, 0, 5, 6);
        big.setColor(new Color(252, 230, 230));
        big.fillOval(0, 0, 3, 3);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    } else if (formula == 12) {
        big.setColor(Color.green);
        big.fillRect(0, 0, 5, 5);
        big.setColor(new Color(20, 178, 38));
        big.fillRect(2, 2, 5, 5);
        Rectangle r = new Rectangle(0, 0, 5, 5);
        texture = new TexturePaint(bufferedImage, r);
    }
    return texture;

}

From source file:org.optaplanner.benchmark.impl.statistic.stepscore.StepScoreProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    List<XYPlot> plotList = new ArrayList<XYPlot>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        List<XYSeries> seriesList = new ArrayList<XYSeries>(BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE);
        // No direct ascending lines between 2 points, but a stepping line instead
        XYItemRenderer renderer = new XYStepRenderer();
        if (singleBenchmarkResult.isSuccess()) {
            StepScoreSingleStatistic singleStatistic = (StepScoreSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (StepScoreStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                double[] levelValues = ScoreUtils.extractLevelDoubles(point.getScore());
                for (int i = 0; i < levelValues.length && i < BenchmarkReport.CHARTED_SCORE_LEVEL_SIZE; i++) {
                    if (i >= seriesList.size()) {
                        seriesList.add(new XYSeries(
                                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix()));
                    }/*from  w  w  w  . j  ava 2  s  . c  om*/
                    seriesList.get(i).add(timeMillisSpent, levelValues[i]);
                }
            }
            if (singleStatistic.getPointList().size() <= 1) {
                // Workaround for https://sourceforge.net/tracker/?func=detail&aid=3387330&group_id=15494&atid=115494
                renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES_AND_LINES);
            }
        }
        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        }
        for (int i = 0; i < seriesList.size(); i++) {
            if (i >= plotList.size()) {
                plotList.add(createPlot(benchmarkReport, i));
            }
            plotList.get(i).setDataset(seriesIndex, new XYSeriesCollection(seriesList.get(i)));
            plotList.get(i).setRenderer(seriesIndex, renderer);
        }
        seriesIndex++;
    }
    graphFileList = new ArrayList<File>(plotList.size());
    for (int scoreLevelIndex = 0; scoreLevelIndex < plotList.size(); scoreLevelIndex++) {
        JFreeChart chart = new JFreeChart(
                problemBenchmarkResult.getName() + " step score level " + scoreLevelIndex + " statistic",
                JFreeChart.DEFAULT_TITLE_FONT, plotList.get(scoreLevelIndex), true);
        graphFileList.add(writeChartToImageFile(chart,
                problemBenchmarkResult.getName() + "StepScoreStatisticLevel" + scoreLevelIndex));
    }
}

From source file:org.cerberus.refactor.LineChart.java

public BufferedImage bi(TimeSeriesCollection timeseriescollection, String xname, String name, int count) {

    BufferedImage bi = null;/*from   w w  w  .j ava2s  . c om*/
    boolean fc = false;
    XYDataset xydataset = timeseriescollection;

    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(name, xname, name, xydataset, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(false);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        Shape point = ShapeUtilities.createDiagonalCross(1, 1);
        String[] seriesColors = { "#FF0000", "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" };
        String[] seriesColors2 = { "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" };
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
        for (int a = 0; a < count; a++) {
            xylineandshaperenderer.setSeriesShape(a, point);
            xyitemrenderer.setSeriesStroke(a, new BasicStroke(1.0F));
            //TODO check this - fc is always false
            if (fc) {
                xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors[count - a - 1]));
            } else {
                xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors2[count - a - 1]));
            }
        }

    }
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

    bi = jfreechart.createBufferedImage(500, 270);

    return bi;

}

From source file:org.jfree.experimental.chart.plot.dial.DialValueIndicator.java

/** 
 * Creates a new instance of <code>DialValueIndicator</code>.
 * //from  w  ww  . j  av  a 2s.  c om
 * @param datasetIndex  the dataset index.
 * @param label  the label.
 */
public DialValueIndicator(int datasetIndex, String label) {
    this.datasetIndex = datasetIndex;
    this.angle = -90.0;
    this.radius = 0.3;
    this.frameAnchor = RectangleAnchor.CENTER;
    this.templateValue = new Double(100.0);
    this.formatter = new DecimalFormat("0.0");
    this.font = new Font("Dialog", Font.BOLD, 14);
    this.paint = Color.black;
    this.backgroundPaint = Color.white;
    this.outlineStroke = new BasicStroke(1.0f);
    this.outlinePaint = Color.blue;
    this.insets = new RectangleInsets(4, 4, 4, 4);
    this.valueAnchor = RectangleAnchor.RIGHT;
    this.textAnchor = TextAnchor.CENTER_RIGHT;
}