📄 categoryplot.java
字号:
* @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(0));
}
return result;
}
/**
* 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();
fireChangeEvent();
}
/**
* 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 primary dataset for the plot.
*
* @return The primary dataset (possibly <code>null</code>).
*
* @see #setDataset(CategoryDataset)
*/
public CategoryDataset getDataset() {
return getDataset(0);
}
/**
* Returns the dataset at the given index.
*
* @param index the dataset index.
*
* @return The dataset (possibly <code>null</code>).
*
* @see #setDataset(int, CategoryDataset)
*/
public CategoryDataset getDataset(int index) {
CategoryDataset result = null;
if (this.datasets.size() > index) {
result = (CategoryDataset) this.datasets.get(index);
}
return result;
}
/**
* Sets the dataset for the plot, replacing the existing dataset, if there
* is one. This method also calls the
* {@link #datasetChanged(DatasetChangeEvent)} method, which adjusts the
* axis ranges if necessary and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param dataset the dataset (<code>null</code> permitted).
*
* @see #getDataset()
*/
public void setDataset(CategoryDataset 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, CategoryDataset dataset) {
CategoryDataset existing = (CategoryDataset) this.datasets.get(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.
*
* @since 1.0.2
*/
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.
*
* @since 1.0.11
*/
public int indexOf(CategoryDataset 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.
*
* @param index the dataset index (zero-based).
* @param axisIndex the axis index (zero-based).
*
* @see #getDomainAxisForDataset(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)));
}
/**
* 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.");
}
HashSet set = new HashSet();
for (int i = 0; i < count; i++) {
Object item = indices.get(i);
if (!(item instanceof Integer)) {
throw new IllegalArgumentException(
"Indices must be Integer instances.");
}
if (set.contains(item)) {
throw new IllegalArgumentException("Indices must be unique.");
}
set.add(item);
}
}
/**
* Returns the domain axis for a dataset. You can change the axis for a
* dataset using the {@link #mapDatasetToDomainAxis(int, int)} method.
*
* @param index the dataset index.
*
* @return The domain axis.
*
* @see #mapDatasetToDomainAxis(int, int)
*/
public CategoryAxis getDomainAxisForDataset(int index) {
if (index < 0) {
throw new IllegalArgumentException("Negative 'index'.");
}
CategoryAxis axis = null;
List axisIndices = (List) this.datasetToDomainAxesMap.get(
new Integer(index));
if (axisIndices != null) {
// the first axis in the list is used for data <--> Java2D
Integer axisIndex = (Integer) axisIndices.get(0);
axis = getDomainAxis(axisIndex.intValue());
}
else {
axis = getDomainAxis(0);
}
return axis;
}
/**
* Maps a dataset to a particular range axis.
*
* @param index the dataset index (zero-based).
* @param axisIndex the axis index (zero-based).
*
* @see #getRangeAxisForDataset(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)));
}
/**
* Returns the range axis for a dataset. You can change the axis for a
* dataset using the {@link #mapDatasetToRangeAxis(int, int)} method.
*
* @param index the dataset index.
*
* @return The range axis.
*
* @see #mapDatasetToRangeAxis(int, int)
*/
public ValueAxis getRangeAxisForDataset(int index) {
if (index < 0) {
throw new IllegalArgumentException("Negative 'index'.");
}
ValueAxis axis = null;
List axisIndices = (List) this.datasetToRangeAxesMap.get(
new Integer(index));
if (axisIndices != null) {
// the first axis in the list is used for data <--> Java2D
Integer axisIndex = (Integer) axisIndices.get(0);
axis = getRangeAxis(axisIndex.intValue());
}
else {
axis = getRangeAxis(0);
}
return axis;
}
/**
* Returns the number of renderer slots for this plot.
*
* @return The number of renderer slots.
*
* @since 1.0.11
*/
public int getRendererCount() {
return this.renderers.size();
}
/**
* Returns a reference to the renderer for the plot.
*
* @return The renderer.
*
* @see #setRenderer(CategoryItemRenderer)
*/
public CategoryItemRenderer getRenderer() {
return getRenderer(0);
}
/**
* Returns the renderer at the given index.
*
* @param index the renderer index.
*
* @return The renderer (possibly <code>null</code>).
*
* @see #setRenderer(int, CategoryItemRenderer)
*/
public CategoryItemRenderer getRenderer(int index) {
CategoryItemRenderer result = null;
if (this.renderers.size() > index) {
result = (CategoryItemRenderer) this.renderers.get(index);
}
return result;
}
/**
* Sets the renderer at index 0 (sometimes referred to as the "primary"
* renderer) and sends a {@link PlotChangeEvent} to all registered
* listeners.
*
* @param renderer the renderer (<code>null</code> permitted.
*
* @see #getRenderer()
*/
public void setRenderer(CategoryItemRenderer renderer) {
setRenderer(0, renderer, true);
}
/**
* Sets the renderer at index 0 (sometimes referred to as the "primary"
* renderer) and, if requested, sends a {@link PlotChangeEvent} to all
* registered listeners.
* <p>
* You can set the renderer to <code>null</code>, but this is not
* recommended because:
* <ul>
* <li>no data will be displayed;</li>
* <li>the plot background will not be painted;</li>
* </ul>
*
* @param renderer the renderer (<code>null</code> permitted).
* @param notify notify listeners?
*
* @see #getRenderer()
*/
public void setRenderer(CategoryItemRenderer renderer, boolean notify) {
setRenderer(0, renderer, notify);
}
/**
* Sets the renderer at the specified index and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param index the index.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -