Example usage for org.jfree.chart.annotations XYShapeAnnotation XYShapeAnnotation

List of usage examples for org.jfree.chart.annotations XYShapeAnnotation XYShapeAnnotation

Introduction

In this page you can find the example usage for org.jfree.chart.annotations XYShapeAnnotation XYShapeAnnotation.

Prototype

public XYShapeAnnotation(Shape shape, Stroke stroke, Paint outlinePaint) 

Source Link

Document

Creates a new annotation where the shape is drawn as an outline using the specified stroke and outlinePaint.

Usage

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

/**
 * Creates a new demo instance.//from  w w w  .j ava2s . c o  m
 * 
 * @param title  the frame title.
 */
public PlotOrientationDemo(String title) {

    super(title);
    JPanel panel = new JPanel(new GridLayout(2, 4));
    for (int i = 0; i < CHART_COUNT; i++) {
        this.datasets[i] = createDataset(i);
        this.charts[i] = createChart(i, this.datasets[i]);
        XYPlot plot = this.charts[i].getXYPlot();
        XYShapeAnnotation a1 = new XYShapeAnnotation(new Rectangle2D.Double(1.0, 2.0, 2.0, 3.0),
                new BasicStroke(1.0f), Color.blue);
        XYLineAnnotation a2 = new XYLineAnnotation(0.0, -5.0, 10.0, -5.0);
        XYImageAnnotation a3 = new XYImageAnnotation(5.0, 2.0, JFreeChart.INFO.getLogo());
        plot.addAnnotation(a1);
        plot.addAnnotation(a2);
        plot.addAnnotation(a3);
        plot.setQuadrantPaint(0, new Color(230, 230, 255));
        plot.setQuadrantPaint(1, new Color(230, 255, 230));
        plot.setQuadrantPaint(2, new Color(255, 230, 230));
        plot.setQuadrantPaint(3, new Color(255, 230, 255));
        this.panels[i] = new ChartPanel(this.charts[i]);
    }
    this.charts[1].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[2].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[3].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[3].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[5].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[6].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[4].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[4].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[4].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[5].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[6].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[7].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);

    panel.add(this.panels[0]);
    panel.add(this.panels[1]);
    panel.add(this.panels[4]);
    panel.add(this.panels[5]);
    panel.add(this.panels[2]);
    panel.add(this.panels[3]);
    panel.add(this.panels[6]);
    panel.add(this.panels[7]);

    panel.setPreferredSize(new Dimension(800, 600));
    setContentPane(panel);

}

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

/**
 * Creates a new demo instance.// w  w w  .jav  a 2  s  . com
 * 
 * @param title  the frame title.
 */
public PlotOrientationDemo2(String title) {

    super(title);
    JPanel panel = new JPanel(new GridLayout(2, 4));
    for (int i = 0; i < CHART_COUNT; i++) {
        this.datasets[i] = createDataset(i);
        this.charts[i] = createChart(i, this.datasets[i]);
        XYPlot plot = this.charts[i].getXYPlot();
        XYShapeAnnotation a1 = new XYShapeAnnotation(new Rectangle2D.Double(1.0, 2.0, 2.0, 3.0),
                new BasicStroke(1.0f), Color.blue);
        XYLineAnnotation a2 = new XYLineAnnotation(0.0, -5.0, 10.0, -5.0);

        plot.addAnnotation(a1);
        plot.addAnnotation(a2);
        plot.addDomainMarker(new IntervalMarker(5.0, 10.0), Layer.BACKGROUND);
        plot.addRangeMarker(new IntervalMarker(-2.0, 0.0), Layer.BACKGROUND);

        this.panels[i] = new ChartPanel(this.charts[i]);
    }
    this.charts[1].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[2].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[3].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[3].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[5].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[6].getXYPlot().getRangeAxis().setInverted(true);
    this.charts[4].getXYPlot().getDomainAxis().setInverted(true);
    this.charts[4].getXYPlot().getRangeAxis().setInverted(true);

    this.charts[4].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[5].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[6].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);
    this.charts[7].getXYPlot().setOrientation(PlotOrientation.HORIZONTAL);

    panel.add(this.panels[0]);
    panel.add(this.panels[1]);
    panel.add(this.panels[4]);
    panel.add(this.panels[5]);
    panel.add(this.panels[2]);
    panel.add(this.panels[3]);
    panel.add(this.panels[6]);
    panel.add(this.panels[7]);

    panel.setPreferredSize(new Dimension(800, 600));
    setContentPane(panel);

}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java

public void plotXYBalls(TrackDataHolder trackDataHolder) {
    int selectedIndexRadius = exploreTrackController.getExploreTrackPanel().getEnclosingBallRadiusCombobox()
            .getSelectedIndex();/*  w  w  w.j a  va2  s  .  co m*/
    List<List<EnclosingBall>> enclosingBallsList = trackDataHolder.getStepCentricDataHolder()
            .getxYEnclosingBalls();
    List<EnclosingBall> enclosingBalls = enclosingBallsList.get(selectedIndexRadius);
    // get the coordinates matrix
    Double[][] coordinatesMatrix = trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix();
    XYSeries xYSeries = JFreeChartUtils.generateXYSeries(coordinatesMatrix);
    String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well "
            + trackDataHolder.getTrack().getWellHasImagingType().getWell();
    xYSeries.setKey(seriesKey);
    XYSeriesCollection ySeriesCollection = new XYSeriesCollection(xYSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "x (m)", "y (m)",
            ySeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyPlot = chart.getXYPlot();
    JFreeChartUtils.setupXYPlot(xyPlot);
    JFreeChartUtils.setupSingleTrackPlot(chart,
            exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true);
    XYSeriesCollection dataset = (XYSeriesCollection) xyPlot.getDataset(0);
    double minY = dataset.getSeries(0).getMinY();
    double maxY = dataset.getSeries(0).getMaxY();
    xyPlot.getRangeAxis().setRange(minY - 10, maxY + 10);

    xYBallsChartPanel.setChart(chart);
    enclosingBalls.stream().forEach((ball) -> {
        xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(),
                GuiUtils.getDefaultColor()));
    });
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java

public void plotXTBalls(TrackDataHolder trackDataHolder) {
    int selectedIndexEpsilon = exploreTrackController.getExploreTrackPanel().getEnclosingBallEpsCombobox()
            .getSelectedIndex();// w w w.j av a 2  s . co m
    List<List<EnclosingBall>> xtEnclosingBallList = trackDataHolder.getStepCentricDataHolder()
            .getxTEnclosingBalls();
    List<EnclosingBall> xTempBalls = xtEnclosingBallList.get(selectedIndexEpsilon);
    // get the track coordinates matrix and transpose it
    Double[][] transpose2DArray = AnalysisUtils
            .transpose2DArray(trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix());
    // we get the x coordinates and the time information
    double[] xCoordinates = ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(transpose2DArray[0]));
    double[] timeIndexes = trackDataHolder.getStepCentricDataHolder().getTimeIndexes();
    // we create the series and set its key
    XYSeries xtSeries = JFreeChartUtils.generateXYSeries(timeIndexes, xCoordinates);
    String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well "
            + trackDataHolder.getTrack().getWellHasImagingType().getWell();
    xtSeries.setKey(seriesKey);
    // we then create the XYSeriesCollection and use it to make a new line chart
    XYSeriesCollection xtSeriesCollection = new XYSeriesCollection(xtSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "time", "x (m)",
            xtSeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis yaxis = (NumberAxis) xyPlot.getRangeAxis();
    yaxis.setAutoRangeIncludesZero(false);
    JFreeChartUtils.setupXYPlot(xyPlot);
    JFreeChartUtils.setupSingleTrackPlot(chart,
            exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true);
    xTBallsChartPanel.setChart(chart);
    xTempBalls.stream().forEach((ball) -> {
        xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(),
                GuiUtils.getDefaultColor()));
    });
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.explore.EnclosingBallController.java

public void plotYTBalls(TrackDataHolder trackDataHolder) {
    int selectedIndexEpsilon = exploreTrackController.getExploreTrackPanel().getEnclosingBallEpsCombobox()
            .getSelectedIndex();//from   w ww  .j  a v  a2s .  c o m
    List<List<EnclosingBall>> ytEnclosingBallList = trackDataHolder.getStepCentricDataHolder()
            .getyTEnclosingBalls();
    List<EnclosingBall> yTempBalls = ytEnclosingBallList.get(selectedIndexEpsilon);
    // get the track coordinates matrix and transpose it
    Double[][] transpose2DArray = AnalysisUtils
            .transpose2DArray(trackDataHolder.getStepCentricDataHolder().getCoordinatesMatrix());
    // we get the y coordinates and the time information
    double[] yCoordinates = ArrayUtils.toPrimitive(AnalysisUtils.excludeNullValues(transpose2DArray[1]));
    double[] timeIndexes = trackDataHolder.getStepCentricDataHolder().getTimeIndexes();
    // we create the series and set its key
    XYSeries ytSeries = JFreeChartUtils.generateXYSeries(timeIndexes, yCoordinates);
    String seriesKey = "track " + trackDataHolder.getTrack().getTrackNumber() + ", well "
            + trackDataHolder.getTrack().getWellHasImagingType().getWell();
    ytSeries.setKey(seriesKey);
    // we then create the XYSeriesCollection and use it to make a new line chart
    XYSeriesCollection ytSeriesCollection = new XYSeriesCollection(ytSeries);
    JFreeChart chart = ChartFactory.createXYLineChart(seriesKey + " - enclosing balls", "time", "y (m)",
            ytSeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyPlot = chart.getXYPlot();
    xyPlot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis yaxis = (NumberAxis) xyPlot.getRangeAxis();
    yaxis.setAutoRangeIncludesZero(false);
    JFreeChartUtils.setupXYPlot(xyPlot);
    JFreeChartUtils.setupSingleTrackPlot(chart,
            exploreTrackController.getExploreTrackPanel().getTracksList().getSelectedIndex(), true);
    yTBallsChartPanel.setChart(chart);
    yTempBalls.stream().forEach((ball) -> {
        xyPlot.addAnnotation(new XYShapeAnnotation(ball.getShape(), JFreeChartUtils.getDashedLine(),
                GuiUtils.getDefaultColor()));
    });
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

private void drawRectangle() {
    if (mouseDownPoint != null && mouseUpPoint != null) {

        double dn = mouseDownPoint.getX();
        double up = mouseUpPoint.getX();

        double x0 = Math.min(dn, up);
        double x1 = Math.max(dn, up);

        dn = mouseDownPoint.getY();//from  ww w  .ja  va 2  s  . c  o  m
        up = mouseUpPoint.getY();

        double y0 = Math.min(dn, up);
        double y1 = Math.max(dn, up);

        removeAnnotations();
        Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3 },
                0);
        Paint paint = Color.BLACK;

        Rectangle2D rect = new Rectangle2D.Double(x0, y0, x1 - x0, y1 - y0);
        intervalAnnotation = new XYShapeAnnotation(rect, stroke, paint);

        addRangeMarker(intervalAnnotation);
        getChartPanel().repaint();
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java

private void showSelection() {
    thePlot.clearAnnotations();//from  w  ww. j a v  a2  s  . com
    if (selected_peaks.size() > 0) {
        double width = screenToDataX(6.);
        double height = screenToDataY(6.);
        double margin = screenToDataY(8.);
        for (Peak p : selected_peaks) {
            // add annotation
            Shape shape = new Rectangle2D.Double(p.getMZ() - width / 2., p.getIntensity() - height / 2., width,
                    height);
            if (p.equals(current_peak)) {
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(2.f), Color.black));
                thePlot.addAnnotation(
                        new XYTextAnnotation(new java.text.DecimalFormat("0.0000").format(p.getMZ()), p.getMZ(),
                                p.getIntensity() + margin));
            } else
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(1.f), Color.black));
        }
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.SpectraPanel.java

private void showSelection() {
    thePlot.clearAnnotations();//from w  w w . jav a  2s .  c o  m
    if (selected_peaks.size() > 0) {
        double width = screenToDataX(6.);
        double height = screenToDataY(6.);
        double margin = screenToDataY(8.);
        for (Peak p : selected_peaks) {
            // add annotation
            Shape shape = new Rectangle2D.Double(p.getMZ() - width / 2., p.getIntensity() - height / 2., width,
                    height);
            if (p.equals(current_peak)) {
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(2.f), Color.blue));
                thePlot.addAnnotation(
                        new XYTextAnnotation(new java.text.DecimalFormat("0.0000").format(p.getMZ()), p.getMZ(),
                                p.getIntensity() + margin));
            } else
                thePlot.addAnnotation(new XYShapeAnnotation(shape, new BasicStroke(1.f), Color.black));
        }
    }
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

@SuppressWarnings("unchecked")
public void redrawSelectedPlots() {

    if (syncedOption.getSyncWhat().isSync() && !getSelectionChanging()) {
        XYPlot xyplot = getChart().getXYPlot();

        //         curationControls.setSyncedState(true);

        Double yscale = (xyplot.getRangeAxis().getUpperBound() - xyplot.getRangeAxis().getLowerBound()) / 50;
        Double xscale = (xyplot.getDomainAxis().getUpperBound() - xyplot.getDomainAxis().getLowerBound()) / 50;

        Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3 },
                0);// ww  w  . java2 s. c  o m
        Paint paint = Color.RED;

        for (Annotation anno : (List<Annotation>) xyplot.getAnnotations()) {
            if (anno != intervalAnnotation && anno instanceof XYShapeAnnotation) {
                xyplot.removeAnnotation((XYShapeAnnotation) anno);
            }
        }

        for (Point2D point : selectedPoints) {
            double x = point.getX();
            double y = point.getY();

            double y1 = y - yscale;
            double y2 = y + yscale;
            double x1 = x - xscale;
            double x2 = x + xscale;

            Ellipse2D oval = new Ellipse2D.Double(x1, y1, x2 - x1, y2 - y1);

            XYShapeAnnotation lineanno0 = new XYShapeAnnotation(oval, stroke, paint);
            addRangeMarker(lineanno0);
        }
    }
    curationControls.updateButtons();
}

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

@Override
public void updateSelectedSamples() {

    PlotsByTraitInstance plotsByTraitInstance = selectedValueStore.getSyncedPlotsByTrait();

    intervalAnnotation = null;// w  w  w .  j  a  v  a 2  s . c o  m
    selectedPoints.clear();

    XYPlot xyplot = getChart().getXYPlot();

    Double yscale = (xyplot.getRangeAxis().getUpperBound() - xyplot.getRangeAxis().getLowerBound()) / 50;
    Double xscale = (xyplot.getDomainAxis().getUpperBound() - xyplot.getDomainAxis().getLowerBound()) / 50;

    removeAnnotations();
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3 }, 0);
    Paint paint = Color.RED;

    xyplot.clearRangeMarkers();

    TraitInstanceValueRetriever<?> x_tivr = tivrByTi.get(xInstance);

    double[] xy = new double[2];

    for (TraitInstance ti : plotsByTraitInstance.getTraitInstances()) {

        if (traitInstances.contains(ti) && !xInstance.equals(ti)) {

            TraitInstanceValueRetriever<?> tivr = tivrByTi.get(ti);

            for (PlotOrSpecimen pos : plotsByTraitInstance.getPlotSpecimens((ti))) {
                if (usedPlotSpecimens.isEmpty() || usedPlotSpecimens.contains(pos)) {

                    xy = getXY(x_tivr, tivr, pos, xy);

                    if (xy != null) {
                        double x = xy[0];
                        double y = xy[1];

                        double y1 = y - yscale;
                        double y2 = y + yscale;
                        double x1 = x - xscale;
                        double x2 = x + xscale;

                        selectedPoints.add(new Point2D.Double(x, y));

                        Ellipse2D oval = new Ellipse2D.Double(x1, y1, x2 - x1, y2 - y1);

                        //               Line2D line0 = new Line2D.Double(x1, y2, x2, y1);
                        //               Line2D line1 = new Line2D.Double(x1, y1, x2, y2);
                        //               
                        XYShapeAnnotation lineanno0 = new XYShapeAnnotation(oval, stroke, paint);
                        //               
                        //               XYShapeAnnotation lineanno0 = new XYShapeAnnotation(line0, stroke, paint);   
                        //               XYShapeAnnotation lineanno1 = new XYShapeAnnotation(line1, stroke, paint);

                        addRangeMarker(lineanno0);
                        //               plotPanel.addRangeMarker(lineanno1);

                    }
                }
            }
        }

        getChartPanel().repaint();
    }
    curationControls.updateButtons(false);
}