Example usage for org.jfree.chart.axis ValueAxis addChangeListener

List of usage examples for org.jfree.chart.axis ValueAxis addChangeListener

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis addChangeListener.

Prototype

public void addChangeListener(AxisChangeListener listener) 

Source Link

Document

Registers an object for notification of changes to the axis.

Usage

From source file:net.sf.mzmine.chartbasics.gui.swing.EChartPanel.java

/**
 * Init ChartPanel Mouse Listener For MouseDraggedOverAxis event For scrolling X-Axis und zooming
 * Y-Axis0/*from ww w  .j  a v  a  2s  .  co  m*/
 */
private void initChartPanel(boolean stickyZeroForRangeAxis) {
    final EChartPanel chartPanel = this;

    // remove old init
    if (mouseAdapter != null) {
        this.removeMouseListener(mouseAdapter);
        this.removeMouseMotionListener(mouseAdapter);
        this.removeMouseWheelListener(mouseAdapter);
    }

    if (chartPanel.getChart().getPlot() instanceof XYPlot) {
        // set sticky zero
        if (stickyZeroForRangeAxis) {
            ValueAxis rangeAxis = chartPanel.getChart().getXYPlot().getRangeAxis();
            if (rangeAxis instanceof NumberAxis) {
                NumberAxis axis = (NumberAxis) rangeAxis;
                axis.setAutoRangeIncludesZero(true);
                axis.setAutoRange(true);
                axis.setAutoRangeStickyZero(true);
                axis.setRangeType(RangeType.POSITIVE);
            }
        }

        Plot p = getChart().getPlot();
        if (addZoomHistory && (p instanceof XYPlot)
                && !(p instanceof CombinedDomainXYPlot || p instanceof CombinedRangeXYPlot)) {
            // zoom history
            zoomHistory = new ZoomHistory(this, 20);

            // axis range changed listener for zooming and more
            ValueAxis rangeAxis = this.getChart().getXYPlot().getRangeAxis();
            ValueAxis domainAxis = this.getChart().getXYPlot().getDomainAxis();
            if (rangeAxis != null) {
                rangeAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {
                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR,
                            Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener)
                                l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
            if (domainAxis != null) {
                domainAxis.addChangeListener(new AxisRangeChangedListener(new ChartViewWrapper(this)) {
                    @Override
                    public void axisRangeChanged(ChartViewWrapper chart, ValueAxis axis, Range lastR,
                            Range newR) {
                        // notify listeners of changed range
                        if (axesRangeListener != null)
                            for (AxesRangeChangedListener l : axesRangeListener)
                                l.axesRangeChanged(chart, axis, lastR, newR);
                    }
                });
            }
        }

        // mouse adapter for scrolling and zooming
        mouseAdapter = new ChartGestureMouseAdapter();
        // mouseAdapter.addDebugHandler();
        this.addMouseListener(mouseAdapter);
        this.addMouseMotionListener(mouseAdapter);
        this.addMouseWheelListener(mouseAdapter);

        // add gestures
        if (standardGestures) {
            addStandardGestures();
        }
    }
}

From source file:de.laures.cewolf.jfree.ThermometerPlot.java

/**
 * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to all registered listeners.
 *
 * @param axis  the new axis (<code>null</code> not permitted).
 *
 * @see #getRangeAxis()/*from   ww w. ja v  a  2 s . c o m*/
 */
public void setRangeAxis(ValueAxis axis) {
    if (axis == null) {
        throw new IllegalArgumentException("Null 'axis' argument.");
    }
    // plot is registered as a listener with the existing axis...
    this.rangeAxis.removeChangeListener(this);

    axis.setPlot(this);
    axis.addChangeListener(this);
    this.rangeAxis = axis;
    fireChangeEvent();
}

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

/**
 * Returns a clone of the plot.//from w  w w. j  a va 2s  .  c om
 *
 * @return A clone.
 *
 * @throws CloneNotSupportedException  this can occur if some component of
 *         the plot cannot be cloned.
 */
public Object clone() throws CloneNotSupportedException {

    MyXYPlot clone = (MyXYPlot) super.clone();
    clone.domainAxes = (ObjectList) ObjectUtilities.clone(this.domainAxes);
    for (int i = 0; i < this.domainAxes.size(); i++) {
        ValueAxis axis = (ValueAxis) this.domainAxes.get(i);
        if (axis != null) {
            ValueAxis clonedAxis = (ValueAxis) axis.clone();
            clone.domainAxes.set(i, clonedAxis);
            clonedAxis.setPlot(clone);
            clonedAxis.addChangeListener(clone);
        }
    }
    clone.domainAxisLocations = (ObjectList) this.domainAxisLocations.clone();

    clone.rangeAxes = (ObjectList) ObjectUtilities.clone(this.rangeAxes);
    for (int i = 0; i < this.rangeAxes.size(); i++) {
        ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);
        if (axis != null) {
            ValueAxis clonedAxis = (ValueAxis) axis.clone();
            clone.rangeAxes.set(i, clonedAxis);
            clonedAxis.setPlot(clone);
            clonedAxis.addChangeListener(clone);
        }
    }
    clone.rangeAxisLocations = (ObjectList) ObjectUtilities.clone(this.rangeAxisLocations);

    // the datasets are not cloned, but listeners need to be added...
    clone.datasets = (ObjectList) ObjectUtilities.clone(this.datasets);
    for (int i = 0; i < clone.datasets.size(); ++i) {
        XYDataset d = getDataset(i);
        if (d != null) {
            d.addChangeListener(clone);
        }
    }

    clone.datasetToDomainAxisMap = new TreeMap();
    clone.datasetToDomainAxisMap.putAll(this.datasetToDomainAxisMap);
    clone.datasetToRangeAxisMap = new TreeMap();
    clone.datasetToRangeAxisMap.putAll(this.datasetToRangeAxisMap);

    clone.renderers = (ObjectList) ObjectUtilities.clone(this.renderers);
    for (int i = 0; i < this.renderers.size(); i++) {
        XYItemRenderer renderer2 = (XYItemRenderer) this.renderers.get(i);
        if (renderer2 instanceof PublicCloneable) {
            PublicCloneable pc = (PublicCloneable) renderer2;
            clone.renderers.set(i, pc.clone());
        }
    }
    clone.foregroundDomainMarkers = (Map) ObjectUtilities.clone(this.foregroundDomainMarkers);
    clone.backgroundDomainMarkers = (Map) ObjectUtilities.clone(this.backgroundDomainMarkers);
    clone.foregroundRangeMarkers = (Map) ObjectUtilities.clone(this.foregroundRangeMarkers);
    clone.backgroundRangeMarkers = (Map) ObjectUtilities.clone(this.backgroundRangeMarkers);
    clone.annotations = (List) ObjectUtilities.deepClone(this.annotations);
    if (this.fixedDomainAxisSpace != null) {
        clone.fixedDomainAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedDomainAxisSpace);
    }
    if (this.fixedRangeAxisSpace != null) {
        clone.fixedRangeAxisSpace = (AxisSpace) ObjectUtilities.clone(this.fixedRangeAxisSpace);
    }
    return clone;

}

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

/**
 * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.//from  w w  w.j  a  va2 s  .c o m
 *
 * @param index  the axis index.
 * @param axis  the axis (<code>null</code> permitted).
 * @param notify and notify the listeners
 */
public void setRangeAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getRangeAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.rangeAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        notifyListeners(new PlotChangeEvent(this));
    }
}

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

/**
 * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to
 * all registered listeners.//from  w  ww  . j a  v a 2 s  . c o m
 *
 * @param index  the axis index.
 * @param axis  the axis.
 * @param notify  notify listeners?
 */
public void setDomainAxis(int index, ValueAxis axis, boolean notify) {
    ValueAxis existing = getDomainAxis(index);
    if (existing != null) {
        existing.removeChangeListener(this);
    }
    if (axis != null) {
        axis.setPlot(this);
    }
    this.domainAxes.set(index, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    if (notify) {
        notifyListeners(new PlotChangeEvent(this));
    }
}

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

/**
 * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to
 * all registered listeners.//from  w  w w. j  a v  a2s  .co  m
 *
 * @param axis  the axis (<code>null</code> permitted).
 *
 */
public void setRangeAxis(ValueAxis axis) {

    if (axis != null) {
        axis.setPlot(this);
    }

    // plot is likely registered as a listener with the existing axis...
    ValueAxis existing = getRangeAxis();
    if (existing != null) {
        existing.removeChangeListener(this);
    }

    this.rangeAxes.set(0, axis);
    if (axis != null) {
        axis.configure();
        axis.addChangeListener(this);
    }
    notifyListeners(new PlotChangeEvent(this));

}

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

/**
 * Creates a new plot.//from   w w w. j av  a 2  s . c  o  m
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param domainAxis  the domain axis (<code>null</code> permitted).
 * @param rangeAxis  the range axis (<code>null</code> permitted).
 * @param renderer  the renderer (<code>null</code> permitted).
 */
public MyXYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) {

    super();

    this.orientation = PlotOrientation.VERTICAL;
    this.weight = 1; // only relevant when this is a subplot
    this.axisOffset = RectangleInsets.ZERO_INSETS;

    // allocate storage for datasets, axes and renderers (all optional)
    this.domainAxes = new ObjectList();
    this.domainAxisLocations = new ObjectList();
    this.foregroundDomainMarkers = new HashMap();
    this.backgroundDomainMarkers = new HashMap();

    this.rangeAxes = new ObjectList();
    this.rangeAxisLocations = new ObjectList();
    this.foregroundRangeMarkers = new HashMap();
    this.backgroundRangeMarkers = new HashMap();

    this.datasets = new ObjectList();
    this.renderers = new ObjectList();

    this.datasetToDomainAxisMap = new TreeMap();
    this.datasetToRangeAxisMap = new TreeMap();

    this.datasets.set(0, dataset);
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.renderers.set(0, renderer);
    if (renderer != null) {
        renderer.setPlot(this);
        renderer.addChangeListener(this);
    }

    this.domainAxes.set(0, domainAxis);
    this.mapDatasetToDomainAxis(0, 0);
    if (domainAxis != null) {
        domainAxis.setPlot(this);
        domainAxis.addChangeListener(this);
    }
    this.domainAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT);

    this.rangeAxes.set(0, rangeAxis);
    this.mapDatasetToRangeAxis(0, 0);
    if (rangeAxis != null) {
        rangeAxis.setPlot(this);
        rangeAxis.addChangeListener(this);
    }
    this.rangeAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT);

    configureDomainAxes();
    configureRangeAxes();

    this.domainGridlinesVisible = true;
    this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT;

    this.rangeGridlinesVisible = true;
    this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE;
    this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT;

    this.rangeZeroBaselineVisible = false;
    this.rangeZeroBaselinePaint = Color.black;
    this.rangeZeroBaselineStroke = new BasicStroke(0.5f);

    this.domainCrosshairVisible = false;
    this.domainCrosshairValue = 0.0;
    this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
    this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;

    this.rangeCrosshairVisible = false;
    this.rangeCrosshairValue = 0.0;
    this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
    this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;

    this.annotations = new java.util.ArrayList();

}