xyplot.java
来自「jfreechart安装程序和使用说明」· Java 代码 · 共 1,821 行 · 第 1/5 页
JAVA
1,821 行
* @param rangeAxis the range axis (<code>null</code> permitted).
* @param renderer the renderer (<code>null</code> permitted).
*/
public XYPlot(XYDataset dataset,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYItemRenderer renderer) {
super();
this.orientation = PlotOrientation.VERTICAL;
this.weight = 1; // only relevant when this is a subplot
this.axisOffset = new Spacer(Spacer.ABSOLUTE, 0.0, 0.0, 0.0, 0.0);
// allocate storage for datasets, axes and renderers (all optional)
this.domainAxes = new ObjectList();
this.domainAxisLocations = new ObjectList();
this.foregroundDomainMarkers = new HashMap();
this.backgroundDomainMarkers = new HashMap();
this.rangeAxes = new ObjectList();
this.rangeAxisLocations = new ObjectList();
this.foregroundRangeMarkers = new HashMap();
this.backgroundRangeMarkers = new HashMap();
this.datasets = new ObjectList();
this.renderers = new ObjectList();
this.domainAxisMap = new ObjectList();
this.rangeAxisMap = new ObjectList();
this.datasets.set(0, dataset);
if (dataset != null) {
dataset.addChangeListener(this);
}
this.renderers.set(0, renderer);
if (renderer != null) {
renderer.setPlot(this);
renderer.addChangeListener(this);
}
this.domainAxes.set(0, domainAxis);
this.mapDatasetToDomainAxis(0, 0);
if (domainAxis != null) {
domainAxis.setPlot(this);
domainAxis.addChangeListener(this);
}
this.domainAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT);
this.rangeAxes.set(0, rangeAxis);
this.mapDatasetToRangeAxis(0, 0);
if (rangeAxis != null) {
rangeAxis.setPlot(this);
rangeAxis.addChangeListener(this);
}
this.rangeAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT);
configureDomainAxes();
configureRangeAxes();
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;
}
/**
* Returns the plot type as a string.
*
* @return a short string describing the type of plot.
*/
public String getPlotType() {
return localizationResources.getString("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() {
return getDomainAxis(0);
}
/**
* Returns a domain axis.
*
* @param index the axis index.
*
* @return The axis (<code>null</code> possible).
*/
public ValueAxis getDomainAxis(int index) {
ValueAxis result = null;
if (index < this.domainAxes.size()) {
result = (ValueAxis) this.domainAxes.get(index);
}
if (result == null) {
Plot parent = getParent();
if (parent instanceof XYPlot) {
XYPlot xy = (XYPlot) parent;
result = xy.getDomainAxis(index);
}
}
return result;
}
/**
* Sets the domain axis for the plot and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param axis the new axis (<code>null</code> permitted).
*/
public void setDomainAxis(ValueAxis axis) {
setDomainAxis(0, axis);
}
/**
* Sets a domain axis and sends a {@link PlotChangeEvent} to all registered listeners.
*
* @param index the axis index.
* @param axis the axis.
*/
public void setDomainAxis(int index, ValueAxis axis) {
ValueAxis existing = getDomainAxis(index);
if (existing != null) {
existing.removeChangeListener(this);
}
if (axis != null) {
axis.setPlot(this);
}
this.domainAxes.set(index, axis);
if (axis != null) {
axis.configure();
axis.addChangeListener(this);
}
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the location of the primary domain axis.
*
* @return The location (never <code>null</code>).
*/
public AxisLocation getDomainAxisLocation() {
return (AxisLocation) this.domainAxisLocations.get(0);
}
/**
* Sets the location of the domain axis and sends a {@link PlotChangeEvent} to all registered
* listeners.
*
* @param location the location (<code>null</code> not permitted).
*/
public void setDomainAxisLocation(AxisLocation location) {
// defer argument checking...
setDomainAxisLocation(location, true);
}
/**
* Sets the location of the domain axis and, if requested, sends a {@link PlotChangeEvent} to
* all registered listeners.
*
* @param location the location (<code>null</code> not permitted).
* @param notify notify listeners?
*/
public void setDomainAxisLocation(AxisLocation location, boolean notify) {
if (location == null) {
throw new IllegalArgumentException("Null 'location' argument.");
}
this.domainAxisLocations.set(0, location);
if (notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the edge for the primary domain axis (taking into account the plot's orientation.
*
* @return The edge.
*/
public RectangleEdge getDomainAxisEdge() {
return Plot.resolveDomainAxisLocation(getDomainAxisLocation(), this.orientation);
}
/**
* Returns the number of domain axes.
*
* @return The axis count.
*/
public int getDomainAxisCount() {
return this.domainAxes.size();
}
/**
* Clears the domain axes from the plot and sends a {@link PlotChangeEvent} to all
* registered listeners.
*/
public void clearDomainAxes() {
for (int i = 0; i < this.domainAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.domainAxes.get(i);
if (axis != null) {
axis.removeChangeListener(this);
}
}
this.domainAxes.clear();
notifyListeners(new PlotChangeEvent(this));
}
/**
* Configures the domain axes.
*/
public void configureDomainAxes() {
for (int i = 0; i < this.domainAxes.size(); i++) {
ValueAxis axis = (ValueAxis) this.domainAxes.get(i);
if (axis != null) {
axis.configure();
}
}
}
/**
* Returns the location for a domain axis. If this hasn't been set explicitly,
* the method returns the location that is opposite to the primary domain axis location.
*
* @param index the axis index.
*
* @return The location (never <code>null</code>).
*/
public AxisLocation getDomainAxisLocation(int index) {
AxisLocation result = null;
if (index < this.domainAxisLocations.size()) {
result = (AxisLocation) this.domainAxisLocations.get(index);
}
if (result == null) {
result = AxisLocation.getOpposite(getDomainAxisLocation());
}
return result;
}
/**
* Sets the location for a domain axis and sends a {@link PlotChangeEvent} to all
* registered listeners.
*
* @param index the axis index.
* @param location the location (<code>null</code> permitted).
*/
public void setDomainAxisLocation(int index, AxisLocation location) {
this.domainAxisLocations.set(index, location);
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the edge for a domain axis.
*
* @param index the axis index.
*
* @return The edge.
*/
public RectangleEdge getDomainAxisEdge(int index) {
AxisLocation location = getDomainAxisLocation(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() {
return getRangeAxis(0);
}
/**
* Sets the range axis for the plot and sends a {@link PlotChangeEvent} to all registered
* listeners.
*
* @param axis the axis (<code>null</code> permitted).
*
*/
public void setRangeAxis(ValueAxis axis) {
if (axis != null) {
axis.setPlot(this);
}
// plot is likely registered as a listener with the existing axis...
ValueAxis existing = getRangeAxis();
if (existing != null) {
existing.removeChangeListener(this);
}
this.rangeAxes.set(0, axis);
if (axis != null) {
axis.configure();
axis.addChangeListener(this);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?