?? plot.java
字號:
g2.setPaint(outlinePaint);
g2.draw(area);
}
}
/**
* Draws a message to state that there is no data to plot.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) {
Shape savedClip = g2.getClip();
g2.clip(area);
String message = this.noDataMessage;
if (message != null) {
g2.setFont(this.noDataMessageFont);
g2.setPaint(this.noDataMessagePaint);
FontRenderContext frc = g2.getFontRenderContext();
Rectangle2D bounds = noDataMessageFont.getStringBounds(message, frc);
float x = (float) (area.getX() + area.getWidth() / 2 - bounds.getWidth() / 2);
float y = (float) (area.getMinY() + (area.getHeight() / 2) - (bounds.getHeight() / 2));
g2.drawString(message, x, y);
}
g2.clip(savedClip);
}
/**
* Handles a 'click' on the plot. Since the plot does not maintain any
* information about where it has been drawn, the plot area is supplied as
* an argument.
*
* @param x the x coordinate.
* @param y the y coordinate.
* @param info an object for collecting information about the drawing of the chart.
*/
public void handleClick(int x, int y, ChartRenderingInfo info) {
}
/**
* 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);
notifyListeners(newEvent);
}
/**
* 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;
}
/**
* Returns the data area ratio.
*
* @return The ratio.
*/
public double getDataAreaRatio() {
return dataAreaRatio;
}
/**
* Sets the data area ratio.
*
* @param ratio the ratio.
*/
public void setDataAreaRatio(double ratio) {
this.dataAreaRatio = ratio;
}
/**
* Tests this plot for equality with another object.
*
* @param obj the object.
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof Plot) {
Plot p = (Plot) obj;
boolean b5 = ObjectUtils.equal(this.noDataMessage, p.noDataMessage);
boolean b6 = ObjectUtils.equal(this.noDataMessageFont, p.noDataMessageFont);
boolean b7 = ObjectUtils.equal(this.noDataMessagePaint, p.noDataMessagePaint);
boolean b8 = ObjectUtils.equal(this.insets, p.insets);
boolean b9 = ObjectUtils.equal(this.outlineStroke, p.outlineStroke);
boolean b10 = ObjectUtils.equal(this.outlinePaint, p.outlinePaint);
boolean b11 = ObjectUtils.equal(this.backgroundPaint, p.backgroundPaint);
boolean b12 = ObjectUtils.equal(this.backgroundImage, p.backgroundImage);
boolean b13 = (this.backgroundImageAlignment == p.backgroundImageAlignment);
boolean b14 = (this.foregroundAlpha == p.foregroundAlpha);
boolean b15 = (this.backgroundAlpha == p.backgroundAlpha);
return b5 && b6 && b7 && b8 && b9
&& b10 && b11 && b12 && b13 && b14 && b15;
}
return false;
}
/**
* Creates a clone of the plot.
*
* @return A clone.
*
* @throws CloneNotSupportedException if some component of the plot does not support cloning.
*/
protected Object clone() throws CloneNotSupportedException {
Plot clone = (Plot) super.clone();
//private Plot parent <-- don't clone the parent plot
clone.datasetGroup = (DatasetGroup) ObjectUtils.clone(this.datasetGroup);
//private String noDataMessage <-- immutable
//private Font noDataMessageFont <-- immutable
//private transient Paint noDataMessagePaint <-- immutable
//private Insets insets <-- immutable
//private transient Stroke outlineStroke <-- immutable
//private transient Paint outlinePaint <-- immutable
//private transient Paint backgroundPaint <-- immutable
//private transient Image backgroundImage <-- ???
//private int backgroundImageAlignment<-- primitive
//private float foregroundAlpha <-- primitive
//private float backgroundAlpha <-- primitive
clone.drawingSupplier = (DrawingSupplier) ObjectUtils.clone(this.drawingSupplier);
//private transient EventListenerList listenerList <-- ???
//private double dataAreaRatio <-- primitive
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.
* @param orientation the orientation.
*
* @return The edge for the domain axis.
*/
public static RectangleEdge resolveDomainAxisLocation(AxisLocation location,
PlotOrientation orientation) {
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 {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.TOP;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.RIGHT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.LEFT;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.BOTTOM;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
return result;
}
/**
* Resolves a domain axis location for a given plot orientation.
*
* @param location the location.
* @param orientation the orientation.
*
* @return The edge for the domain axis.
*/
public static RectangleEdge resolveRangeAxisLocation(AxisLocation location,
PlotOrientation orientation) {
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 {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.TOP_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.TOP;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.BOTTOM_OR_RIGHT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.RIGHT;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
else if (location == AxisLocation.BOTTOM_OR_LEFT) {
if (orientation == PlotOrientation.HORIZONTAL) {
result = RectangleEdge.BOTTOM;
}
else if (orientation == PlotOrientation.VERTICAL) {
result = RectangleEdge.LEFT;
}
else {
throw new IllegalStateException("XYPlot.resolveDomainAxisLocation(...)");
}
}
return result;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -