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

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

Introduction

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

Prototype

XYAnnotation

Source Link

Usage

From source file:org.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private XYAnnotation slopeLine() {
    return new XYAnnotation() {

        private double x1, y1, x2, y2;

        @Override/*from w ww  .  j  a  v a2  s. com*/
        public void removeChangeListener(final AnnotationChangeListener listener) {
            // ignore
        }

        @Override
        public void addChangeListener(final AnnotationChangeListener listener) {
            // ignore
        }

        @Override
        public void draw(final Graphics2D g2, final XYPlot plot, final Rectangle2D dataArea,
                final ValueAxis domainAxis, final ValueAxis rangeAxis, final int rendererIndex,
                final PlotRenderingInfo info) {
            calcLineCoords(dataArea);
            drawLine(g2);
        }

        private void drawLine(final Graphics2D g2) {
            final Color origColor = g2.getColor();
            g2.setColor(Color.black);
            g2.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
            g2.setColor(Color.lightGray);
            g2.drawLine((int) x1, 0, (int) x1, 192);
            g2.drawLine((int) x2, 0, (int) x2, 192);
            g2.setColor(origColor);
        }

        @SuppressWarnings("synthetic-access")
        private void calcLineCoords(final Rectangle2D rect) {
            // offset necessary since chart is not drawn on whole rectangle
            int offset = 12;
            final double x = rect.getMinX() + offset;
            final double y = rect.getMinY();
            final double w = rect.getWidth() - 2 * offset;
            final double h = rect.getHeight();
            final double min = bundle.getTheoreticalMin();
            final double max = bundle.getTheoreticalMax();
            final double defaultMin = bundle.getDataMin();
            final double defaultMax = bundle.getDataMax();
            final double scale = w / (defaultMax - defaultMin);
            double slope = 0.0;
            if (max != min) {
                slope = h / (max - min);
            }
            if (min >= defaultMin) {
                x1 = scale * (min - defaultMin);
                y1 = h;
            } else {
                x1 = 0;
                if (max > min) {
                    y1 = h - ((defaultMin - min) * slope);
                } else {
                    y1 = h;
                }
            }
            if (max <= defaultMax) {
                x2 = (scale * (max - defaultMin));
                y2 = 0;
            } else {
                x2 = w;
                if (max > min) {
                    y2 = h - ((defaultMax - min) * slope);
                } else {
                    y2 = 0;
                }
            }
            x1 += x;
            x2 += x;
            y1 += y;
            y2 += y;
        }
    };
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java

/**
 * Show time/*w w  w.  j  a  v a 2s. com*/
 *
 * @param value show time
 */
public void showAnimationTime(boolean value) {
    this.showAnimationTime = value;
    if (animationTimeAnnotation == null) {
        animationTimeAnnotation = new XYAnnotation() {
            public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis,
                    ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
                if (showAnimationTime) {
                    drawTime(g2, plot, dataArea, domainAxis, rangeAxis, rendererIndex, info);
                }
            }

            @Override
            public void addChangeListener(AnnotationChangeListener arg0) {
            }

            @Override
            public void removeChangeListener(AnnotationChangeListener arg0) {
            }
        };
        List plots = getPlots();
        for (int plotIdx = 0; plotIdx < plots.size(); plotIdx++) {
            ChartHolder chartHolder = (ChartHolder) plots.get(plotIdx);
            ((XYPlot) chartHolder.getPlot()).addAnnotation(animationTimeAnnotation);
        }
    }
}

From source file:ucar.unidata.idv.control.chart.XYChartManager.java

/**
 * Set the label to use when we have an empty chart
 *
 * @param label empty chart label//from ww  w  .j  a  v a  2s. co m
 */
public void setEmptyChartLabel(String label) {
    boolean signalChange = !Misc.equals(emptyChartLabel, label);
    if (emptyChartAnnotation == null) {
        signalChange = true;
        emptyChartAnnotation = new XYAnnotation() {
            public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis,
                    ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
                if (!hasStuff()) {
                    g2.setColor(Color.black);
                    g2.drawString(emptyChartLabel, 100, 50);
                }
            }

            @Override
            public void addChangeListener(AnnotationChangeListener arg0) {
            }

            @Override
            public void removeChangeListener(AnnotationChangeListener arg0) {
            }
        };
        for (int plotIdx = 0; plotIdx < chartHolders.size(); plotIdx++) {
            ChartHolder chartHolder = (ChartHolder) chartHolders.get(plotIdx);
            ((XYPlot) chartHolder.getPlot()).addAnnotation(emptyChartAnnotation);
        }
    }
    emptyChartLabel = label;
    if (signalChange) {
        signalChartChanged();
    }
}