📄 categoryplot.java
字号:
*
* @return The legend items.
*/
public LegendItemCollection getLegendItems() {
LegendItemCollection result = this.fixedLegendItems;
if (result == null) {
result = new LegendItemCollection();
// get the legend items for the datasets...
int count = this.datasets.size();
for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
CategoryDataset dataset = getDataset(datasetIndex);
if (dataset != null) {
CategoryItemRenderer renderer = getRenderer(datasetIndex);
if (renderer != null) {
int seriesCount = dataset.getRowCount();
for (int i = 0; i < seriesCount; i++) {
LegendItem item = renderer.getLegendItem(
datasetIndex, i
);
if (item != null) {
result.add(item);
}
}
}
}
}
}
return result;
}
/**
* Handles a 'click' on the plot by updating the anchor value.
*
* @param x x-coordinate of the click (in Java2D space).
* @param y y-coordinate of the click (in Java2D space).
* @param info information about the plot's dimensions.
*
*/
public void handleClick(int x, int y, PlotRenderingInfo info) {
Rectangle2D dataArea = info.getDataArea();
if (dataArea.contains(x, y)) {
// set the anchor value for the range axis...
double java2D = 0.0;
if (this.orientation == PlotOrientation.HORIZONTAL) {
java2D = x;
}
else if (this.orientation == PlotOrientation.VERTICAL) {
java2D = y;
}
RectangleEdge edge = Plot.resolveRangeAxisLocation(
getRangeAxisLocation(), this.orientation
);
double value = getRangeAxis().java2DToValue(
java2D, info.getDataArea(), edge
);
setAnchorValue(value);
setRangeCrosshairValue(value);
}
}
/**
* Zooms (in or out) on the plot's value axis.
* <p>
* If the value 0.0 is passed in as the zoom percent, the auto-range
* calculation for the axis is restored (which sets the range to include
* the minimum and maximum data values, thus displaying all the data).
*
* @param percent the zoom amount.
*/
public void zoom(double percent) {
if (percent > 0.0) {
double range = getRangeAxis().getRange().getLength();
double scaledRange = range * percent;
getRangeAxis().setRange(
this.anchorValue - scaledRange / 2.0,
this.anchorValue + scaledRange / 2.0
);
}
else {
getRangeAxis().setAutoRange(true);
}
}
/**
* Receives notification of a change to the plot's dataset.
* <P>
* The range axis bounds will be recalculated if necessary.
*
* @param event information about the event (not used here).
*/
public void datasetChanged(DatasetChangeEvent event) {
int count = this.rangeAxes.size();
for (int axisIndex = 0; axisIndex < count; axisIndex++) {
ValueAxis yAxis = getRangeAxis(axisIndex);
if (yAxis != null) {
yAxis.configure();
}
}
if (getParent() != null) {
getParent().datasetChanged(event);
}
else {
PlotChangeEvent e = new PlotChangeEvent(this);
e.setType(ChartChangeEventType.DATASET_UPDATED);
notifyListeners(e);
}
}
/**
* Receives notification of a renderer change event.
*
* @param event the event.
*/
public void rendererChanged(RendererChangeEvent event) {
Plot parent = getParent();
if (parent != null) {
if (parent instanceof RendererChangeListener) {
RendererChangeListener rcl = (RendererChangeListener) parent;
rcl.rendererChanged(event);
}
else {
// this should never happen with the existing code, but throw
// an exception in case future changes make it possible...
throw new RuntimeException(
"The renderer has changed and I don't know what to do!"
);
}
}
else {
configureRangeAxes();
PlotChangeEvent e = new PlotChangeEvent(this);
notifyListeners(e);
}
}
/**
* Adds a marker for display (in the foreground) against the domain axis and
* sends a {@link PlotChangeEvent} to all registered listeners. Typically a
* marker will be drawn by the renderer as a line perpendicular to the
* domain axis, however this is entirely up to the renderer.
*
* @param marker the marker (<code>null</code> not permitted).
*/
public void addDomainMarker(CategoryMarker marker) {
addDomainMarker(marker, Layer.FOREGROUND);
}
/**
* Adds a marker for display against the domain axis and sends a
* {@link PlotChangeEvent} to all registered listeners. Typically a marker
* will be drawn by the renderer as a line perpendicular to the domain axis,
* however this is entirely up to the renderer.
*
* @param marker the marker (<code>null</code> not permitted).
* @param layer the layer (foreground or background) (<code>null</code>
* not permitted).
*/
public void addDomainMarker(CategoryMarker marker, Layer layer) {
addDomainMarker(0, marker, layer);
}
/**
* Adds a marker for display by a particular renderer.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to a domain axis, however this is entirely up to the renderer.
*
* @param index the renderer index.
* @param marker the marker.
* @param layer the layer.
*/
public void addDomainMarker(int index, CategoryMarker marker, Layer layer) {
Collection markers;
if (layer == Layer.FOREGROUND) {
markers = (Collection) this.foregroundDomainMarkers.get(
new Integer(index)
);
if (markers == null) {
markers = new java.util.ArrayList();
this.foregroundDomainMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
else if (layer == Layer.BACKGROUND) {
markers = (Collection) this.backgroundDomainMarkers.get(
new Integer(index)
);
if (markers == null) {
markers = new java.util.ArrayList();
this.backgroundDomainMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the domain markers for the plot and sends a
* {@link PlotChangeEvent} to all registered listeners.
*/
public void clearDomainMarkers() {
if (this.backgroundDomainMarkers != null) {
this.backgroundDomainMarkers.clear();
}
if (this.foregroundDomainMarkers != null) {
this.foregroundDomainMarkers.clear();
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the list of domain markers (read only) for the specified layer.
*
* @param layer the layer (foreground or background).
*
* @return The list of domain markers.
*/
public Collection getDomainMarkers(Layer layer) {
return getDomainMarkers(0, layer);
}
/**
* Returns a collection of domain markers for a particular renderer and
* layer.
*
* @param index the renderer index.
* @param layer the layer.
*
* @return A collection of markers (possibly <code>null</code>).
*/
public Collection getDomainMarkers(int index, Layer layer) {
Collection result = null;
Integer key = new Integer(index);
if (layer == Layer.FOREGROUND) {
result = (Collection) this.foregroundDomainMarkers.get(key);
}
else if (layer == Layer.BACKGROUND) {
result = (Collection) this.backgroundDomainMarkers.get(key);
}
if (result != null) {
result = Collections.unmodifiableCollection(result);
}
return result;
}
/**
* Clears all the domain markers for the specified renderer.
*
* @param index the renderer index.
*/
public void clearDomainMarkers(int index) {
Integer key = new Integer(index);
if (this.backgroundDomainMarkers != null) {
Collection markers
= (Collection) this.backgroundDomainMarkers.get(key);
if (markers != null) {
markers.clear();
}
}
if (this.foregroundDomainMarkers != null) {
Collection markers
= (Collection) this.foregroundDomainMarkers.get(key);
if (markers != null) {
markers.clear();
}
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Adds a marker for display (in the foreground) against the range axis and
* sends a {@link PlotChangeEvent} to all registered listeners. Typically a
* marker will be drawn by the renderer as a line perpendicular to the
* range axis, however this is entirely up to the renderer.
*
* @param marker the marker (<code>null</code> not permitted).
*/
public void addRangeMarker(Marker marker) {
addRangeMarker(marker, Layer.FOREGROUND);
}
/**
* Adds a marker for display against the range axis and sends a
* {@link PlotChangeEvent} to all registered listeners. Typically a marker
* will be drawn by the renderer as a line perpendicular to the range axis,
* however this is entirely up to the renderer.
*
* @param marker the marker (<code>null</code> not permitted).
* @param layer the layer (foreground or background) (<code>null</code>
* not permitted).
*/
public void addRangeMarker(Marker marker, Layer layer) {
addRangeMarker(0, marker, layer);
}
/**
* Adds a marker for display by a particular renderer.
* <P>
* Typically a marker will be drawn by the renderer as a line perpendicular
* to a range axis, however this is entirely up to the renderer.
*
* @param index the renderer index.
* @param marker the marker.
* @param layer the layer.
*/
public void addRangeMarker(int index, Marker marker, Layer layer) {
Collection markers;
if (layer == Layer.FOREGROUND) {
markers = (Collection) this.foregroundRangeMarkers.get(
new Integer(index)
);
if (markers == null) {
markers = new java.util.ArrayList();
this.foregroundRangeMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
else if (layer == Layer.BACKGROUND) {
markers = (Collection) this.backgroundRangeMarkers.get(
new Integer(index)
);
if (markers == null) {
markers = new java.util.ArrayList();
this.backgroundRangeMarkers.put(new Integer(index), markers);
}
markers.add(marker);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears all the range markers for the plot and sends a
* {@link PlotChangeEvent} to all registered listeners.
*/
public void clearRangeMarkers() {
if (this.backgroundRangeMarkers != null) {
this.backgroundRangeMarkers.clear();
}
if (this.foregroundRangeMarkers != null) {
this.foregroundRangeMarkers.clear();
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the list of range markers (read only) for the specified layer.
*
* @param layer the layer (foreground or background).
*
* @return The list of range markers.
*/
public Collection getRangeMarkers(Layer layer) {
return getRangeMarkers(0, layer);
}
/**
* Returns a collection of range markers for a particular renderer and
* layer.
*
* @param index the renderer index.
* @param layer the layer.
*
* @return A collection of markers (possibly <code>null</code>).
*/
public Collection getRangeMarkers(int index, Layer layer) {
Collection result = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -