📄 xyplot.java
字号:
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).
*
* @see #getRangeAxis(int)
*/
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).
* @param notify notify listeners?
*
* @see #getRangeAxis(int)
*/
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) {
fireChangeEvent();
}
}
/**
* Sets the range axes for this plot and sends a {@link PlotChangeEvent}
* to all registered listeners.
*
* @param axes the axes (<code>null</code> not permitted).
*
* @see #setDomainAxes(ValueAxis[])
*/
public void setRangeAxes(ValueAxis[] axes) {
for (int i = 0; i < axes.length; i++) {
setRangeAxis(i, axes[i], false);
}
fireChangeEvent();
}
/**
* Returns the number of range axes.
*
* @return The axis count.
*
* @see #getDomainAxisCount()
*/
public int getRangeAxisCount() {
return this.rangeAxes.size();
}
/**
* Clears the range axes from the plot and sends a {@link PlotChangeEvent}
* to all registered listeners.
*
* @see #clearDomainAxes()
*/
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();
fireChangeEvent();
}
/**
* Configures the range axes.
*
* @see #configureDomainAxes()
*/
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>).
*
* @see #setRangeAxisLocation(int, AxisLocation)
*/
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).
*
* @see #getRangeAxisLocation(int)
*/
public void setRangeAxisLocation(int index, AxisLocation location) {
// delegate...
setRangeAxisLocation(index, location, true);
}
/**
* Sets the axis location for a domain axis and, if requested, sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param index the axis index.
* @param location the location (<code>null</code> not permitted for
* index 0).
* @param notify notify listeners?
*
* @since 1.0.5
*
* @see #getRangeAxisLocation(int)
* @see #setDomainAxisLocation(int, AxisLocation, boolean)
*/
public void setRangeAxisLocation(int index, AxisLocation location,
boolean notify) {
if (index == 0 && location == null) {
throw new IllegalArgumentException(
"Null 'location' for index 0 not permitted.");
}
this.rangeAxisLocations.set(index, location);
if (notify) {
fireChangeEvent();
}
}
/**
* Returns the edge for a range axis.
*
* @param index the axis index.
*
* @return The edge.
*
* @see #getRangeAxisLocation(int)
* @see #getOrientation()
*/
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>).
*
* @see #getDataset(int)
* @see #setDataset(XYDataset)
*/
public XYDataset getDataset() {
return getDataset(0);
}
/**
* Returns a dataset.
*
* @param index the dataset index.
*
* @return The dataset (possibly <code>null</code>).
*
* @see #setDataset(int, XYDataset)
*/
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).
*
* @see #getDataset()
* @see #setDataset(int, XYDataset)
*/
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).
*
* @see #getDataset(int)
*/
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.
*
* @see #mapDatasetToRangeAxis(int, int)
*/
public void mapDatasetToDomainAxis(int index, int axisIndex) {
List axisIndices = new java.util.ArrayList(1);
axisIndices.add(new Integer(axisIndex));
mapDatasetToDomainAxes(index, axisIndices);
}
/**
* Maps the specified dataset to the axes in the list. Note that the
* conversion of data values into Java2D space is always performed using
* the first axis in the list.
*
* @param index the dataset index (zero-based).
* @param axisIndices the axis indices (<code>null</code> permitted).
*
* @since 1.0.12
*/
public void mapDatasetToDomainAxes(int index, List axisIndices) {
if (index < 0) {
throw new IllegalArgumentException("Requires 'index' >= 0.");
}
checkAxisIndices(axisIndices);
Integer key = new Integer(index);
this.datasetToDomainAxesMap.put(key, new ArrayList(axisIndices));
// fake a dataset change event to update axes...
datasetChanged(new DatasetChangeEvent(this, getDataset(index)));
}
/**
* Maps a dataset to a particular range 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.
*
* @see #mapDatasetToDomainAxis(int, int)
*/
public void mapDatasetToRangeAxis(int index, int axisIndex) {
List axisIndices = new java.util.ArrayList(1);
axisIndices.add(new Integer(axisIndex));
mapDatasetToRangeAxes(index, axisIndices);
}
/**
* Maps the specified dataset to the axes in the list. Note that the
* conversion of data values into Java2D space is always performed using
* the first axis in the list.
*
* @param index the dataset index (zero-based).
* @param axisIndices the axis indices (<code>null</code> permitted).
*
* @since 1.0.12
*/
public void mapDatasetToRangeAxes(int index, List axisIndices) {
if (index < 0) {
throw new IllegalArgumentException("Requires 'index' >= 0.");
}
checkAxisIndices(axisIndices);
Integer key = new Integer(index);
this.datasetToRangeAxesMap.put(key, new ArrayList(axisIndices));
// fake a dataset change event to update axes...
datasetChanged(new DatasetChangeEvent(this, getDataset(index)));
}
/**
* This method is used to perform argument checking on the list of
* axis indices passed to mapDatasetToDomainAxes() and
* mapDatasetToRangeAxes().
*
* @param indices the list of indices (<code>null</code> permitted).
*/
private void checkAxisIndices(List indices) {
// axisIndices can be:
// 1. null;
// 2. non-empty, containing only Integer objects that are unique.
if (indices == null) {
return; // OK
}
int count = indices.size();
if (count == 0) {
throw new IllegalArgumentException("Empty list not permitted.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -