📄 categoryplot.java
字号:
}
/**
* 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;
Integer key = new Integer(index);
if (layer == Layer.FOREGROUND) {
result = (Collection) this.foregroundRangeMarkers.get(key);
}
else if (layer == Layer.BACKGROUND) {
result = (Collection) this.backgroundRangeMarkers.get(key);
}
if (result != null) {
result = Collections.unmodifiableCollection(result);
}
return result;
}
/**
* Clears all the range markers for the specified renderer.
*
* @param index the renderer index.
*/
public void clearRangeMarkers(int index) {
Integer key = new Integer(index);
if (this.backgroundRangeMarkers != null) {
Collection markers = (Collection) this.backgroundRangeMarkers.get(key);
if (markers != null) {
markers.clear();
}
}
if (this.foregroundRangeMarkers != null) {
Collection markers = (Collection) this.foregroundRangeMarkers.get(key);
if (markers != null) {
markers.clear();
}
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns a flag indicating whether or not the range crosshair is visible.
*
* @return the flag.
*/
public boolean isRangeCrosshairVisible() {
return this.rangeCrosshairVisible;
}
/**
* Sets the flag indicating whether or not the range crosshair is visible.
*
* @param flag the new value of the flag.
*/
public void setRangeCrosshairVisible(boolean flag) {
if (this.rangeCrosshairVisible != flag) {
this.rangeCrosshairVisible = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns a flag indicating whether or not the crosshair should "lock-on"
* to actual data values.
*
* @return the flag.
*/
public boolean isRangeCrosshairLockedOnData() {
return this.rangeCrosshairLockedOnData;
}
/**
* Sets the flag indicating whether or not the range crosshair should "lock-on"
* to actual data values.
*
* @param flag the flag.
*/
public void setRangeCrosshairLockedOnData(boolean flag) {
if (this.rangeCrosshairLockedOnData != flag) {
this.rangeCrosshairLockedOnData = flag;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the range crosshair value.
*
* @return The value.
*/
public double getRangeCrosshairValue() {
return this.rangeCrosshairValue;
}
/**
* Sets the domain crosshair value.
* <P>
* Registered listeners are notified that the plot has been modified, but
* only if the crosshair is visible.
*
* @param value the new value.
*/
public void setRangeCrosshairValue(double value) {
setRangeCrosshairValue(value, true);
}
/**
* Sets the range crosshair value.
* <P>
* Registered listeners are notified that the axis has been modified, but
* only if the crosshair is visible.
*
* @param value the new value.
* @param notify a flag that controls whether or not listeners are notified.
*/
public void setRangeCrosshairValue(double value, boolean notify) {
this.rangeCrosshairValue = value;
if (isRangeCrosshairVisible() && notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the pen-style (<code>Stroke</code>) used to draw the crosshair (if visible).
*
* @return the crosshair stroke.
*/
public Stroke getRangeCrosshairStroke() {
return this.rangeCrosshairStroke;
}
/**
* Sets the pen-style (<code>Stroke</code>) used to draw the crosshairs (if visible).
* A {@link PlotChangeEvent} is sent to all registered listeners.
*
* @param stroke the new crosshair stroke.
*/
public void setRangeCrosshairStroke(Stroke stroke) {
this.rangeCrosshairStroke = stroke;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the range crosshair color.
*
* @return the crosshair color.
*/
public Paint getRangeCrosshairPaint() {
return this.rangeCrosshairPaint;
}
/**
* Sets the Paint used to color the crosshairs (if visible) and notifies
* registered listeners that the axis has been modified.
*
* @param paint the new crosshair paint.
*/
public void setRangeCrosshairPaint(Paint paint) {
this.rangeCrosshairPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the list of annotations.
*
* @return The list of annotations.
*/
public List getAnnotations() {
return this.annotations;
}
/**
* Adds an annotation to the plot.
*
* @param annotation the annotation.
*/
public void addAnnotation(CategoryAnnotation annotation) {
if (this.annotations == null) {
this.annotations = new java.util.ArrayList();
}
this.annotations.add(annotation);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Calculates the space required for the domain axis/axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param space a carrier for the result (<code>null</code> permitted).
*
* @return The required space.
*/
protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea,
AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the domain axis...
if (this.fixedDomainAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT);
}
else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP);
space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM);
}
}
else {
// reserve space for the primary domain axis...
RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
getDomainAxisLocation(), this.orientation
);
if (this.drawSharedDomainAxis) {
space = getDomainAxis().reserveSpace(g2, this, plotArea, domainEdge, space);
}
// reserve space for any domain axes...
for (int i = 0; i < this.domainAxes.size(); i++) {
Axis xAxis = (Axis) this.domainAxes.get(i);
if (xAxis != null) {
RectangleEdge edge = getDomainAxisEdge(i);
space = xAxis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
/**
* Calculates the space required for the range axis/axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
* @param space a carrier for the result (<code>null</code> permitted).
*
* @return The required space.
*/
protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea,
AxisSpace space) {
if (space == null) {
space = new AxisSpace();
}
// reserve some space for the range axis...
if (this.fixedRangeAxisSpace != null) {
if (this.orientation == PlotOrientation.HORIZONTAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP);
space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM);
}
else if (this.orientation == PlotOrientation.VERTICAL) {
space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT);
space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT);
}
}
else {
// reserve space for the range axes (if any)...
for (int i = 0; i < this.rangeAxes.size(); i++) {
Axis yAxis = (Axis) this.rangeAxes.get(i);
if (yAxis != null) {
RectangleEdge edge = getRangeAxisEdge(i);
space = yAxis.reserveSpace(g2, this, plotArea, edge, space);
}
}
}
return space;
}
/**
* Calculates the space required for the axes.
*
* @param g2 the graphics device.
* @param plotArea the plot area.
*
* @return The space required for the axes.
*/
protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) {
AxisSpace space = new AxisSpace();
space = calculateRangeAxisSpace(g2, plotArea, space);
space = calculateDomainAxisSpace(g2, plotArea, space);
return space;
}
/**
* Draws the plot on a Java 2D graphics device (such as the screen or a printer).
* <P>
* At your option, you may supply an instance of {@link PlotRenderingInfo}.
* If you do, it will be populated with information about the drawing,
* including various plot dimensions and tooltip info.
*
* @param g2 the graphics device.
* @param plotArea the area within which the plot (including axes) should be drawn.
* @param parentState the state from the parent plot, if there is one.
* @param state collects info as the chart is drawn (possibly <code>null</code>).
*/
public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState,
PlotRenderingInfo state) {
// if the plot area is too small, just return...
boolean b1 = (plotArea.getWidth() <= MINIMUM_WIDTH_TO_DRAW);
boolean b2 = (plotArea.getHeight() <= MINIMUM_HEIGHT_TO_DRAW);
if (b1 || b2) {
return;
}
// record the plot area...
if (state != null) {
state.setPlotArea(plotArea);
}
// adjust the drawing area for the plot insets (if any)...
Insets insets = getInsets();
if (insets != null) {
plotArea.setRect(
plotArea.getX() + insets.left,
plotArea.getY() + insets.top,
plotArea.getWidth() - insets.left - insets.right,
plotArea.getHeight() - insets.top - insets.bottom
);
}
// calculate the data area...
AxisSpace space = calculateAxisSpace(g2, plotArea);
Rectangle2D dataArea = space.shrink(plotArea, null);
this.axisOffset.trim(dataArea);
if (state != null) {
state.setDataArea(dataArea);
}
// if there is a renderer, it draws the background, otherwise use the default background...
if (getRenderer() != null) {
getRenderer().drawBackground(g2, this, dataArea);
}
else {
drawBackground(g2, dataArea);
}
Map axisStateMap = drawAxes(g2, plotArea, dataArea, state);
drawDomainGridlines(g2, dataArea);
AxisState rangeAxisState = (AxisState) axisStateMap.get(getRangeAxis());
if (rangeAxisState == null) {
if (parentState != null) {
rangeAxisState = (AxisState) parentState.getSharedAxisSt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -