categoryplot.java
来自「JFreeChart它主要是用来制作各种各样的图表」· Java 代码 · 共 1,851 行 · 第 1/5 页
JAVA
1,851 行
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the stroke used to draw the grid-lines against the range axis.
*
* @return The stroke (never <code>null</code>).
*/
public Stroke getRangeGridlineStroke() {
return this.rangeGridlineStroke;
}
/**
* Sets the stroke used to draw the grid-lines against the range axis and
* sends a {@link PlotChangeEvent} to all registered listeners.
*
* @param stroke the stroke (<code>null</code> not permitted).
*/
public void setRangeGridlineStroke(Stroke stroke) {
if (stroke == null) {
throw new IllegalArgumentException("Null 'stroke' argument.");
}
this.rangeGridlineStroke = stroke;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the paint used to draw the grid-lines against the range axis.
*
* @return The paint (never <code>null</code>).
*/
public Paint getRangeGridlinePaint() {
return this.rangeGridlinePaint;
}
/**
* Sets the paint used to draw the grid lines against the range axis and
* sends a {@link PlotChangeEvent} to all registered listeners.
*
* @param paint the paint (<code>null</code> not permitted).
*/
public void setRangeGridlinePaint(Paint paint) {
if (paint == null) {
throw new IllegalArgumentException("Null 'paint' argument.");
}
this.rangeGridlinePaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the fixed legend items, if any.
*
* @return The legend items (possibly <code>null</code>).
*/
public LegendItemCollection getFixedLegendItems() {
return this.fixedLegendItems;
}
/**
* Sets the fixed legend items for the plot. Leave this set to
* <code>null</code> if you prefer the legend items to be created
* automatically.
*
* @param items the legend items (<code>null</code> permitted).
*/
public void setFixedLegendItems(LegendItemCollection items) {
this.fixedLegendItems = items;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the legend items for the plot. By default, this method creates
* a legend item for each series in each of the datasets. You can change
* this behaviour by overriding this method.
*
* @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 (<code>null</code> not permitted).
* @param layer the layer (<code>null</code> not permitted).
*/
public void addDomainMarker(int index, CategoryMarker marker, Layer layer) {
if (marker == null) {
throw new IllegalArgumentException("Null 'marker' not permitted.");
}
if (layer == null) {
throw new IllegalArgumentException("Null 'layer' not permitted.");
}
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);
}
marker.addChangeListener(this);
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) {
Set keys = this.backgroundDomainMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearDomainMarkers(key.intValue());
}
this.backgroundDomainMarkers.clear();
}
if (this.foregroundDomainMarkers != null) {
Set keys = this.foregroundDomainMarkers.keySet();
Iterator iterator = keys.iterator();
while (iterator.hasNext()) {
Integer key = (Integer) iterator.next();
clearDomainMarkers(key.intValue());
}
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) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
}
if (this.foregroundDomainMarkers != null) {
Collection markers
= (Collection) this.foregroundDomainMarkers.get(key);
if (markers != null) {
Iterator iterator = markers.iterator();
while (iterator.hasNext()) {
Marker m = (Marker) iterator.next();
m.removeChangeListener(this);
}
markers.clear();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?