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.loklak.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = (String) iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }/*w  ww  .j  ava2s . co m*/

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:ai.susi.server.api.vis.PieChartServlet.java

public JFreeChart getChart(JSONObject jsonData, boolean legendBit, boolean tooltipBit) {
    DefaultPieDataset dataset = new DefaultPieDataset();
    Iterator<String> iter = jsonData.keys();

    while (iter.hasNext()) {
        String keyData = iter.next();
        Float value = Float.parseFloat(jsonData.getString(keyData));
        dataset.setValue(keyData, value);
    }//from  w ww  .  j  a  v a  2s  .com

    boolean legend = legendBit;
    boolean tooltips = tooltipBit;
    boolean urls = false;

    JFreeChart chart = ChartFactory.createPieChart("Loklak Visualizes - PieChart", dataset, legend, tooltips,
            urls);

    chart.setBorderPaint(Color.BLACK);
    chart.setBorderStroke(new BasicStroke(5.0f));
    chart.setBorderVisible(true);

    return chart;
}

From source file:ec.ui.chart.RevisionChartPanel.java

/**
 * Sets the data of the graph/*from   ww  w .  ja v  a  2s . c om*/
 * @param reference Reference serie used for the revisions
 * @param revisions Calculated list of revision's series
 */
public void setTsData(TsData reference, List<TsData> revisions) {
    this.reference = reference;
    this.revs = revisions;

    TimeSeriesCollection ref = new TimeSeriesCollection();
    addSerie(ref, reference);

    XYPlot plot = panel.getChart().getXYPlot();
    plot.setDataset(REF_INDEX, ref);
    plot.setRenderer(REF_INDEX, refRenderer);
    refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.RED));
    refRenderer.setSeriesStroke(0, new BasicStroke(2.0f));

    TimeSeriesCollection revCol = null;
    if (revisions != null && !revisions.isEmpty()) {
        revCol = new TimeSeriesCollection();
        for (TsData t : revisions) {
            addSerie(revCol, t);
        }

        plot.setDataset(SERIES_INDEX, revCol);
        plot.setRenderer(SERIES_INDEX, seriesRenderer);
        for (int i = 0; i < revCol.getSeriesCount(); i++) {
            seriesRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE));
            seriesRenderer.setSeriesStroke(i, new BasicStroke(0.75f));
        }
    } else {
        plot.setDataset(SERIES_INDEX, Charts.emptyXYDataset());
        refRenderer.setSeriesPaint(0, themeSupport.getLineColor(ColorScheme.KnownColor.ORANGE));
    }

    configureAxis(plot);

    setRange(ref, revCol);
}

From source file:org.madsonic.controller.StatusChartController.java

public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String type = request.getParameter("type");
    int index = Integer.parseInt(request.getParameter("index"));

    List<TransferStatus> statuses = Collections.emptyList();
    if ("stream".equals(type)) {
        statuses = statusService.getAllStreamStatuses();
    } else if ("download".equals(type)) {
        statuses = statusService.getAllDownloadStatuses();
    } else if ("upload".equals(type)) {
        statuses = statusService.getAllUploadStatuses();
    }/*from w  ww .  j  av  a2 s. c  o m*/

    if (index < 0 || index >= statuses.size()) {
        return null;
    }
    TransferStatus status = statuses.get(index);

    TimeSeries series = new TimeSeries("Kbps", Millisecond.class);
    TransferStatus.SampleHistory history = status.getHistory();
    long to = System.currentTimeMillis();
    long from = to - status.getHistoryLengthMillis();
    Range range = new DateRange(from, to);

    if (!history.isEmpty()) {

        TransferStatus.Sample previous = history.get(0);

        for (int i = 1; i < history.size(); i++) {
            TransferStatus.Sample sample = history.get(i);

            long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp();
            long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered());

            double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0);
            series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps);

            previous = sample;
        }
    }

    // Compute moving average.
    series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000);

    // Find min and max values.
    double min = 100;
    double max = 250;
    for (Object obj : series.getItems()) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) obj;
        double value = item.getValue().doubleValue();
        if (item.getPeriod().getFirstMillisecond() > from) {
            min = Math.min(min, value);
            max = Math.max(max, value);
        }
    }

    // Add 10% to max value.
    max *= 1.1D;

    // Subtract 10% from min value.
    min *= 0.9D;

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);

    XYItemRenderer renderer = plot.getRendererForDataset(dataset);
    renderer.setSeriesPaint(0, Color.gray.darker());
    renderer.setSeriesStroke(0, new BasicStroke(2f));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setRange(range);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(new Range(min, max));
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT);

    return null;
}

From source file:com.bdb.weather.display.freeplot.FreePlot.java

/**
 * Build the Stroke objects that will be used for each series collection.
 */// w  w w .  j a v  a 2 s .  c  om
private void buildStrokes() {
    strokes = new BasicStroke[STROKE_DASH.length + 1];
    //
    // The zeroith series is a solid line
    //
    strokes[0] = new BasicStroke(STROKE_WEIGHT);

    //
    // The rest of the strokes are build from the STROKE_DASH array
    //
    for (int i = 1; i < strokes.length; i++) {
        strokes[i] = new BasicStroke(STROKE_WEIGHT, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f,
                STROKE_DASH[i - 1], 0.0f);
    }
}

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

/**
 * Draws the pointer.//  w w w . jav  a2  s  .c om
 *
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view.
 */
@Override
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:rod_design_compute.ShowPanel.java

private void paintSR(SR rodSR, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    if (rodSR.flag == true) {
        g2d.setColor(Color.red);/*ww  w  . j ava2 s.c  om*/
        g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y),
                toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
        g.drawLine(toScreenX(rodSR.getPointB().X), toScreenY(rodSR.getPointB().Y),
                toScreenX(rodSR.getPointE().X), toScreenY(rodSR.getPointE().Y));
        drawOtherPoint(rodSR.getPointE(), g);
        g2d.setColor(Color.black);
    }

    g2d.setColor(Color.green);
    g.drawLine(toScreenX(rodSR.getPointA().X), toScreenY(rodSR.getPointA().Y), toScreenX(rodSR.getPointB().X),
            toScreenY(rodSR.getPointB().Y));
    g2d.setColor(Color.black);

    drawBasePoint(rodSR.getPointA(), g);
    drawJunctionPoint(rodSR.getPointB(), g);
}

From source file:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.Classes.FindMaxpoint.java

/**
 * Creates a chart.//from  w  w w . j a va 2  s .co  m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
public JFreeChart createChart() {

    //http://www.java2s.com/Code/Java/Chart/JFreeChartDualAxisDemo2.htm
    String xlabel = "Delay (ps)";
    String ylabel = "Signal (DN)";

    // create the chart with findmaxpoint results
    final JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            xlabel, // x axis label
            ylabel, // y axis label
            findMaxpointData_, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );

    final XYPlot plot = chart.getXYPlot();
    // deal with axes and add second dataset
    final NumberAxis yaxis1 = (NumberAxis) plot.getRangeAxis();
    yaxis1.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    yaxis1.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    final NumberAxis yaxis2 = new NumberAxis(null);
    final NumberAxis xaxis = (NumberAxis) plot.getDomainAxis();
    xaxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    xaxis.setLabelFont(new Font("Dialog", Font.PLAIN, 10));
    plot.setRangeAxis(1, yaxis2);
    plot.setDataset(1, gatePositionData_);
    plot.mapDatasetToRangeAxis(1, 1);
    yaxis1.setRange(0, 5000);
    yaxis2.setRange(-1, 1);
    yaxis2.setTickLabelsVisible(false);
    xaxis.setRange(0, 16666);

    // deal with visuals

    final XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(true, true);
    renderer1.setSeriesPaint(0, Color.RED);
    renderer1.setSeriesStroke(0, new BasicStroke(3));

    //        renderer1.setBaseShapesVisible(true);
    //        renderer1.setSeriesShape(0, ShapeUtilities.createDiagonalCross(4,1));

    plot.setRenderer(0, renderer1);

    //        final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(false, true);
    renderer2.setSeriesPaint(0, Color.CYAN);
    renderer2.setSeriesShapesFilled(0, Boolean.TRUE);
    renderer2.setBaseShapesVisible(true);
    renderer2.setShape(new Rectangle(-2, -100, 4, 200));
    renderer2.setOutlineStroke(new BasicStroke(1));
    renderer2.setOutlinePaint(Color.GRAY);
    renderer2.setUseOutlinePaint(true);
    plot.setRenderer(1, renderer2);

    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    //                
    return chart;

}

From source file:net.sourceforge.subsonic.controller.StatusChartController.java

public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String type = request.getParameter("type");
    int index = Integer.parseInt(request.getParameter("index"));

    List<TransferStatus> statuses = Collections.emptyList();
    if ("stream".equals(type)) {
        statuses = statusService.getAllStreamStatuses();
    } else if ("download".equals(type)) {
        statuses = statusService.getAllDownloadStatuses();
    } else if ("upload".equals(type)) {
        statuses = statusService.getAllUploadStatuses();
    }//from   ww  w. jav a 2  s . c om

    if (index < 0 || index >= statuses.size()) {
        return null;
    }
    TransferStatus status = statuses.get(index);

    TimeSeries series = new TimeSeries("Kbps", Millisecond.class);
    TransferStatus.SampleHistory history = status.getHistory();
    long to = System.currentTimeMillis();
    long from = to - status.getHistoryLengthMillis();
    Range range = new DateRange(from, to);

    if (!history.isEmpty()) {

        TransferStatus.Sample previous = history.get(0);

        for (int i = 1; i < history.size(); i++) {
            TransferStatus.Sample sample = history.get(i);

            long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp();
            long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered());

            double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0);
            series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps);

            previous = sample;
        }
    }

    // Compute moving average.
    series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000);

    // Find min and max values.
    double min = 100;
    double max = 250;
    for (Object obj : series.getItems()) {
        TimeSeriesDataItem item = (TimeSeriesDataItem) obj;
        double value = item.getValue().doubleValue();
        if (item.getPeriod().getFirstMillisecond() > from) {
            min = Math.min(min, value);
            max = Math.max(max, value);
        }
    }

    // Add 10% to max value.
    max *= 1.1D;

    // Subtract 10% from min value.
    min *= 0.9D;

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();

    plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white);
    plot.setBackgroundPaint(background);

    XYItemRenderer renderer = plot.getRendererForDataset(dataset);
    renderer.setSeriesPaint(0, Color.blue.darker());
    renderer.setSeriesStroke(0, new BasicStroke(2f));

    // Set theme-specific colors.
    Color bgColor = getBackground(request);
    Color fgColor = getForeground(request);

    chart.setBackgroundPaint(bgColor);

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setRange(range);
    domainAxis.setTickLabelPaint(fgColor);
    domainAxis.setTickMarkPaint(fgColor);
    domainAxis.setAxisLinePaint(fgColor);

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setRange(new Range(min, max));
    rangeAxis.setTickLabelPaint(fgColor);
    rangeAxis.setTickMarkPaint(fgColor);
    rangeAxis.setAxisLinePaint(fgColor);

    ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT);

    return null;
}

From source file:org.optaplanner.benchmark.impl.statistic.scorecalculationspeed.ScoreCalculationSpeedProblemStatistic.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("Score calculation speed per second");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries series = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix());
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.hasAllSuccess()) {
            ScoreCalculationSpeedSubSingleStatistic subSingleStatistic = (ScoreCalculationSpeedSubSingleStatistic) singleBenchmarkResult
                    .getSubSingleStatistic(problemStatisticType);
            List<ScoreCalculationSpeedStatisticPoint> points = subSingleStatistic.getPointList();
            for (ScoreCalculationSpeedStatisticPoint point : points) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long scoreCalculationSpeed = point.getScoreCalculationSpeed();
                series.add(timeMillisSpent, scoreCalculationSpeed);
            }/*  w w  w .  java 2 s.com*/
        }
        plot.setDataset(seriesIndex, new XYSeriesCollection(series));

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
}