| Method from org.jfree.chart.JFreeChart Detail: |
public void addChangeListener(ChartChangeListener listener) {
if (listener == null) {
throw new IllegalArgumentException("Null 'listener' argument.");
}
this.changeListeners.add(ChartChangeListener.class, listener);
}
Registers an object for notification of changes to the chart. |
public void addLegend(LegendTitle legend) {
addSubtitle(legend);
}
Adds a legend to the plot and sends a ChartChangeEvent to all
registered listeners. |
public void addProgressListener(ChartProgressListener listener) {
this.progressListeners.add(ChartProgressListener.class, listener);
}
Registers an object for notification of progress events relating to the
chart. |
public void addSubtitle(Title subtitle) {
if (subtitle == null) {
throw new IllegalArgumentException("Null 'subtitle' argument.");
}
this.subtitles.add(subtitle);
subtitle.addChangeListener(this);
fireChartChanged();
}
Adds a chart subtitle, and notifies registered listeners that the chart
has been modified. |
public void addSubtitle(int index,
Title subtitle) {
if (index < 0 || index > getSubtitleCount()) {
throw new IllegalArgumentException(
"The 'index' argument is out of range.");
}
if (subtitle == null) {
throw new IllegalArgumentException("Null 'subtitle' argument.");
}
this.subtitles.add(index, subtitle);
subtitle.addChangeListener(this);
fireChartChanged();
}
Adds a subtitle at a particular position in the subtitle list, and sends
a ChartChangeEvent to all registered listeners. |
public void clearSubtitles() {
Iterator iterator = this.subtitles.iterator();
while (iterator.hasNext()) {
Title t = (Title) iterator.next();
t.removeChangeListener(this);
}
this.subtitles.clear();
fireChartChanged();
}
Clears all subtitles from the chart and sends a ChartChangeEvent
to all registered listeners. |
public Object clone() throws CloneNotSupportedException {
JFreeChart chart = (JFreeChart) super.clone();
chart.renderingHints = (RenderingHints) this.renderingHints.clone();
// private boolean borderVisible;
// private transient Stroke borderStroke;
// private transient Paint borderPaint;
if (this.title != null) {
chart.title = (TextTitle) this.title.clone();
chart.title.addChangeListener(chart);
}
chart.subtitles = new ArrayList();
for (int i = 0; i < getSubtitleCount(); i++) {
Title subtitle = (Title) getSubtitle(i).clone();
chart.subtitles.add(subtitle);
subtitle.addChangeListener(chart);
}
if (this.plot != null) {
chart.plot = (Plot) this.plot.clone();
chart.plot.addChangeListener(chart);
}
chart.progressListeners = new EventListenerList();
chart.changeListeners = new EventListenerList();
return chart;
}
Clones the object, and takes care of listeners.
Note: caller shall register its own listeners on cloned graph. |
public BufferedImage createBufferedImage(int width,
int height) {
return createBufferedImage(width, height, null);
}
Creates and returns a buffered image into which the chart has been drawn. |
public BufferedImage createBufferedImage(int width,
int height,
ChartRenderingInfo info) {
return createBufferedImage(width, height, BufferedImage.TYPE_INT_ARGB,
info);
}
Creates and returns a buffered image into which the chart has been drawn. |
public BufferedImage createBufferedImage(int width,
int height,
int imageType,
ChartRenderingInfo info) {
BufferedImage image = new BufferedImage(width, height, imageType);
Graphics2D g2 = image.createGraphics();
draw(g2, new Rectangle2D.Double(0, 0, width, height), null, info);
g2.dispose();
return image;
}
Creates and returns a buffered image into which the chart has been drawn. |
public BufferedImage createBufferedImage(int imageWidth,
int imageHeight,
double drawWidth,
double drawHeight,
ChartRenderingInfo info) {
BufferedImage image = new BufferedImage(imageWidth, imageHeight,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
double scaleX = imageWidth / drawWidth;
double scaleY = imageHeight / drawHeight;
AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY);
g2.transform(st);
draw(g2, new Rectangle2D.Double(0, 0, drawWidth, drawHeight), null,
info);
g2.dispose();
return image;
}
Creates and returns a buffered image into which the chart has been drawn. |
public void draw(Graphics2D g2,
Rectangle2D area) {
draw(g2, area, null, null);
}
|
public void draw(Graphics2D g2,
Rectangle2D area,
ChartRenderingInfo info) {
draw(g2, area, null, info);
}
Draws the chart on a Java 2D graphics device (such as the screen or a
printer). This method is the focus of the entire JFreeChart library. |
public void draw(Graphics2D g2,
Rectangle2D chartArea,
Point2D anchor,
ChartRenderingInfo info) {
notifyListeners(new ChartProgressEvent(this, this,
ChartProgressEvent.DRAWING_STARTED, 0));
// record the chart area, if info is requested...
if (info != null) {
info.clear();
info.setChartArea(chartArea);
}
// ensure no drawing occurs outside chart area...
Shape savedClip = g2.getClip();
g2.clip(chartArea);
g2.addRenderingHints(this.renderingHints);
// draw the chart background...
if (this.backgroundPaint != null) {
g2.setPaint(this.backgroundPaint);
g2.fill(chartArea);
}
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, chartArea, this.backgroundImageAlignment);
g2.drawImage(this.backgroundImage, (int) dest.getX(),
(int) dest.getY(), (int) dest.getWidth(),
(int) dest.getHeight(), null);
g2.setComposite(originalComposite);
}
if (isBorderVisible()) {
Paint paint = getBorderPaint();
Stroke stroke = getBorderStroke();
if (paint != null && stroke != null) {
Rectangle2D borderArea = new Rectangle2D.Double(
chartArea.getX(), chartArea.getY(),
chartArea.getWidth() - 1.0, chartArea.getHeight()
- 1.0);
g2.setPaint(paint);
g2.setStroke(stroke);
g2.draw(borderArea);
}
}
// draw the title and subtitles...
Rectangle2D nonTitleArea = new Rectangle2D.Double();
nonTitleArea.setRect(chartArea);
this.padding.trim(nonTitleArea);
EntityCollection entities = null;
if (info != null) {
entities = info.getEntityCollection();
}
if (this.title != null) {
EntityCollection e = drawTitle(this.title, g2, nonTitleArea,
(entities != null));
if (e != null) {
entities.addAll(e);
}
}
Iterator iterator = this.subtitles.iterator();
while (iterator.hasNext()) {
Title currentTitle = (Title) iterator.next();
EntityCollection e = drawTitle(currentTitle, g2, nonTitleArea,
(entities != null));
if (e != null) {
entities.addAll(e);
}
}
Rectangle2D plotArea = nonTitleArea;
// draw the plot (axes and data visualisation)
PlotRenderingInfo plotInfo = null;
if (info != null) {
plotInfo = info.getPlotInfo();
}
this.plot.draw(g2, plotArea, anchor, null, plotInfo);
g2.setClip(savedClip);
notifyListeners(new ChartProgressEvent(this, this,
ChartProgressEvent.DRAWING_FINISHED, 100));
}
|
protected EntityCollection drawTitle(Title t,
Graphics2D g2,
Rectangle2D area,
boolean entities) {
if (t == null) {
throw new IllegalArgumentException("Null 't' argument.");
}
if (area == null) {
throw new IllegalArgumentException("Null 'area' argument.");
}
Rectangle2D titleArea = new Rectangle2D.Double();
RectangleEdge position = t.getPosition();
double ww = area.getWidth();
if (ww < = 0.0) {
return null;
}
double hh = area.getHeight();
if (hh < = 0.0) {
return null;
}
RectangleConstraint constraint = new RectangleConstraint(ww,
new Range(0.0, ww), LengthConstraintType.RANGE, hh,
new Range(0.0, hh), LengthConstraintType.RANGE);
Object retValue = null;
BlockParams p = new BlockParams();
p.setGenerateEntities(entities);
if (position == RectangleEdge.TOP) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area,
t.getHorizontalAlignment(), VerticalAlignment.TOP);
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), Math.min(area.getY() + size.height,
area.getMaxY()), area.getWidth(), Math.max(area.getHeight()
- size.height, 0));
}
else if (position == RectangleEdge.BOTTOM) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area,
t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), area.getY(), area.getWidth(),
area.getHeight() - size.height);
}
else if (position == RectangleEdge.RIGHT) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area,
HorizontalAlignment.RIGHT, t.getVerticalAlignment());
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX(), area.getY(), area.getWidth()
- size.width, area.getHeight());
}
else if (position == RectangleEdge.LEFT) {
Size2D size = t.arrange(g2, constraint);
titleArea = createAlignedRectangle2D(size, area,
HorizontalAlignment.LEFT, t.getVerticalAlignment());
retValue = t.draw(g2, titleArea, p);
area.setRect(area.getX() + size.width, area.getY(), area.getWidth()
- size.width, area.getHeight());
}
else {
throw new RuntimeException("Unrecognised title position.");
}
EntityCollection result = null;
if (retValue instanceof EntityBlockResult) {
EntityBlockResult ebr = (EntityBlockResult) retValue;
result = ebr.getEntityCollection();
}
return result;
}
Draws a title. The title should be drawn at the top, bottom, left or
right of the specified area, and the area should be updated to reflect
the amount of space used by the title. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof JFreeChart)) {
return false;
}
JFreeChart that = (JFreeChart) obj;
if (!this.renderingHints.equals(that.renderingHints)) {
return false;
}
if (this.borderVisible != that.borderVisible) {
return false;
}
if (!ObjectUtilities.equal(this.borderStroke, that.borderStroke)) {
return false;
}
if (!PaintUtilities.equal(this.borderPaint, that.borderPaint)) {
return false;
}
if (!this.padding.equals(that.padding)) {
return false;
}
if (!ObjectUtilities.equal(this.title, that.title)) {
return false;
}
if (!ObjectUtilities.equal(this.subtitles, that.subtitles)) {
return false;
}
if (!ObjectUtilities.equal(this.plot, that.plot)) {
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.notify != that.notify) {
return false;
}
return true;
}
Tests this chart for equality with another object. |
public void fireChartChanged() {
ChartChangeEvent event = new ChartChangeEvent(this);
notifyListeners(event);
}
|
public boolean getAntiAlias() {
Object val = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING);
return RenderingHints.VALUE_ANTIALIAS_ON.equals(val);
}
Returns a flag that indicates whether or not anti-aliasing is used when
the chart is drawn. |
public Image getBackgroundImage() {
return this.backgroundImage;
}
Returns the background image for the chart, or null if
there is no image. |
public int getBackgroundImageAlignment() {
return this.backgroundImageAlignment;
}
Returns the background image alignment. Alignment constants are defined
in the org.jfree.ui.Align class in the JCommon class
library. |
public float getBackgroundImageAlpha() {
return this.backgroundImageAlpha;
}
Returns the alpha-transparency for the chart's background image. |
public Paint getBackgroundPaint() {
return this.backgroundPaint;
}
Returns the paint used for the chart background. |
public Paint getBorderPaint() {
return this.borderPaint;
}
Returns the paint used to draw the chart border (if visible). |
public Stroke getBorderStroke() {
return this.borderStroke;
}
Returns the stroke used to draw the chart border (if visible). |
public CategoryPlot getCategoryPlot() {
return (CategoryPlot) this.plot;
}
Returns the plot cast as a CategoryPlot .
NOTE: if the plot is not an instance of CategoryPlot , then a
ClassCastException is thrown. |
public LegendTitle getLegend() {
return getLegend(0);
}
Returns the legend for the chart, if there is one. Note that a chart
can have more than one legend - this method returns the first. |
public LegendTitle getLegend(int index) {
int seen = 0;
Iterator iterator = this.subtitles.iterator();
while (iterator.hasNext()) {
Title subtitle = (Title) iterator.next();
if (subtitle instanceof LegendTitle) {
if (seen == index) {
return (LegendTitle) subtitle;
}
else {
seen++;
}
}
}
return null;
}
Returns the nth legend for a chart, or null. |
public RectangleInsets getPadding() {
return this.padding;
}
Returns the padding between the chart border and the chart drawing area. |
public Plot getPlot() {
return this.plot;
}
Returns the plot for the chart. The plot is a class responsible for
coordinating the visual representation of the data, including the axes
(if any). |
public RenderingHints getRenderingHints() {
return this.renderingHints;
}
Returns the collection of rendering hints for the chart. |
public Title getSubtitle(int index) {
if ((index < 0) || (index >= getSubtitleCount())) {
throw new IllegalArgumentException("Index out of range.");
}
return (Title) this.subtitles.get(index);
}
Returns a chart subtitle. |
public int getSubtitleCount() {
return this.subtitles.size();
}
Returns the number of titles for the chart. |
public List getSubtitles() {
return new ArrayList(this.subtitles);
}
Returns the list of subtitles for the chart. |
public Object getTextAntiAlias() {
return this.renderingHints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
}
|
public TextTitle getTitle() {
return this.title;
}
Returns the main chart title. Very often a chart will have just one
title, so we make this case simple by providing accessor methods for
the main title. However, multiple titles are supported - see the
#addSubtitle(Title) method. |
public XYPlot getXYPlot() {
return (XYPlot) this.plot;
}
Returns the plot cast as an XYPlot .
NOTE: if the plot is not an instance of XYPlot , then a
ClassCastException is thrown. |
public void handleClick(int x,
int y,
ChartRenderingInfo info) {
// pass the click on to the plot...
// rely on the plot to post a plot change event and redraw the chart...
this.plot.handleClick(x, y, info.getPlotInfo());
}
Handles a 'click' on the chart. JFreeChart is not a UI component, so
some other object (for example, ChartPanel ) needs to capture
the click event and pass it onto the JFreeChart object.
If you are not using JFreeChart in a client application, then this
method is not required. |
public boolean isBorderVisible() {
return this.borderVisible;
}
Returns a flag that controls whether or not a border is drawn around the
outside of the chart. |
public boolean isNotify() {
return this.notify;
}
Returns a flag that controls whether or not change events are sent to
registered listeners. |
public static void main(String[] args) {
System.out.println(JFreeChart.INFO.toString());
}
Prints information about JFreeChart to standard output. |
protected void notifyListeners(ChartChangeEvent event) {
if (this.notify) {
Object[] listeners = this.changeListeners.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ChartChangeListener.class) {
((ChartChangeListener) listeners[i + 1]).chartChanged(
event);
}
}
}
}
|
protected void notifyListeners(ChartProgressEvent event) {
Object[] listeners = this.progressListeners.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ChartProgressListener.class) {
((ChartProgressListener) listeners[i + 1]).chartProgress(event);
}
}
}
|
public void plotChanged(PlotChangeEvent event) {
event.setChart(this);
notifyListeners(event);
}
Receives notification that the plot has changed, and passes this on to
registered listeners. |
public void removeChangeListener(ChartChangeListener listener) {
if (listener == null) {
throw new IllegalArgumentException("Null 'listener' argument.");
}
this.changeListeners.remove(ChartChangeListener.class, listener);
}
Deregisters an object for notification of changes to the chart. |
public void removeLegend() {
removeSubtitle(getLegend());
}
Removes the first legend in the chart and sends a
ChartChangeEvent to all registered listeners. |
public void removeProgressListener(ChartProgressListener listener) {
this.progressListeners.remove(ChartProgressListener.class, listener);
}
Deregisters an object for notification of changes to the chart. |
public void removeSubtitle(Title title) {
this.subtitles.remove(title);
fireChartChanged();
}
Removes the specified subtitle and sends a ChartChangeEvent to
all registered listeners. |
public void setAntiAlias(boolean flag) {
Object val = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING);
if (val == null) {
val = RenderingHints.VALUE_ANTIALIAS_DEFAULT;
}
if (!flag && RenderingHints.VALUE_ANTIALIAS_OFF.equals(val)
|| flag && RenderingHints.VALUE_ANTIALIAS_ON.equals(val)) {
// no change, do nothing
return;
}
if (flag) {
this.renderingHints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
else {
this.renderingHints.put(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_OFF);
}
fireChartChanged();
}
Sets a flag that indicates whether or not anti-aliasing is used when the
chart is drawn.
Anti-aliasing usually improves the appearance of charts, but is slower. |
public void setBackgroundImage(Image image) {
if (this.backgroundImage != null) {
if (!this.backgroundImage.equals(image)) {
this.backgroundImage = image;
fireChartChanged();
}
}
else {
if (image != null) {
this.backgroundImage = image;
fireChartChanged();
}
}
}
Sets the background image for the chart and sends a
ChartChangeEvent to all registered listeners. |
public void setBackgroundImageAlignment(int alignment) {
if (this.backgroundImageAlignment != alignment) {
this.backgroundImageAlignment = alignment;
fireChartChanged();
}
}
Sets the background alignment. Alignment options are defined by the
org.jfree.ui.Align class. |
public void setBackgroundImageAlpha(float alpha) {
if (this.backgroundImageAlpha != alpha) {
this.backgroundImageAlpha = alpha;
fireChartChanged();
}
}
Sets the alpha-transparency for the chart's background image.
Registered listeners are notified that the chart has been changed. |
public void setBackgroundPaint(Paint paint) {
if (this.backgroundPaint != null) {
if (!this.backgroundPaint.equals(paint)) {
this.backgroundPaint = paint;
fireChartChanged();
}
}
else {
if (paint != null) {
this.backgroundPaint = paint;
fireChartChanged();
}
}
}
Sets the paint used to fill the chart background and sends a
ChartChangeEvent to all registered listeners. |
public void setBorderPaint(Paint paint) {
this.borderPaint = paint;
fireChartChanged();
}
Sets the paint used to draw the chart border (if visible). |
public void setBorderStroke(Stroke stroke) {
this.borderStroke = stroke;
fireChartChanged();
}
Sets the stroke used to draw the chart border (if visible). |
public void setBorderVisible(boolean visible) {
this.borderVisible = visible;
fireChartChanged();
}
Sets a flag that controls whether or not a border is drawn around the
outside of the chart. |
public void setNotify(boolean notify) {
this.notify = notify;
// if the flag is being set to true, there may be queued up changes...
if (notify) {
notifyListeners(new ChartChangeEvent(this));
}
}
Sets a flag that controls whether or not listeners receive
ChartChangeEvent notifications. |
public void setPadding(RectangleInsets padding) {
if (padding == null) {
throw new IllegalArgumentException("Null 'padding' argument.");
}
this.padding = padding;
notifyListeners(new ChartChangeEvent(this));
}
Sets the padding between the chart border and the chart drawing area,
and sends a ChartChangeEvent to all registered listeners. |
public void setRenderingHints(RenderingHints renderingHints) {
if (renderingHints == null) {
throw new NullPointerException("RenderingHints given are null");
}
this.renderingHints = renderingHints;
fireChartChanged();
}
Sets the rendering hints for the chart. These will be added (using the
Graphics2D.addRenderingHints() method) near the start of the
JFreeChart.draw() method. |
public void setSubtitles(List subtitles) {
if (subtitles == null) {
throw new NullPointerException("Null 'subtitles' argument.");
}
setNotify(false);
clearSubtitles();
Iterator iterator = subtitles.iterator();
while (iterator.hasNext()) {
Title t = (Title) iterator.next();
if (t != null) {
addSubtitle(t);
}
}
setNotify(true); // this fires a ChartChangeEvent
}
Sets the title list for the chart (completely replaces any existing
titles) and sends a ChartChangeEvent to all registered
listeners. |
public void setTextAntiAlias(boolean flag) {
if (flag) {
setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}
else {
setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
}
|
public void setTextAntiAlias(Object val) {
this.renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, val);
notifyListeners(new ChartChangeEvent(this));
}
|
public void setTitle(TextTitle title) {
if (this.title != null) {
this.title.removeChangeListener(this);
}
this.title = title;
if (title != null) {
title.addChangeListener(this);
}
fireChartChanged();
}
Sets the main title for the chart and sends a ChartChangeEvent
to all registered listeners. If you do not want a title for the
chart, set it to null. If you want more than one title on
a chart, use the #addSubtitle(Title) method. |
public void setTitle(String text) {
if (text != null) {
if (this.title == null) {
setTitle(new TextTitle(text, JFreeChart.DEFAULT_TITLE_FONT));
}
else {
this.title.setText(text);
}
}
else {
setTitle((TextTitle) null);
}
}
Sets the chart title and sends a ChartChangeEvent to all
registered listeners. This is a convenience method that ends up calling
the #setTitle(TextTitle) method. If there is an existing title,
its text is updated, otherwise a new title using the default font is
added to the chart. If text is null the chart
title is set to null. |
public void titleChanged(TitleChangeEvent event) {
event.setChart(this);
notifyListeners(event);
}
Receives notification that a chart title has changed, and passes this
on to registered listeners. |