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.jfree.chart.demo.selection.SelectionDemo3.java

private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) {
    JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo3", "X", "Y", dataset);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");

    plot.setDomainPannable(true);// ww  w  .j a v  a  2s. c o m
    plot.setRangePannable(true);
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    //XYItemRenderer r = plot.getRenderer();
    XYDotRenderer r = new XYDotRenderer();
    r.setDotHeight(2);
    r.setDotWidth(2);

    r.setSeriesPaint(0, Color.blue);
    r.setSeriesPaint(1, Color.green);
    r.setSeriesPaint(2, Color.yellow);
    r.setSeriesPaint(3, Color.orange);
    plot.setRenderer(r);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);

    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(2.0f);

    domainAxis.setMinorTickMarksVisible(true);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(2.0f);
    rangeAxis.setMinorTickMarksVisible(true);

    //add selection specific rendering
    IRSUtilities.setSelectedItemPaint(r, ext, Color.red);

    //register plot as selection change listener
    ext.addChangeListener(plot);

    return chart;
}

From source file:mase.app.soccer.Soccer.java

@Override
public void start() {
    super.start();
    this.field = new Continuous2D(par.discretization, par.fieldLength, par.fieldWidth);
    double fl = par.fieldLength, fw = par.fieldWidth, hg = par.goalWidth / 2, d = par.cornerDiag;
    Segment t1 = new Segment(new Double2D(0, fw / 2 - hg), new Double2D(0, d));
    Segment t2 = new Segment(t1.end, new Double2D(d, 0));
    Segment t3 = new Segment(t2.end, new Double2D(fl - d, 0));
    Segment t4 = new Segment(t3.end, new Double2D(fl, d));
    Segment t5 = new Segment(t4.end, new Double2D(fl, fw / 2 - hg));
    Segment t6 = new Segment(new Double2D(fl, fw / 2 + hg), new Double2D(fl, fw - d));
    Segment t7 = new Segment(t6.end, new Double2D(fl - d, fw));
    Segment t8 = new Segment(t7.end, new Double2D(d, fw));
    Segment t9 = new Segment(t8.end, new Double2D(0, fw - d));
    Segment t10 = new Segment(t9.end, new Double2D(0, fw / 2 + hg));

    leftGoalCenter = new PointObject(field, new Double2D(0, fw / 2));
    rightGoalCenter = new PointObject(field, new Double2D(fl, fw / 2));

    fieldBoundaries = new MultilineObject(field, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
    fieldBoundaries.setStroke(new BasicStroke(1));
    fieldBoundaries.paint = Color.BLACK;
    fieldBoundaries.filled = false;/*from  w  ww  . j a  v  a  2  s . co m*/
    fieldBoundaries.setLocation(new Double2D(0, 0));

    ball = new Ball(this);
    ball.setLabel("");
    ball.setColor(Color.WHITE);
    schedule.scheduleRepeating(ball);

    createAgents();
    resetTeams(startFlag);
    startFlag = !startFlag;

    referee = new Referee();
    schedule.scheduleRepeating(referee);
}

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

/**
 * Creates a sample chart./*from  w  w w . j a  v  a  2 s.  c  om*/
 *
 * @param dataset  a dataset for the chart.
 *
 * @return A sample chart.
 */
private static JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart = ChartFactory.createTimeSeriesChart("XYDrawableAnnotationDemo1", null, "$ million",
            dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainPannable(true);
    plot.setRangePannable(true);
    DateAxis xAxis = (DateAxis) plot.getDomainAxis();
    xAxis.setLowerMargin(0.2);
    xAxis.setUpperMargin(0.2);
    xAxis.setStandardTickUnits(createStandardDateTickUnits());

    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLowerMargin(0.2);
    yAxis.setUpperMargin(0.2);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseLinesVisible(true);
    renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesShape(1, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5.0f,
            new float[] { 10.0f, 5.0f }, 0.0f));
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesFillPaint(1, Color.white);
    renderer.setUseFillPaint(true);

    renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.addAnnotation(new XYDrawableAnnotation(new Month(4, 2005).getFirstMillisecond(), 600, 180, 100,
            3.0, createPieChart()));
    renderer.addAnnotation(new XYDrawableAnnotation(new Month(9, 2007).getFirstMillisecond(), 1250, 120, 100,
            2.0, createBarChart()));
    plot.setRenderer(renderer);
    return chart;
}

From source file:io.sanfran.wikiTrends.extraction.plots.PlotTimeSeries.java

private static JFreeChart createChart(XYDataset dataset, String title) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Page visits", // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );// w ww. j  a va2  s .  c  om

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(false); // if you want visible dots -> true
        renderer.setBaseShapesFilled(false); // if you want visible dots -> true

        if (seriesWidth != null) {
            for (int i = 0; i < seriesWidth.size(); i++) {
                renderer.setSeriesStroke(i, new BasicStroke(seriesWidth.get(i)));
            }
        }
        if (seriesColor != null) {
            for (int i = 0; i < seriesColor.size(); i++) {
                renderer.setSeriesPaint(i, seriesColor.get(i));
            }
        }

    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    //axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));

    return chart;

}

From source file:edu.ucla.stat.SOCR.chart.gui.CircleDrawer.java

/**
 * Draws the circle.//from  w w w  .  ja  v a2  s .  c o  m
 * 
 * @param g2  the graphics device.
 * @param area  the area in which to draw.
 */
public void draw(Graphics2D g2, Rectangle2D area) {
    Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight());
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(ellipse);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(ellipse);
    }

    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1.0f));
    Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
    Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY());
    g2.draw(line1);
    g2.draw(line2);
}

From source file:com.compomics.pepshell.view.statistics.CleavingProbabilityPane.java

@Override
public void setGraphData(PepshellProtein aPepshellProtein) {
    //obligatory checks
    if (aPepshellProtein != null && experiment.getProteins().contains(aPepshellProtein)) {
        if (aPepshellProtein != currentPepshellProtein) {
            //TODO: run this outside of the gui thread
            currentPepshellProtein = experiment.getProteins()
                    .get(experiment.getProteins().indexOf(aPepshellProtein));
            XYSeriesCollection xYSeriesCollection = new XYSeriesCollection();
            fillSeries(currentPepshellProtein).forEach(xYSeriesCollection::addSeries);
            JFreeChart CPDTchart = ChartFactory.createXYLineChart("probability of cleaving",
                    "aminoacids of " + currentPepshellProtein.getVisibleAccession(), "probability",
                    xYSeriesCollection, PlotOrientation.VERTICAL, false, true, false);
            prettifyChart(CPDTchart);/* w  ww . j  av  a 2  s  .  c  o m*/
            CPDTchart.getXYPlot().getRangeAxis().setLowerBound(cutoff - 0.05);
            for (int i = 0; i < CPDTchart.getXYPlot().getSeriesCount(); i++) {
                CPDTchart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(5));
            }
            if (!aPepshellProtein.getDomains().isEmpty()) {
                CPDTchart.setBackgroundImageAlpha(0.18f);
                CPDTchart.getXYPlot().getDomainAxis().setRange(0,
                        aPepshellProtein.getProteinSequence().length());
                BufferedImage anImage = new BufferedImage(this.getHeight(), this.getWidth(),
                        BufferedImage.TYPE_INT_ARGB);
                for (FeatureWithLocation aDomain : aPepshellProtein.getDomains()) {
                    anImage.getGraphics().drawRect(aDomain.getStartPosition(), 0, aDomain.getEndPosition(),
                            this.getHeight());
                }
                CPDTchart.setBackgroundImage(anImage);
            }
            chart.setChart(CPDTchart);
        }
    } else {
        chart.setChart(null);
        this.getGraphics().drawString("missing data", 0, 0);
    }
}

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

/**
 * Creates a new demo./*w  w w  .  j  a  va 2 s.  c om*/
 *
 * @param title  the frame title.
 */
public ThermometerDemo2(final String title) {

    super(title);

    // create a dataset...
    final DefaultValueDataset dataset = new DefaultValueDataset(new Double(43.0));

    // create the chart...
    final ThermometerPlot plot = new ThermometerPlot(dataset);
    final JFreeChart chart = new JFreeChart("Thermometer Demo 2", // chart title
            JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
            false); // include legend

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    //    plot.setInsets(new Insets(5, 5, 5, 5));
    //plot.setRangeInfo(ThermometerPlot.NORMAL, 0.0, 55.0, 0.0, 100.0);
    //plot.setRangeInfo(ThermometerPlot.WARNING, 55.0, 75.0, 0.0, 100.0);
    //plot.setRangeInfo(ThermometerPlot.CRITICAL, 75.0, 100.0, 0.0, 100.0);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Color.lightGray);
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    setContentPane(chartPanel);

}

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

public static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Normal Distribution Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainZeroBaselineVisible(true);
    xyplot.setRangeZeroBaselineVisible(true);
    xyplot.setDomainPannable(true);//from  w w w  .j  a  va 2s. c o  m
    xyplot.setRangePannable(true);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setDrawSeriesLineAsPath(true);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.5F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(2,
            new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F, 3F, 3F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 4F, 4F }, 0.0F));
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(" = -2.0, \262 = 0.5", -2D,
            0.56399999999999995D, 3.9269908169872414D);
    xypointerannotation.setLabelOffset(4D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    xypointerannotation.setBackgroundPaint(Color.yellow);
    xyplot.addAnnotation(xypointerannotation);
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation(" = 0.0, \262 = 0.2",
            0.22500000000000001D, 0.80000000000000004D, 0.0D);
    xypointerannotation1.setLabelOffset(4D);
    xypointerannotation1.setTextAnchor(TextAnchor.CENTER_LEFT);
    xypointerannotation1.setBackgroundPaint(new Color(0, 0, 255, 63));
    xyplot.addAnnotation(xypointerannotation1);
    XYPointerAnnotation xypointerannotation2 = new XYPointerAnnotation(" = 0.0, \262 = 1.0", 0.75D,
            0.29999999999999999D, 5.497787143782138D);
    xypointerannotation2.setLabelOffset(4D);
    xypointerannotation2.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xypointerannotation2.setBackgroundPaint(new Color(255, 0, 0, 63));
    xyplot.addAnnotation(xypointerannotation2);
    XYPointerAnnotation xypointerannotation3 = new XYPointerAnnotation(" = 0.0, \262 = 5.0", 3D,
            0.074999999999999997D, 4.7123889803846897D);
    xypointerannotation3.setLabelOffset(4D);
    xypointerannotation3.setTextAnchor(TextAnchor.BOTTOM_CENTER);
    xypointerannotation3.setBackgroundPaint(new Color(0, 255, 0, 63));
    xyplot.addAnnotation(xypointerannotation3);
    return jfreechart;
}

From source file:storybook.ui.chart.jfreechart.ChartUtil.java

public static Marker getAverageMarker(double paramDouble) {
    ValueMarker localValueMarker = new ValueMarker(paramDouble, Color.red, new BasicStroke(0.3F));
    localValueMarker.setLabel(I18N.getMsg("msg.common.average"));
    localValueMarker.setLabelFont(new Font("SansSerif", 2, 11));
    localValueMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    localValueMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    return localValueMarker;
}

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator.java

/**
 * /*from ww w  .java2 s.  c om*/
 */
public static Renderable evaluateRenderable(JasperReportsContext jasperReportsContext,
        JRComponentElement element, SpiderChartSharedBean spiderchartBean, ChartCustomizer chartCustomizer,
        String defaultRenderType, String datasetType) {
    SpiderChartComponent chartComponent = (SpiderChartComponent) element.getComponent();
    ChartSettings chartSettings = chartComponent.getChartSettings();
    SpiderPlot plot = (SpiderPlot) chartComponent.getPlot();

    DefaultCategoryDataset dataset = null;
    StandardCategoryItemLabelGenerator labelGenerator = null;

    if (FILL_DATASET.equals(datasetType)) {
        dataset = ((FillSpiderDataset) spiderchartBean.getDataset()).getCustomDataset();
        labelGenerator = ((FillSpiderDataset) spiderchartBean.getDataset()).getLabelGenerator();
    } else {
        dataset = getSampleDataset();
        labelGenerator = new StandardCategoryItemLabelGenerator();
    }

    SpiderWebPlot spiderWebPlot = new SpiderWebPlot(dataset);

    if (plot.getAxisLineColor() != null) {
        spiderWebPlot.setAxisLinePaint(plot.getAxisLineColor());
    }
    if (plot.getAxisLineWidth() != null) {
        spiderWebPlot.setAxisLineStroke(new BasicStroke(plot.getAxisLineWidth()));
    }
    if (plot.getBackcolor() != null) {
        spiderWebPlot.setBackgroundPaint(plot.getBackcolor());
    }
    if (plot.getBackgroundAlpha() != null) {
        spiderWebPlot.setBackgroundAlpha(plot.getBackgroundAlpha());
    }
    if (plot.getForegroundAlpha() != null) {
        spiderWebPlot.setForegroundAlpha(plot.getForegroundAlpha());
    }
    if (plot.getHeadPercent() != null) {
        spiderWebPlot.setHeadPercent(plot.getHeadPercent());
    }
    if (plot.getInteriorGap() != null) {
        spiderWebPlot.setInteriorGap(plot.getInteriorGap());
    }
    if (plot.getLabelColor() != null) {
        spiderWebPlot.setLabelPaint(plot.getLabelColor());
    }
    if (plot.getLabelFont() != null) {
        spiderWebPlot.setLabelFont(FontUtil.getInstance(jasperReportsContext).getAwtFont(plot.getLabelFont(),
                Locale.getDefault()));
    }
    if (plot.getLabelGap() != null) {
        spiderWebPlot.setAxisLabelGap(plot.getLabelGap());
    }
    if (spiderchartBean.getMaxValue() != null) {
        spiderWebPlot.setMaxValue(spiderchartBean.getMaxValue());
    }
    if (plot.getRotation() != null) {
        spiderWebPlot.setDirection(plot.getRotation().getRotation());
    }
    if (plot.getStartAngle() != null) {
        spiderWebPlot.setStartAngle(plot.getStartAngle());
    }
    if (plot.getTableOrder() != null) {
        spiderWebPlot.setDataExtractOrder(plot.getTableOrder().getOrder());
    }
    if (plot.getWebFilled() != null) {
        spiderWebPlot.setWebFilled(plot.getWebFilled());
    }

    spiderWebPlot.setToolTipGenerator(new StandardCategoryToolTipGenerator());
    spiderWebPlot.setLabelGenerator(labelGenerator);

    Font titleFont = chartSettings.getTitleFont() != null ? FontUtil.getInstance(jasperReportsContext)
            .getAwtFont(chartSettings.getTitleFont(), Locale.getDefault()) : TextTitle.DEFAULT_FONT;

    String titleText = spiderchartBean.getTitleText();

    JFreeChart jfreechart = new JFreeChart(titleText, titleFont, spiderWebPlot, true);

    Color backcolor = chartSettings.getBackcolor() != null ? chartSettings.getBackcolor()
            : element.getBackcolor();
    if (backcolor != null) {
        jfreechart.setBackgroundPaint(backcolor);
    }

    RectangleEdge titleEdge = getEdge(chartSettings.getTitlePosition(), RectangleEdge.TOP);

    if (titleText != null) {
        TextTitle title = jfreechart.getTitle();
        title.setText(titleText);
        if (chartSettings.getTitleColor() != null) {
            title.setPaint(chartSettings.getTitleColor());
        }

        title.setFont(titleFont);
        title.setPosition(titleEdge);
        jfreechart.setTitle(title);
    }

    String subtitleText = spiderchartBean.getSubtitleText();
    if (subtitleText != null) {
        TextTitle subtitle = new TextTitle(subtitleText);
        subtitle.setText(subtitleText);
        if (chartSettings.getSubtitleColor() != null) {
            subtitle.setPaint(chartSettings.getSubtitleColor());
        }

        if (chartSettings.getSubtitleColor() != null) {
            Font subtitleFont = chartSettings.getSubtitleFont() != null
                    ? FontUtil.getInstance(jasperReportsContext).getAwtFont(chartSettings.getSubtitleFont(),
                            Locale.getDefault())
                    : TextTitle.DEFAULT_FONT;
            subtitle.setFont(subtitleFont);
        }

        subtitle.setPosition(titleEdge);

        jfreechart.addSubtitle(subtitle);
    }

    // Apply all of the legend formatting options
    LegendTitle legend = jfreechart.getLegend();

    if (legend != null) {
        legend.setVisible((chartSettings.getShowLegend() == null || chartSettings.getShowLegend()));
        if (legend.isVisible()) {
            if (chartSettings.getLegendColor() != null) {
                legend.setItemPaint(chartSettings.getLegendColor());
            }
            if (chartSettings.getLegendBackgroundColor() != null) {
                legend.setBackgroundPaint(chartSettings.getLegendBackgroundColor());
            }

            if (chartSettings.getLegendFont() != null) {
                legend.setItemFont(FontUtil.getInstance(jasperReportsContext)
                        .getAwtFont(chartSettings.getLegendFont(), Locale.getDefault()));
            }
            legend.setPosition(getEdge(chartSettings.getLegendPosition(), RectangleEdge.BOTTOM));
        }
    }

    String renderType = chartSettings.getRenderType() == null ? defaultRenderType
            : chartSettings.getRenderType();
    Rectangle2D rectangle = new Rectangle2D.Double(0, 0, element.getWidth(), element.getHeight());

    if (chartCustomizer != null) {
        chartCustomizer.customize(jfreechart, chartComponent);
    }

    return ChartUtil.getInstance(jasperReportsContext).getChartRenderableFactory(renderType)
            .getRenderable(jasperReportsContext, jfreechart, spiderchartBean.getHyperlinkProvider(), rectangle);
}