?? plot.java
字號:
/**
* Returns the insets for the plot area.
*
* @return The insets.
*/
public Insets getInsets() {
return this.insets;
}
/**
* Sets the insets for the plot and notifies registered listeners that the
* plot has been modified.
*
* @param insets the new insets.
*/
public void setInsets(Insets insets) {
this.setInsets(insets, true);
}
/**
* Sets the insets for the plot and, if requested, notifies registered listeners that the
* plot has been modified.
*
* @param insets the new insets.
* @param notify a flag that controls whether the registered listeners are notified.
*/
public void setInsets(Insets insets, boolean notify) {
if (!this.insets.equals(insets)) {
this.insets = insets;
if (notify) {
notifyListeners(new PlotChangeEvent(this));
}
}
}
/**
* Returns the background color of the plot area.
*
* @return The paint (possibly <code>null</code>).
*/
public Paint getBackgroundPaint() {
return this.backgroundPaint;
}
/**
* Sets the background color of the plot area. A {@link PlotChangeEvent} is forwarded to
* all registered listeners.
*
* @param paint the paint (<code>null</code> permitted).
*/
public void setBackgroundPaint(Paint paint) {
if (paint == null) {
if (this.backgroundPaint != null) {
this.backgroundPaint = null;
notifyListeners(new PlotChangeEvent(this));
}
}
else {
if (this.backgroundPaint != null) {
if (this.backgroundPaint.equals(paint)) {
return; // nothing to do
}
}
this.backgroundPaint = paint;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the alpha transparency of the plot area background.
*
* @return the alpha transparency.
*/
public float getBackgroundAlpha() {
return this.backgroundAlpha;
}
/**
* Sets the alpha transparency of the plot area background, and notifies
* registered listeners that the plot has been modified.
*
* @param alpha the new alpha value.
*/
public void setBackgroundAlpha(float alpha) {
if (this.backgroundAlpha != alpha) {
this.backgroundAlpha = alpha;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the drawing supplier for the plot.
*
* @return The drawing supplier.
*/
public DrawingSupplier getDrawingSupplier() {
DrawingSupplier result = null;
Plot p = getParent();
if (p != null) {
return p.getDrawingSupplier();
}
else {
result = this.drawingSupplier;
}
return result;
}
/**
* Sets the drawing supplier for the plot. The drawing supplier is responsible for
* supplying a limitless (possibly repeating) sequence of <code>Paint</code>,
* <code>Stroke</code> and <code>Shape</code> objects that the plot's renderer(s) can use
* to populate its(their) tables.
*
* @param supplier the new supplier.
*/
public void setDrawingSupplier(DrawingSupplier supplier) {
this.drawingSupplier = supplier;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the background image that is used to fill the plot's background area.
*
* @return The image (possibly <code>null</code>).
*/
public Image getBackgroundImage() {
return this.backgroundImage;
}
/**
* Sets the background image for the plot.
*
* @param image the image (<code>null</code> permitted).
*/
public void setBackgroundImage(Image image) {
this.backgroundImage = image;
notifyListeners(new PlotChangeEvent(this));
}
/**
* Returns the background image alignment. Alignment constants are defined in the
* <code>org.jfree.ui.Align</code> class in the JCommon class library.
*
* @return The alignment.
*/
public int getBackgroundImageAlignment() {
return this.backgroundImageAlignment;
}
/**
* Sets the background alignment.
* <p>
* Alignment options are defined by the {@link org.jfree.ui.Align} class.
*
* @param alignment the alignment.
*/
public void setBackgroundImageAlignment(int alignment) {
if (this.backgroundImageAlignment != alignment) {
this.backgroundImageAlignment = alignment;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the stroke used to outline the plot area.
*
* @return The stroke (possibly <code>null</code>).
*/
public Stroke getOutlineStroke() {
return this.outlineStroke;
}
/**
* Sets the stroke used to outline the plot area. A {@link PlotChangeEvent} is sent to all
* registered listeners.
* <p>
* If you set this attribute to <code>null<.code>, no outline will be drawn.
*
* @param stroke the stroke (<code>null</code> permitted).
*/
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>).
*/
public Paint getOutlinePaint() {
return this.outlinePaint;
}
/**
* Sets the color used to draw the outline of the plot area. A {@link PlotChangeEvent} is
* sent to all registered listeners.
* <p>
* If you set this attribute to <code>null</code>, no outline will be drawn.
*
* @param paint the paint (<code>null</code> permitted).
*/
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.
*/
public float getForegroundAlpha() {
return this.foregroundAlpha;
}
/**
* Sets the alpha-transparency for the plot.
*
* @param alpha the new alpha transparency.
*/
public void setForegroundAlpha(float alpha) {
if (this.foregroundAlpha != alpha) {
this.foregroundAlpha = alpha;
notifyListeners(new PlotChangeEvent(this));
}
}
/**
* Returns the legend items for the plot.
* <P>
* By default, this method returns <code>null</code>. Subclasses should override to return a
* {@link LegendItemCollection}.
*
* @return the legend items for the plot.
*/
public LegendItemCollection getLegendItems() {
return null;
}
/**
* Registers an object for notification of changes to the plot.
*
* @param listener the object to be registered.
*/
public void addChangeListener(PlotChangeListener listener) {
listenerList.add(PlotChangeListener.class, listener);
}
/**
* Unregisters an object for notification of changes to the plot.
*
* @param listener the object to be unregistered.
*/
public void removeChangeListener(PlotChangeListener listener) {
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 on a Java 2D graphics device (such as the screen or a printer).
* <P>
* This class does not store any information about where the individual
* items that make up the plot are actually drawn. If you want to collect
* this information, pass in a ChartRenderingInfo object. After the
* drawing is complete, the info object will contain lots of information
* about the chart. If you don't want the information, pass in null.
* *
* @param g2 the graphics device.
* @param plotArea the area within which the plot should be drawn.
* @param info an object for collecting information about the drawing of the chart.
*/
public abstract void draw(Graphics2D g2, Rectangle2D plotArea, ChartRenderingInfo info);
/**
* Draw the plot background.
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
public void drawBackground(Graphics2D g2, Rectangle2D area) {
if (backgroundPaint != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
this.backgroundAlpha));
g2.setPaint(backgroundPaint);
g2.fill(area);
g2.setComposite(originalComposite);
}
if (backgroundImage != null) {
Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, this.backgroundAlpha));
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);
}
}
/**
* Draw the plot outline
*
* @param g2 the graphics device.
* @param area the area within which the plot should be drawn.
*/
public void drawOutline(Graphics2D g2, Rectangle2D area) {
if ((outlineStroke != null) && (outlinePaint != null)) {
g2.setStroke(outlineStroke);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -