📄 plot.java
字号:
* Handles a 'click' on the plot. Since the plot does not maintain any
* information about where it has been drawn, the plot rendering info is
* supplied as an argument.
*
* @param x the x coordinate (in Java2D space).
* @param y the y coordinate (in Java2D space).
* @param info an object containing information about the dimensions of
* the plot.
*/
public void handleClick(int x, int y, PlotRenderingInfo info) {
// provides a 'no action' default
}
/**
* Performs a zoom on the plot. Subclasses should override if zooming is
* appropriate for the type of plot.
*
* @param percent the zoom percentage.
*/
public void zoom(double percent) {
// do nothing by default.
}
/**
* Receives notification of a change to one of the plot's axes.
*
* @param event information about the event (not used here).
*/
public void axisChanged(AxisChangeEvent event) {
notifyListeners(new PlotChangeEvent(this));
}
/**
* Receives notification of a change to the plot's dataset.
* <P>
* The plot reacts by passing on a plot change event to all registered
* listeners.
*
* @param event information about the event (not used here).
*/
public void datasetChanged(DatasetChangeEvent event) {
PlotChangeEvent newEvent = new PlotChangeEvent(this);
newEvent.setType(ChartChangeEventType.DATASET_UPDATED);
notifyListeners(newEvent);
}
/**
* Receives notification of a change to a marker that is assigned to the
* plot.
*
* @param event the event.
*
* @since 1.0.3
*/
public void markerChanged(MarkerChangeEvent event) {
notifyListeners(new PlotChangeEvent(this));
}
/**
* Adjusts the supplied x-value.
*
* @param x the x-value.
* @param w1 width 1.
* @param w2 width 2.
* @param edge the edge (left or right).
*
* @return The adjusted x-value.
*/
protected double getRectX(double x, double w1, double w2,
RectangleEdge edge) {
double result = x;
if (edge == RectangleEdge.LEFT) {
result = result + w1;
}
else if (edge == RectangleEdge.RIGHT) {
result = result + w2;
}
return result;
}
/**
* Adjusts the supplied y-value.
*
* @param y the x-value.
* @param h1 height 1.
* @param h2 height 2.
* @param edge the edge (top or bottom).
*
* @return The adjusted y-value.
*/
protected double getRectY(double y, double h1, double h2,
RectangleEdge edge) {
double result = y;
if (edge == RectangleEdge.TOP) {
result = result + h1;
}
else if (edge == RectangleEdge.BOTTOM) {
result = result + h2;
}
return result;
}
/**
* Tests this plot for equality with another object.
*
* @param obj the object (<code>null</code> permitted).
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Plot)) {
return false;
}
Plot that = (Plot) obj;
if (!ObjectUtilities.equal(this.noDataMessage, that.noDataMessage)) {
return false;
}
if (!ObjectUtilities.equal(
this.noDataMessageFont, that.noDataMessageFont
)) {
return false;
}
if (!PaintUtilities.equal(this.noDataMessagePaint,
that.noDataMessagePaint)) {
return false;
}
if (!ObjectUtilities.equal(this.insets, that.insets)) {
return false;
}
if (this.outlineVisible != that.outlineVisible) {
return false;
}
if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) {
return false;
}
if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) {
return false;
}
if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) {
return false;
}
if (!ObjectUtilities.equal(this.backgroundImage,
that.backgroundImage)) {
return false;
}
if (this.backgroundImageAlignment != that.backgroundImageAlignment) {
return false;
}
if (this.backgroundImageAlpha != that.backgroundImageAlpha) {
return false;
}
if (this.foregroundAlpha != that.foregroundAlpha) {
return false;
}
if (this.backgroundAlpha != that.backgroundAlpha) {
return false;
}
if (!this.drawingSupplier.equals(that.drawingSupplier)) {
return false;
}
return true;
}
/**
* Creates a clone of the plot.
*
* @return A clone.
*
* @throws CloneNotSupportedException if some component of the plot does not
* support cloning.
*/
public Object clone() throws CloneNotSupportedException {
Plot clone = (Plot) super.clone();
// private Plot parent <-- don't clone the parent plot, but take care
// childs in combined plots instead
if (this.datasetGroup != null) {
clone.datasetGroup
= (DatasetGroup) ObjectUtilities.clone(this.datasetGroup);
}
clone.drawingSupplier
= (DrawingSupplier) ObjectUtilities.clone(this.drawingSupplier);
clone.listenerList = new EventListenerList();
return clone;
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
SerialUtilities.writePaint(this.noDataMessagePaint, stream);
SerialUtilities.writeStroke(this.outlineStroke, stream);
SerialUtilities.writePaint(this.outlinePaint, stream);
// backgroundImage
SerialUtilities.writePaint(this.backgroundPaint, stream);
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.noDataMessagePaint = SerialUtilities.readPaint(stream);
this.outlineStroke = SerialUtilities.readStroke(stream);
this.outlinePaint = SerialUtilities.readPaint(stream);
// backgroundImage
this.backgroundPaint = SerialUtilities.readPaint(stream);
this.listenerList = new EventListenerList();
}
/**
* Resolves a domain axis location for a given plot orientation.
*
* @param location the location (<code>null</code> not permitted).
* @param orientation the orientation (<code>null</code> not permitted).
*
* @return The edge (never <code>null</code>).
*/
public static RectangleEdge resolveDomainAxisLocation(
AxisLocation location, PlotOrientation orientation) {
if (location == null) {
throw new IllegalArgumentException("Null 'location' argument.");
}
if (orientation == null) {
throw new IllegalArgumentException("Null 'orientation' argument.");
}
RectangleEdge result = null;
if (location == AxisLocation.TOP_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
}
else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
}
else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
}
else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveDomainAxisLocation()");
}
return result;
}
/**
* Resolves a range axis location for a given plot orientation.
*
* @param location the location (<code>null</code> not permitted).
* @param orientation the orientation (<code>null</code> not permitted).
*
* @return The edge (never <code>null</code>).
*/
public static RectangleEdge resolveRangeAxisLocation(
AxisLocation location, PlotOrientation orientation) {
if (location == null) {
throw new IllegalArgumentException("Null 'location' argument.");
}
if (orientation == null) {
throw new IllegalArgumentException("Null 'orientation' argument.");
}
RectangleEdge result = null;
if (location == AxisLocation.TOP_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
}
else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
}
else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
}
else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
}
// the above should cover all the options...
if (result == null) {
throw new IllegalStateException("resolveRangeAxisLocation()");
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -