📄 plot.java
字号:
throw new IllegalArgumentException(
"The 'alpha' value must be in the range 0.0f to 1.0f.");
if (this.backgroundImageAlpha != alpha) {
this.backgroundImageAlpha = alpha;
this.notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the flag that controls whether or not the plot outline is
* drawn. The default value is <code>true</code>. Note that for
* historical reasons, the plot's outline paint and stroke can take on
* <code>null</code> values, in which case the outline will not be drawn
* even if this flag is set to <code>true</code>.
*
* @return The outline visibility flag.
*
* @since 1.0.6
*
* @see #setOutlineVisible(boolean)
*/
public boolean isOutlineVisible() {
return this.outlineVisible;
}
/**
* Sets the flag that controls whether or not the plot's outline is
* drawn, and sends a {@link PlotChangeEvent} to all registered listeners.
*
* @param visible the new flag value.
*
* @since 1.0.6
*
* @see #isOutlineVisible()
*/
public void setOutlineVisible(boolean visible) {
this.outlineVisible = visible;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the stroke used to outline the plot area.
*
* @return The stroke (possibly <code>null</code>).
*
* @see #setOutlineStroke(Stroke)
*/
public Stroke getOutlineStroke() {
return this.outlineStroke;
}
/**
* Sets the stroke used to outline the plot area and sends a
* {@link PlotChangeEvent} to all registered listeners. If you set this
* attribute to <code>null</code>, no outline will be drawn.
*
* @param stroke the stroke (<code>null</code> permitted).
*
* @see #getOutlineStroke()
*/
public void setOutlineStroke(Stroke stroke) {
if (stroke == null) {
if (this.outlineStroke != null) {
this.outlineStroke = null;
notifyListeners(new PlotChangeEvent(this));
}
}
else {
if (this.outlineStroke != null) {
if (this.outlineStroke.equals(stroke)) {
return; // nothing to do
}
}
this.outlineStroke = stroke;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the color used to draw the outline of the plot area.
*
* @return The color (possibly <code>null<code>).
*
* @see #setOutlinePaint(Paint)
*/
public Paint getOutlinePaint() {
return this.outlinePaint;
}
/**
* Sets the paint used to draw the outline of the plot area and sends a
* {@link PlotChangeEvent} to all registered listeners. If you set this
* attribute to <code>null</code>, no outline will be drawn.
*
* @param paint the paint (<code>null</code> permitted).
*
* @see #getOutlinePaint()
*/
public void setOutlinePaint(Paint paint) {
if (paint == null) {
if (this.outlinePaint != null) {
this.outlinePaint = null;
notifyListeners(new PlotChangeEvent(this));
}
}
else {
if (this.outlinePaint != null) {
if (this.outlinePaint.equals(paint)) {
return; // nothing to do
}
}
this.outlinePaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the alpha-transparency for the plot foreground.
*
* @return The alpha-transparency.
*
* @see #setForegroundAlpha(float)
*/
public float getForegroundAlpha() {
return this.foregroundAlpha;
}
/**
* Sets the alpha-transparency for the plot and sends a
* {@link PlotChangeEvent} to all registered listeners.
*
* @param alpha the new alpha transparency.
*
* @see #getForegroundAlpha()
*/
public void setForegroundAlpha(float alpha) {
if (this.foregroundAlpha != alpha) {
this.foregroundAlpha = alpha;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the legend items for the plot. By default, this method returns
* <code>null</code>. Subclasses should override to return a
* {@link LegendItemCollection}.
*
* @return The legend items for the plot (possibly <code>null</code>).
*/
public LegendItemCollection getLegendItems() {
return null;
}
/**
* Registers an object for notification of changes to the plot.
*
* @param listener the object to be registered.
*
* @see #removeChangeListener(PlotChangeListener)
*/
public void addChangeListener(PlotChangeListener listener) {
this.listenerList.add(PlotChangeListener.class, listener);
}
/**
* Unregisters an object for notification of changes to the plot.
*
* @param listener the object to be unregistered.
*
* @see #addChangeListener(PlotChangeListener)
*/
public void removeChangeListener(PlotChangeListener listener) {
this.listenerList.remove(PlotChangeListener.class, listener);
}
/**
* Notifies all registered listeners that the plot has been modified.
*
* @param event information about the change event.
*/
public void notifyListeners(PlotChangeEvent event) {
Object[] listeners = this.listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == PlotChangeListener.class) {
((PlotChangeListener) listeners[i + 1]).plotChanged(event);
}
}
}
/**
* Draws the plot within the specified area. The anchor is a point on the
* chart that is specified externally (for instance, it may be the last
* point of the last mouse click performed by the user) - plots can use or
* ignore this value as they see fit.
* <br><br>
* Subclasses need to provide an implementation of this method, obviously.
*
* @param g2 the graphics device.
* @param area the plot area.
* @param anchor the anchor point (<code>null</code> permitted).
* @param parentState the parent state (if any).
* @param info carries back plot rendering info.
*/
public abstract void draw(Graphics2D g2,
Rectangle2D area,
Point2D anchor,
PlotState parentState,
PlotRenderingInfo info);
/**
* Draws the plot background (the background color and/or image).
* <P>
* This method will be called during the chart drawing process and is
* declared public so that it can be accessed by the renderers used by
* certain subclasses. You shouldn't need to call this method directly.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
public void drawBackground(Graphics2D g2, Rectangle2D area) {
// some subclasses override this method completely, so don't put
// anything here that *must* be done
fillBackground(g2, area);
drawBackgroundImage(g2, area);
}
/**
* Fills the specified area with the background paint.
*
* @param g2 the graphics device.
* @param area the area.
*
* @see #getBackgroundPaint()
* @see #getBackgroundAlpha()
* @see #fillBackground(Graphics2D, Rectangle2D, PlotOrientation)
*/
protected void fillBackground(Graphics2D g2, Rectangle2D area) {
fillBackground(g2, area, PlotOrientation.VERTICAL);
}
/**
* Fills the specified area with the background paint. If the background
* paint is an instance of <code>GradientPaint</code>, the gradient will
* run in the direction suggested by the plot's orientation.
*
* @param g2 the graphics target.
* @param area the plot area.
* @param orientation the plot orientation (<code>null</code> not
* permitted).
*
* @since 1.0.6
*/
protected void fillBackground(Graphics2D g2, Rectangle2D area,
PlotOrientation orientation) {
if (orientation == null) {
throw new IllegalArgumentException("Null 'orientation' argument.");
}
if (this.backgroundPaint == null) {
return;
}
Paint p = this.backgroundPaint;
if (p instanceof GradientPaint) {
GradientPaint gp = (GradientPaint) p;
if (orientation == PlotOrientation.VERTICAL) {
p = new GradientPaint((float) area.getCenterX(),
(float) area.getMaxY(), gp.getColor1(),
(float) area.getCenterX(), (float) area.getMinY(),
gp.getColor2());
}
else if (orientation == PlotOrientation.HORIZONTAL) {
p = new GradientPaint((float) area.getMinX(),
(float) area.getCenterY(), gp.getColor1(),
(float) area.getMaxX(), (float) area.getCenterY(),
gp.getColor2());
}
}
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.backgroundAlpha));
g2.setPaint(p);
g2.fill(area);
g2.setComposite(originalComposite);
}
/**
* Draws the background image (if there is one) aligned within the
* specified area.
*
* @param g2 the graphics device.
* @param area the area.
*
* @see #getBackgroundImage()
* @see #getBackgroundImageAlignment()
* @see #getBackgroundImageAlpha()
*/
public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
if (this.backgroundImage != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.backgroundImageAlpha));
Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
this.backgroundImage.getWidth(null),
this.backgroundImage.getHeight(null));
Align.align(dest, area, this.backgroundImageAlignment);
g2.drawImage(this.backgroundImage, (int) dest.getX(),
(int) dest.getY(), (int) dest.getWidth() + 1,
(int) dest.getHeight() + 1, null);
g2.setComposite(originalComposite);
}
}
/**
* Draws the plot outline. This method will be called during the chart
* drawing process and is declared public so that it can be accessed by the
* renderers used by certain subclasses. You shouldn't need to call this
* method directly.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
public void drawOutline(Graphics2D g2, Rectangle2D area) {
if (!this.outlineVisible) {
return;
}
if ((this.outlineStroke != null) && (this.outlinePaint != null)) {
g2.setStroke(this.outlineStroke);
g2.setPaint(this.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);
TextBlock block = TextUtilities.createTextBlock(
this.noDataMessage, this.noDataMessageFont,
this.noDataMessagePaint, 0.9f * (float) area.getWidth(),
new G2TextMeasurer(g2));
block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(),
TextBlockAnchor.CENTER);
}
g2.setClip(savedClip);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -