xyplot.java

来自「JfreeChart 常用图表例子」· Java 代码 · 共 1,937 行 · 第 1/5 页

JAVA
1,937
字号
     *     * @return The location (never <code>null</code>).     */    public AxisLocation getDomainAxisLocation(int index) {        AxisLocation result = null;        if (index < this.domainAxisLocations.size()) {            result = (AxisLocation) this.domainAxisLocations.get(index);        }        if (result == null) {            result = AxisLocation.getOpposite(getDomainAxisLocation());        }        return result;    }    /**     * Sets the location for a domain axis and sends a {@link PlotChangeEvent}     * to all registered listeners.     *     * @param index  the axis index.     * @param location  the location (<code>null</code> permitted).     */    public void setDomainAxisLocation(int index, AxisLocation location) {        this.domainAxisLocations.set(index, location);        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the edge for a domain axis.     *     * @param index  the axis index.     *     * @return The edge.     */    public RectangleEdge getDomainAxisEdge(int index) {        AxisLocation location = getDomainAxisLocation(index);        RectangleEdge result = Plot.resolveDomainAxisLocation(            location, this.orientation        );        if (result == null) {            result = RectangleEdge.opposite(getDomainAxisEdge());        }        return result;    }    /**     * Returns the range axis for the plot.  If the range axis for this plot is     * null, then the method will return the parent plot's range axis (if     * there is a parent plot).     *     * @return The range axis.     */    public ValueAxis getRangeAxis() {        return getRangeAxis(0);    }    /**     * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to     * all registered listeners.     *     * @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));    }    /**     * Returns the location of the primary range axis.     *     * @return The location (never <code>null</code>).     */    public AxisLocation getRangeAxisLocation() {        return (AxisLocation) this.rangeAxisLocations.get(0);    }    /**     * Sets the location of the primary range axis and sends a     * {@link PlotChangeEvent} to all registered listeners.     *     * @param location  the location (<code>null</code> not permitted).     */    public void setRangeAxisLocation(AxisLocation location) {        // defer argument checking...        setRangeAxisLocation(location, true);    }    /**     * Sets the location of the primary range axis and, if requested, sends a     * {@link PlotChangeEvent} to all registered listeners.     *     * @param location  the location (<code>null</code> not permitted).     * @param notify  notify listeners?     */    public void setRangeAxisLocation(AxisLocation location, boolean notify) {        if (location == null) {            throw new IllegalArgumentException("Null 'location' argument.");        }        this.rangeAxisLocations.set(0, location);        if (notify) {            notifyListeners(new PlotChangeEvent(this));        }    }    /**     * Returns the edge for the primary range axis.     *     * @return The range axis edge.     */    public RectangleEdge getRangeAxisEdge() {        return Plot.resolveRangeAxisLocation(            getRangeAxisLocation(), this.orientation        );    }    /**     * Returns a range axis.     *     * @param index  the axis index.     *     * @return The axis (<code>null</code> possible).     */    public ValueAxis getRangeAxis(int index) {        ValueAxis result = null;        if (index < this.rangeAxes.size()) {            result = (ValueAxis) this.rangeAxes.get(index);        }        if (result == null) {            Plot parent = getParent();            if (parent instanceof XYPlot) {                XYPlot xy = (XYPlot) parent;                result = xy.getRangeAxis(index);            }        }        return result;    }    /**     * Sets a range axis and sends a {@link PlotChangeEvent} to all registered     * listeners.     *     * @param index  the axis index.     * @param axis  the axis (<code>null</code> permitted).     */    public void setRangeAxis(int index, ValueAxis axis) {        setRangeAxis(index, axis, true);    }         /**     * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to      * all registered listeners.     *     * @param index  the axis index.     * @param axis  the axis (<code>null</code> permitted).     */    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));        }    }    /**     * Sets the range axes for this plot and sends a {@link PlotChangeEvent}     * to all registered listeners.     *      * @param axes  the axes.     */    public void setRangeAxes(ValueAxis[] axes) {        for (int i = 0; i < axes.length; i++) {            setRangeAxis(i, axes[i], false);           }        notifyListeners(new PlotChangeEvent(this));    }        /**     * Returns the number of range axes.     *     * @return The axis count.     */    public int getRangeAxisCount() {        return this.rangeAxes.size();    }    /**     * Clears the range axes from the plot and sends a {@link PlotChangeEvent}     * to all registered listeners.     */    public void clearRangeAxes() {        for (int i = 0; i < this.rangeAxes.size(); i++) {            ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);            if (axis != null) {                axis.removeChangeListener(this);            }        }        this.rangeAxes.clear();        notifyListeners(new PlotChangeEvent(this));    }    /**     * Configures the range axes.     */    public void configureRangeAxes() {        for (int i = 0; i < this.rangeAxes.size(); i++) {            ValueAxis axis = (ValueAxis) this.rangeAxes.get(i);            if (axis != null) {                axis.configure();            }        }    }    /**     * Returns the location for a range axis.  If this hasn't been set     * explicitly, the method returns the location that is opposite to the     * primary range axis location.     *     * @param index  the axis index.     *     * @return The location (never <code>null</code>).     */    public AxisLocation getRangeAxisLocation(int index) {        AxisLocation result = null;        if (index < this.rangeAxisLocations.size()) {            result = (AxisLocation) this.rangeAxisLocations.get(index);        }        if (result == null) {            result = AxisLocation.getOpposite(getRangeAxisLocation());        }        return result;    }    /**     * Sets the location for a range axis and sends a {@link PlotChangeEvent}     * to all registered listeners.     *     * @param index  the axis index.     * @param location  the location (<code>null</code> permitted).     */    public void setRangeAxisLocation(int index, AxisLocation location) {        this.rangeAxisLocations.set(index, location);        notifyListeners(new PlotChangeEvent(this));    }    /**     * Returns the edge for a range axis.     *     * @param index  the axis index.     *     * @return The edge.     */    public RectangleEdge getRangeAxisEdge(int index) {        AxisLocation location = getRangeAxisLocation(index);        RectangleEdge result = Plot.resolveRangeAxisLocation(            location, this.orientation        );        if (result == null) {            result = RectangleEdge.opposite(getRangeAxisEdge());        }        return result;    }    /**     * Returns the primary dataset for the plot.     *     * @return The primary dataset (possibly <code>null</code>).     */    public XYDataset getDataset() {        return getDataset(0);    }    /**     * Returns a dataset.     *     * @param index  the dataset index.     *     * @return The dataset (possibly <code>null</code>).     */    public XYDataset getDataset(int index) {        XYDataset result = null;        if (this.datasets.size() > index) {            result = (XYDataset) this.datasets.get(index);        }        return result;    }    /**     * Sets the primary dataset for the plot, replacing the existing dataset if     * there is one.     *     * @param dataset  the dataset (<code>null</code> permitted).     */    public void setDataset(XYDataset dataset) {        setDataset(0, dataset);    }    /**     * Sets a dataset for the plot.     *     * @param index  the dataset index.     * @param dataset  the dataset (<code>null</code> permitted).     */    public void setDataset(int index, XYDataset dataset) {        XYDataset existing = getDataset(index);        if (existing != null) {            existing.removeChangeListener(this);        }        this.datasets.set(index, dataset);        if (dataset != null) {            dataset.addChangeListener(this);        }        // send a dataset change event to self...        DatasetChangeEvent event = new DatasetChangeEvent(this, dataset);        datasetChanged(event);    }    /**     * Returns the number of datasets.     *     * @return The number of datasets.     */    public int getDatasetCount() {        return this.datasets.size();    }    /**     * Returns the index of the specified dataset, or <code>-1</code> if the     * dataset does not belong to the plot.     *     * @param dataset  the dataset (<code>null</code> not permitted).     *     * @return The index.     */    public int indexOf(XYDataset dataset) {        int result = -1;        for (int i = 0; i < this.datasets.size(); i++) {            if (dataset == this.datasets.get(i)) {                result = i;                break;            }        }        return result;    }    /**     * Maps a dataset to a particular domain axis.  All data will be plotted     * against axis zero by default, no mapping is required for this case.     *     * @param index  the dataset index (zero-based).     * @param axisIndex  the axis index.     */    public void mapDatasetToDomainAxis(int index, int axisIndex) {        this.datasetToDomainAxisMap.put(            new Integer(index), new Integer(axisIndex)        );        // fake a dataset change event to update axes...        datasetChanged(new DatasetChangeEvent(this, getDataset(index)));    }    /**

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?