📄 xyplot.java
字号:
}
this.rangeAxisLocation = AxisLocation.TOP_OR_LEFT;
this.renderer = renderer;
if (renderer != null) {
renderer.setPlot(this);
renderer.addPropertyChangeListener(this);
}
this.domainGridlinesVisible = true;
this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT;
this.rangeGridlinesVisible = true;
this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE;
this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT;
this.domainCrosshairVisible = false;
this.domainCrosshairValue = 0.0;
this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;
this.rangeCrosshairVisible = false;
this.rangeCrosshairValue = 0.0;
this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE;
this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT;
this.axesAtTop = new ArrayList();
this.axesAtBottom = new ArrayList();
this.axesAtLeft = new ArrayList();
this.axesAtRight = new ArrayList();
}
/**
* Returns the plot type as a string.
*
* @return a short string describing the type of plot.
*/
public String getPlotType() {
return "XY Plot";
}
/**
* Returns the orientation of the plot.
*
* @return The orientation of the plot.
*/
public PlotOrientation getOrientation() {
return this.orientation;
}
/**
* Sets the orientation for the plot.
*
* @param orientation the orientation (<code>null</code> not allowed).
*/
public void setOrientation(PlotOrientation orientation) {
if (orientation == null) {
throw new IllegalArgumentException("XYPlot.setOrientation(...): null not allowed.");
}
if (orientation != this.orientation) {
this.orientation = orientation;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the axis offset.
*
* @return The axis offset.
*/
public Spacer getAxisOffset() {
return this.axisOffset;
}
/**
* Sets the axis offsets (gap between the data area and the axes).
*
* @param offset the offset.
*/
public void setAxisOffset(Spacer offset) {
this.axisOffset = offset;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the domain axis for the plot. If the domain axis for this plot
* is null, then the method will return the parent plot's domain axis (if
* there is a parent plot).
*
* @return The domain axis.
*/
public ValueAxis getDomainAxis() {
ValueAxis result = this.domainAxis;
if (result == null) {
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getDomainAxis();
}
}
return result;
}
/**
* Sets the domain axis for the plot.
*
* @param axis the new axis.
*/
public void setDomainAxis(ValueAxis axis) {
if (axis != null) {
try {
axis.setPlot(this);
}
catch (PlotNotCompatibleException e) {
}
axis.addChangeListener(this);
}
// plot is likely registered as a listener with the existing axis...
if (this.domainAxis != null) {
this.domainAxis.removeChangeListener(this);
}
this.domainAxis = axis;
if (axis != null) {
axis.configure();
axis.addChangeListener(this);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the location of the domain axis.
*
* @return the location.
*/
public AxisLocation getDomainAxisLocation() {
return this.domainAxisLocation;
}
/**
* Sets the location of the domain axis.
* <p>
* Use one of the constants <code>LEFT</code>, <code>RIGHT</code>, <code>TOP</code> or
* <code>BOTTOM</code>.
*
* @param location the axis location.
*/
public void setDomainAxisLocation(AxisLocation location) {
setDomainAxisLocation(location, true);
}
/**
* Sets the location of the domain axis (TOP, BOTTOM, LEFT or RIGHT).
*
* @param location the axis location.
* @param notify a flag that controls whether listeners are notified.
*/
public void setDomainAxisLocation(AxisLocation location, boolean notify) {
if (location != this.domainAxisLocation) {
this.domainAxisLocation = location;
if (notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
}
/**
* Returns the edge for the domain axis (taking into account the plot's orientation.
*
* @return The edge.
*/
public RectangleEdge getDomainAxisEdge() {
return Plot.resolveDomainAxisLocation(this.domainAxisLocation, this.orientation);
}
/**
* Returns a secondary domain axis.
*
* @param index the axis index.
*
* @return The axis (<code>null</code> possible).
*/
public ValueAxis getSecondaryDomainAxis(int index) {
ValueAxis result = null;
if (index < this.secondaryDomainAxes.size()) {
result = (ValueAxis) this.secondaryDomainAxes.get(index);
}
if (result == null) {
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getSecondaryDomainAxis(index);
}
}
return result;
}
/**
* Sets a secondary domain axis.
*
* @param index the axis index.
* @param axis the axis.
*/
public void setSecondaryDomainAxis(int index, ValueAxis axis) {
ValueAxis existing = getSecondaryDomainAxis(index);
if (existing != null) {
existing.removeChangeListener(this);
}
if (axis != null) {
try {
axis.setPlot(this);
}
catch (PlotNotCompatibleException e) {
}
}
this.secondaryDomainAxes.set(index, axis);
if (axis != null) {
axis.configure();
axis.addChangeListener(this);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Clears the secondary domain axes from the plot.
*/
public void clearSecondaryDomainAxes() {
for (int i = 0; i < this.secondaryDomainAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.secondaryDomainAxes.get(i);
if (axis != null) {
axis.removeChangeListener(this);
}
}
this.secondaryDomainAxes.clear();
notifyListeners(new PlotChangeEvent(this));
}
/**
* Configures the secondary domain axes.
*/
public void configureSecondaryDomainAxes() {
for (int i = 0; i < this.secondaryDomainAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.secondaryDomainAxes.get(i);
if (axis != null) {
axis.configure();
}
}
}
/**
* Returns the location for a secondary domain axis.
*
* @param index the axis index.
*
* @return The location.
*/
public AxisLocation getSecondaryDomainAxisLocation(int index) {
AxisLocation result = null;
if (index < this.secondaryDomainAxisLocations.size()) {
result = (AxisLocation) this.secondaryDomainAxisLocations.get(index);
}
if (result == null) {
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getSecondaryDomainAxisLocation(index);
}
}
return result;
}
/**
* Sets the location for a secondary domain axis.
*
* @param index the axis index.
* @param location the location.
*/
public void setSecondaryDomainAxisLocation(int index, AxisLocation location) {
this.secondaryDomainAxisLocations.set(index, location);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the edge for a secondary domain axis.
*
* @param index the axis index.
*
* @return The edge.
*/
public RectangleEdge getSecondaryDomainAxisEdge(int index) {
AxisLocation location = getSecondaryDomainAxisLocation(index);
RectangleEdge result = Plot.resolveDomainAxisLocation(location, this.orientation);
if (result == null) {
result = RectangleEdge.opposite(getDomainAxisEdge());
}
return result;
}
/**
* Returns the range axis for the plot. If the range axis for this plot is
* null, then the method will return the parent plot's range axis (if
* there is a parent plot).
*
* @return the range axis.
*/
public ValueAxis getRangeAxis() {
ValueAxis result = this.rangeAxis;
if (result == null) {
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getRangeAxis();
}
}
return result;
}
/**
* Sets the range axis for the plot.
* <P>
* An exception is thrown if the new axis and the plot are not mutually compatible.
*
* @param axis the new axis (null permitted).
*
*/
public void setRangeAxis(ValueAxis axis) {
if (axis != null) {
try {
axis.setPlot(this);
}
catch (PlotNotCompatibleException e) {
}
}
// plot is likely registered as a listener with the existing axis...
if (this.rangeAxis != null) {
this.rangeAxis.removeChangeListener(this);
}
this.rangeAxis = axis;
if (axis != null) {
axis.configure();
axis.addChangeListener(this);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the location of the range axis.
*
* @return the location.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -