1 122 123 package org.jfree.chart; 124 125 import java.awt.AlphaComposite ; 126 import java.awt.BasicStroke ; 127 import java.awt.Color ; 128 import java.awt.Composite ; 129 import java.awt.Font ; 130 import java.awt.Graphics2D ; 131 import java.awt.Image ; 132 import java.awt.Paint ; 133 import java.awt.RenderingHints ; 134 import java.awt.Shape ; 135 import java.awt.Stroke ; 136 import java.awt.geom.AffineTransform ; 137 import java.awt.geom.Point2D ; 138 import java.awt.geom.Rectangle2D ; 139 import java.awt.image.BufferedImage ; 140 import java.io.IOException ; 141 import java.io.ObjectInputStream ; 142 import java.io.ObjectOutputStream ; 143 import java.io.Serializable ; 144 import java.net.URL ; 145 import java.util.ArrayList ; 146 import java.util.Arrays ; 147 import java.util.Iterator ; 148 import java.util.List ; 149 import java.util.ResourceBundle ; 150 151 import javax.swing.ImageIcon ; 152 import javax.swing.UIManager ; 153 import javax.swing.event.EventListenerList ; 154 155 import org.jfree.JCommon; 156 import org.jfree.chart.block.BlockBorder; 157 import org.jfree.chart.block.BlockParams; 158 import org.jfree.chart.block.EntityBlockResult; 159 import org.jfree.chart.block.LengthConstraintType; 160 import org.jfree.chart.block.RectangleConstraint; 161 import org.jfree.chart.entity.EntityCollection; 162 import org.jfree.chart.event.ChartChangeEvent; 163 import org.jfree.chart.event.ChartChangeListener; 164 import org.jfree.chart.event.ChartProgressEvent; 165 import org.jfree.chart.event.ChartProgressListener; 166 import org.jfree.chart.event.LegendChangeEvent; 167 import org.jfree.chart.event.LegendChangeListener; 168 import org.jfree.chart.event.PlotChangeEvent; 169 import org.jfree.chart.event.PlotChangeListener; 170 import org.jfree.chart.event.TitleChangeEvent; 171 import org.jfree.chart.event.TitleChangeListener; 172 import org.jfree.chart.plot.CategoryPlot; 173 import org.jfree.chart.plot.Plot; 174 import org.jfree.chart.plot.PlotRenderingInfo; 175 import org.jfree.chart.plot.XYPlot; 176 import org.jfree.chart.title.LegendTitle; 177 import org.jfree.chart.title.TextTitle; 178 import org.jfree.chart.title.Title; 179 import org.jfree.data.Range; 180 import org.jfree.io.SerialUtilities; 181 import org.jfree.ui.Align; 182 import org.jfree.ui.Drawable; 183 import org.jfree.ui.HorizontalAlignment; 184 import org.jfree.ui.RectangleEdge; 185 import org.jfree.ui.RectangleInsets; 186 import org.jfree.ui.Size2D; 187 import org.jfree.ui.VerticalAlignment; 188 import org.jfree.ui.about.Contributor; 189 import org.jfree.ui.about.Licences; 190 import org.jfree.ui.about.ProjectInfo; 191 import org.jfree.util.ObjectUtilities; 192 193 216 public class JFreeChart implements Drawable, 217 TitleChangeListener, 218 LegendChangeListener, 219 PlotChangeListener, 220 Serializable , 221 Cloneable { 222 223 224 private static final long serialVersionUID = -3470703747817429120L; 225 226 227 public static final ProjectInfo INFO = new JFreeChartInfo(); 228 229 230 public static final Font DEFAULT_TITLE_FONT 231 = new Font ("SansSerif", Font.BOLD, 18); 232 233 234 public static final Paint DEFAULT_BACKGROUND_PAINT 235 = UIManager.getColor("Panel.background"); 236 237 238 public static final Image DEFAULT_BACKGROUND_IMAGE = null; 239 240 241 public static final int DEFAULT_BACKGROUND_IMAGE_ALIGNMENT = Align.FIT; 242 243 244 public static final float DEFAULT_BACKGROUND_IMAGE_ALPHA = 0.5f; 245 246 247 private transient RenderingHints renderingHints; 248 249 250 private boolean borderVisible; 251 252 253 private transient Stroke borderStroke; 254 255 256 private transient Paint borderPaint; 257 258 259 private TextTitle title; 260 261 262 private List subtitles; 263 264 265 private OldLegend oldLegend; 266 267 268 private Plot plot; 269 270 271 private transient Paint backgroundPaint; 272 273 274 private transient Image backgroundImage; 276 277 private int backgroundImageAlignment = Align.FIT; 278 279 280 private float backgroundImageAlpha = 0.5f; 281 282 283 private transient EventListenerList changeListeners; 284 285 286 private transient EventListenerList progressListeners; 287 288 292 private boolean notify; 293 294 305 public JFreeChart(Plot plot) { 306 307 this( 308 null, null, plot, 311 true ); 313 314 } 315 316 328 public JFreeChart(String title, Plot plot) { 329 this(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); 330 } 331 332 349 public JFreeChart(String title, Font titleFont, Plot plot, 350 boolean createLegend) { 351 352 if (plot == null) { 353 throw new NullPointerException ("Null 'plot' argument."); 354 } 355 356 this.progressListeners = new EventListenerList (); 358 this.changeListeners = new EventListenerList (); 359 this.notify = true; 362 this.renderingHints = new RenderingHints ( 363 RenderingHints.KEY_ANTIALIASING, 364 RenderingHints.VALUE_ANTIALIAS_ON 365 ); 366 367 this.borderVisible = false; 368 this.borderStroke = new BasicStroke (1.0f); 369 this.borderPaint = Color.black; 370 371 this.plot = plot; 372 plot.addChangeListener(this); 373 374 this.subtitles = new ArrayList (); 375 376 if (createLegend) { 378 LegendTitle legend = new LegendTitle(this.plot); 379 legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); 380 legend.setBorder(new BlockBorder()); 381 legend.setBackgroundPaint(Color.white); 382 legend.setPosition(RectangleEdge.BOTTOM); 383 this.subtitles.add(legend); 384 } 385 386 if (title != null) { 388 if (titleFont == null) { 389 titleFont = DEFAULT_TITLE_FONT; 390 } 391 this.title = new TextTitle(title, titleFont); 392 this.title.addChangeListener(this); 393 } 394 395 this.backgroundPaint = DEFAULT_BACKGROUND_PAINT; 396 397 this.backgroundImage = DEFAULT_BACKGROUND_IMAGE; 398 this.backgroundImageAlignment = DEFAULT_BACKGROUND_IMAGE_ALIGNMENT; 399 this.backgroundImageAlpha = DEFAULT_BACKGROUND_IMAGE_ALPHA; 400 401 } 402 403 408 public RenderingHints getRenderingHints() { 409 return this.renderingHints; 410 } 411 412 420 public void setRenderingHints(RenderingHints renderingHints) { 421 if (renderingHints == null) { 422 throw new NullPointerException ("RenderingHints given are null"); 423 } 424 this.renderingHints = renderingHints; 425 fireChartChanged(); 426 } 427 428 434 public boolean isBorderVisible() { 435 return this.borderVisible; 436 } 437 438 444 public void setBorderVisible(boolean visible) { 445 this.borderVisible = visible; 446 fireChartChanged(); 447 } 448 449 454 public Stroke getBorderStroke() { 455 return this.borderStroke; 456 } 457 458 463 public void setBorderStroke(Stroke stroke) { 464 this.borderStroke = stroke; 465 fireChartChanged(); 466 } 467 468 473 public Paint getBorderPaint() { 474 return this.borderPaint; 475 } 476 477 482 public void setBorderPaint(Paint paint) { 483 this.borderPaint = paint; 484 fireChartChanged(); 485 } 486 487 495 public TextTitle getTitle() { 496 return this.title; 497 } 498 499 507 public void setTitle(TextTitle title) { 508 this.title = title; 509 fireChartChanged(); 510 } 511 512 522 public void setTitle(String text) { 523 if (text != null) { 524 if (this.title == null) { 525 setTitle(new TextTitle(text, JFreeChart.DEFAULT_TITLE_FONT)); 526 } 527 else { 528 this.title.setText(text); 529 } 530 } 531 else { 532 setTitle((TextTitle) null); 533 } 534 } 535 536 542 public LegendTitle getLegend() { 543 return getLegend(0); 544 } 545 546 553 public LegendTitle getLegend(int index) { 554 int seen = 0; 555 Iterator iterator = this.subtitles.iterator(); 556 while (iterator.hasNext()) { 557 Title subtitle = (Title) iterator.next(); 558 if (subtitle instanceof LegendTitle) { 559 if (seen == index) { 560 return (LegendTitle) subtitle; 561 } 562 else { 563 seen++; 564 } 565 } 566 } 567 return null; 568 } 569 570 574 public void removeLegend() { 575 removeSubtitle(getLegend()); 576 } 577 578 583 public List getSubtitles() { 584 return this.subtitles; 585 } 586 587 594 public void setSubtitles(List subtitles) { 595 if (subtitles == null) { 596 throw new NullPointerException ("Null 'subtitles' argument."); 597 } 598 this.subtitles = subtitles; 599 fireChartChanged(); 600 } 601 602 607 public int getSubtitleCount() { 608 return this.subtitles.size(); 609 } 610 611 618 public Title getSubtitle(int index) { 619 if ((index < 0) || (index == getSubtitleCount())) { 620 throw new IllegalArgumentException ("Index out of range."); 621 } 622 return (Title) this.subtitles.get(index); 623 } 624 625 631 public void addSubtitle(Title subtitle) { 632 if (subtitle == null) { 633 throw new IllegalArgumentException ("Null 'subtitle' argument."); 634 } 635 this.subtitles.add(subtitle); 636 subtitle.addChangeListener(this); 637 fireChartChanged(); 638 } 639 640 644 public void clearSubtitles() { 645 Iterator iterator = this.subtitles.iterator(); 646 while (iterator.hasNext()) { 647 Title t = (Title) iterator.next(); 648 t.removeChangeListener(this); 649 } 650 this.subtitles.clear(); 651 fireChartChanged(); 652 } 653 654 660 public void removeSubtitle(Title title) { 661 this.subtitles.remove(title); 662 fireChartChanged(); 663 } 664 665 670 public OldLegend getOldLegend() { 671 return this.oldLegend; 672 } 673 674 680 public void setOldLegend(OldLegend legend) { 681 682 OldLegend existing = this.oldLegend; 685 if (existing != null) { 686 existing.removeChangeListener(this); 687 existing.registerChart(null); 688 } 689 690 this.oldLegend = legend; 692 if (legend != null) { 693 legend.registerChart(this); 694 legend.addChangeListener(this); 695 } 696 697 fireChartChanged(); 699 700 } 701 702 709 public Plot getPlot() { 710 return this.plot; 711 } 712 713 721 public CategoryPlot getCategoryPlot() { 722 return (CategoryPlot) this.plot; 723 } 724 725 733 public XYPlot getXYPlot() { 734 return (XYPlot) this.plot; 735 } 736 737 743 public boolean getAntiAlias() { 744 Object o = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING); 745 if (o == null) { 746 return false; 747 } 748 return (o.equals(RenderingHints.VALUE_ANTIALIAS_ON)); 749 } 750 751 759 public void setAntiAlias(boolean flag) { 760 761 Object o = this.renderingHints.get(RenderingHints.KEY_ANTIALIASING); 762 if (o == null) { 763 o = RenderingHints.VALUE_ANTIALIAS_DEFAULT; 764 } 765 if (!flag && RenderingHints.VALUE_ANTIALIAS_OFF.equals(o) 766 || flag && RenderingHints.VALUE_ANTIALIAS_ON.equals(o)) { 767 return; 769 } 770 if (flag) { 771 this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 772 RenderingHints.VALUE_ANTIALIAS_ON); 773 } 774 else { 775 this.renderingHints.put(RenderingHints.KEY_ANTIALIASING, 776 RenderingHints.VALUE_ANTIALIAS_OFF); 777 } 778 fireChartChanged(); 779 780 } 781 782 787 public Paint getBackgroundPaint() { 788 return this.backgroundPaint; 789 } 790 791 797 public void setBackgroundPaint(Paint paint) { 798 799 if (this.backgroundPaint != null) { 800 if (!this.backgroundPaint.equals(paint)) { 801 this.backgroundPaint = paint; 802 fireChartChanged(); 803 } 804 } 805 else { 806 if (paint != null) { 807 this.backgroundPaint = paint; 808 fireChartChanged(); 809 } 810 } 811 812 } 813 814 820 public Image getBackgroundImage() { 821 return this.backgroundImage; 822 } 823 824 830 public void setBackgroundImage(Image image) { 831 832 if (this.backgroundImage != null) { 833 if (!this.backgroundImage.equals(image)) { 834 this.backgroundImage = image; 835 fireChartChanged(); 836 } 837 } 838 else { 839 if (image != null) { 840 this.backgroundImage = image; 841 fireChartChanged(); 842 } 843 } 844 845 } 846 847 854 public int getBackgroundImageAlignment() { 855 return this.backgroundImageAlignment; 856 } 857 858 864 public void setBackgroundImageAlignment(int alignment) { 865 if (this.backgroundImageAlignment != alignment) { 866 this.backgroundImageAlignment = alignment; 867 fireChartChanged(); 868 } 869 } 870 871 876 public float getBackgroundImageAlpha() { 877 return this.backgroundImageAlpha; 878 } 879 880 886 public void setBackgroundImageAlpha(float alpha) { 887 888 if (this.backgroundImageAlpha != alpha) { 889 this.backgroundImageAlpha = alpha; 890 fireChartChanged(); 891 } 892 893 } 894 895 901 public boolean isNotify() { 902 return this.notify; 903 } 904 905 911 public void setNotify(boolean notify) { 912 this.notify = notify; 913 if (notify) { 915 notifyListeners(new ChartChangeEvent(this)); 916 } 917 } 918 919 928 public void draw(Graphics2D g2, Rectangle2D area) { 929 draw(g2, area, null, null); 930 } 931 932 940 public void draw(Graphics2D g2, Rectangle2D area, ChartRenderingInfo info) { 941 draw(g2, area, null, info); 942 } 943 944 956 public void draw(Graphics2D g2, 957 Rectangle2D chartArea, Point2D anchor, 958 ChartRenderingInfo info) { 959 960 notifyListeners( 961 new ChartProgressEvent( 962 this, this, ChartProgressEvent.DRAWING_STARTED, 0 963 ) 964 ); 965 966 if (info != null) { 968 info.clear(); 969 info.setChartArea(chartArea); 970 } 971 972 Shape savedClip = g2.getClip(); 974 g2.clip(chartArea); 975 976 g2.addRenderingHints(this.renderingHints); 977 978 if (this.backgroundPaint != null) { 980 g2.setPaint(this.backgroundPaint); 981 g2.fill(chartArea); 982 } 983 984 if (this.backgroundImage != null) { 985 Composite originalComposite = g2.getComposite(); 986 g2.setComposite( 987 AlphaComposite.getInstance( 988 AlphaComposite.SRC_OVER, 989 this.backgroundImageAlpha 990 ) 991 ); 992 Rectangle2D dest = new Rectangle2D.Double ( 993 0.0, 0.0, this.backgroundImage.getWidth(null), 994 this.backgroundImage.getHeight(null) 995 ); 996 Align.align(dest, chartArea, this.backgroundImageAlignment); 997 g2.drawImage( 998 this.backgroundImage, (int) dest.getX(), (int) dest.getY(), 999 (int) dest.getWidth(), (int) dest.getHeight(), null 1000 ); 1001 g2.setComposite(originalComposite); 1002 } 1003 1004 if (isBorderVisible()) { 1005 Paint paint = getBorderPaint(); 1006 Stroke stroke = getBorderStroke(); 1007 if (paint != null && stroke != null) { 1008 Rectangle2D borderArea = new Rectangle2D.Double ( 1009 chartArea.getX(), chartArea.getY(), 1010 chartArea.getWidth() - 1.0, chartArea.getHeight() - 1.0 1011 ); 1012 g2.setPaint(paint); 1013 g2.setStroke(stroke); 1014 g2.draw(borderArea); 1015 } 1016 } 1017 1018 Rectangle2D nonTitleArea = new Rectangle2D.Double (); 1020 nonTitleArea.setRect(chartArea); 1021 1022 EntityCollection entities = null; 1023 if (info != null) { 1024 entities = info.getEntityCollection(); 1025 } 1026 if (this.title != null) { 1027 EntityCollection e = drawTitle( 1028 this.title, g2, nonTitleArea, (entities != null) 1029 ); 1030 if (e != null) { 1031 entities.addAll(e); 1032 } 1033 } 1034 1035 Iterator iterator = this.subtitles.iterator(); 1036 while (iterator.hasNext()) { 1037 Title currentTitle = (Title) iterator.next(); 1038 EntityCollection e = drawTitle( 1039 currentTitle, g2, nonTitleArea, (entities != null) 1040 ); 1041 if (e != null) { 1042 entities.addAll(e); 1043 } 1044 } 1045 1046 Rectangle2D plotArea = nonTitleArea; 1049 if (this.oldLegend != null) { 1050 plotArea.setRect(this.oldLegend.draw(g2, nonTitleArea, info)); 1051 } 1052 1053 PlotRenderingInfo plotInfo = null; 1055 if (info != null) { 1056 plotInfo = info.getPlotInfo(); 1057 } 1058 this.plot.draw(g2, plotArea, anchor, null, plotInfo); 1059 1060 g2.setClip(savedClip); 1061 1062 notifyListeners( 1063 new ChartProgressEvent( 1064 this, this, ChartProgressEvent.DRAWING_FINISHED, 100 1065 ) 1066 ); 1067 } 1068 1069 1079 private Rectangle2D createAlignedRectangle2D(Size2D dimensions, 1080 Rectangle2D frame, HorizontalAlignment hAlign, 1081 VerticalAlignment vAlign) { 1082 double x = Double.NaN; 1083 double y = Double.NaN; 1084 if (hAlign == HorizontalAlignment.LEFT) { 1085 x = frame.getX(); 1086 } 1087 else if (hAlign == HorizontalAlignment.CENTER) { 1088 x = frame.getCenterX() - (dimensions.width / 2.0); 1089 } 1090 else if (hAlign == HorizontalAlignment.RIGHT) { 1091 x = frame.getMaxX() - dimensions.width; 1092 } 1093 if (vAlign == VerticalAlignment.TOP) { 1094 y = frame.getY(); 1095 } 1096 else if (vAlign == VerticalAlignment.CENTER) { 1097 y = frame.getCenterY() - (dimensions.height / 2.0); 1098 } 1099 else if (vAlign == VerticalAlignment.BOTTOM) { 1100 y = frame.getMaxY() - dimensions.height; 1101 } 1102 1103 return new Rectangle2D.Double ( 1104 x, y, dimensions.width, dimensions.height 1105 ); 1106 } 1107 1108 1122 protected EntityCollection drawTitle(Title t, Graphics2D g2, 1123 Rectangle2D area, boolean entities) { 1124 1125 if (t == null) { 1126 throw new IllegalArgumentException ("Null 't' argument."); 1127 } 1128 if (area == null) { 1129 throw new IllegalArgumentException ("Null 'area' argument."); 1130 } 1131 Rectangle2D titleArea = new Rectangle2D.Double (); 1132 RectangleEdge position = t.getPosition(); 1133 double ww = area.getWidth(); 1134 double hh = area.getHeight(); 1135 RectangleConstraint constraint = new RectangleConstraint( 1136 ww, new Range(0.0, ww), LengthConstraintType.RANGE, 1137 hh, new Range(0.0, hh), LengthConstraintType.RANGE 1138 ); 1139 Object retValue = null; 1140 BlockParams p = new BlockParams(); 1141 p.setGenerateEntities(entities); 1142 if (position == RectangleEdge.TOP) { 1143 Size2D size = t.arrange(g2, constraint); 1144 titleArea = createAlignedRectangle2D( 1145 size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP 1146 ); 1147 retValue = t.draw(g2, titleArea, p); 1148 area.setRect( 1149 area.getX(), 1150 Math.min(area.getY() + size.height, area.getMaxY()), 1151 area.getWidth(), Math.max(area.getHeight() - size.height, 0) 1152 ); 1153 } 1154 else if (position == RectangleEdge.BOTTOM) { 1155 Size2D size = t.arrange(g2, constraint); 1156 titleArea = createAlignedRectangle2D( 1157 size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM 1158 ); 1159 retValue = t.draw(g2, titleArea, p); 1160 area.setRect( 1161 area.getX(), area.getY(), 1162 area.getWidth(), area.getHeight() - size.height 1163 ); 1164 } 1165 else if (position == RectangleEdge.RIGHT) { 1166 Size2D size = t.arrange(g2, constraint); 1167 titleArea = createAlignedRectangle2D( 1168 size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment() 1169 ); 1170 retValue = t.draw(g2, titleArea, p); 1171 area.setRect( 1172 area.getX(), area.getY(), 1173 area.getWidth() - size.width, area.getHeight() 1174 ); 1175 } 1176 1177 else if (position == RectangleEdge.LEFT) { 1178 Size2D size = t.arrange(g2, constraint); 1179 titleArea = createAlignedRectangle2D( 1180 size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment() 1181 ); 1182 retValue = t.draw(g2, titleArea, p); 1183 area.setRect( 1184 area.getX() + size.width, area.getY(), 1185 area.getWidth() - size.width, area.getHeight() 1186 ); 1187 } 1188 else { 1189 throw new RuntimeException ("Unrecognised title position."); 1190 } 1191 EntityCollection result = null; 1192 if (retValue instanceof EntityBlockResult) { 1193 EntityBlockResult ebr = (EntityBlockResult) retValue; 1194 result = ebr.getEntityCollection(); 1195 } 1196 return result; 1197 } 1198 1199 1207 public BufferedImage createBufferedImage(int width, int height) { 1208 return createBufferedImage(width, height, null); 1209 } 1210 1211 1221 public BufferedImage createBufferedImage(int width, int height, 1222 ChartRenderingInfo info) { 1223 return createBufferedImage( 1224 width, height, BufferedImage.TYPE_INT_RGB, info 1225 ); 1226 } 1227 1228 1239 public BufferedImage createBufferedImage(int width, int height, 1240 int imageType, 1241 ChartRenderingInfo info) { 1242 BufferedImage image = new BufferedImage (width, height, imageType); 1243 Graphics2D g2 = image.createGraphics(); 1244 draw(g2, new Rectangle2D.Double (0, 0, width, height), null, info); 1245 g2.dispose(); 1246 return image; 1247 } 1248 1249 1263 public BufferedImage createBufferedImage(int imageWidth, 1264 int imageHeight, 1265 double drawWidth, 1266 double drawHeight, 1267 ChartRenderingInfo info) { 1268 1269 BufferedImage image = new BufferedImage ( 1270 imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB 1271 ); 1272 Graphics2D g2 = image.createGraphics(); 1273 double scaleX = imageWidth / drawWidth; 1274 double scaleY = imageHeight / drawHeight; 1275 AffineTransform st = AffineTransform.getScaleInstance(scaleX, scaleY); 1276 g2.transform(st); 1277 draw( 1278 g2, new Rectangle2D.Double (0, 0, drawWidth, drawHeight), null, info 1279 ); 1280 g2.dispose(); 1281 return image; 1282 1283 } 1284 1285 1297 public void handleClick(int x, int y, ChartRenderingInfo info) { 1298 1299 this.plot.handleClick(x, y, info.getPlotInfo()); 1302 1303 } 1304 1305 1310 public void addChangeListener(ChartChangeListener listener) { 1311 if (listener == null) { 1312 throw new IllegalArgumentException ("Null 'listener' argument."); 1313 } 1314 this.changeListeners.add(ChartChangeListener.class, listener); 1315 } 1316 1317 1322 public void removeChangeListener(ChartChangeListener listener) { 1323 if (listener == null) { 1324 throw new IllegalArgumentException ("Null 'listener' argument."); 1325 } 1326 this.changeListeners.remove(ChartChangeListener.class, listener); 1327 } 1328 1329 1334 public void fireChartChanged() { 1335 ChartChangeEvent event = new ChartChangeEvent(this); 1336 notifyListeners(event); 1337 } 1338 1339 1345 protected void notifyListeners(ChartChangeEvent event) { 1346 if (this.notify) { 1347 Object [] listeners = this.changeListeners.getListenerList(); 1348 for (int i = listeners.length - 2; i >= 0; i -= 2) { 1349 if (listeners[i] == ChartChangeListener.class) { 1350 ((ChartChangeListener) listeners[i + 1]).chartChanged( 1351 event 1352 ); 1353 } 1354 } 1355 } 1356 } 1357 1358 1364 public void addProgressListener(ChartProgressListener listener) { 1365 this.progressListeners.add(ChartProgressListener.class, listener); 1366 } 1367 1368 1373 public void removeProgressListener(ChartProgressListener listener) { 1374 this.progressListeners.remove(ChartProgressListener.class, listener); 1375 } 1376 1377 1383 protected void notifyListeners(ChartProgressEvent event) { 1384 1385 Object [] listeners = this.progressListeners.getListenerList(); 1386 for (int i = listeners.length - 2; i >= 0; i -= 2) { 1387 if (listeners[i] == ChartProgressListener.class) { 1388 ((ChartProgressListener) listeners[i + 1]).chartProgress(event); 1389 } 1390 } 1391 1392 } 1393 1394 1400 public void titleChanged(TitleChangeEvent event) { 1401 event.setChart(this); 1402 notifyListeners(event); 1403 } 1404 1405 1411 public void legendChanged(LegendChangeEvent event) { 1412 event.setChart(this); 1413 notifyListeners(event); 1414 } 1415 1416 1422 public void plotChanged(PlotChangeEvent event) { 1423 event.setChart(this); 1424 notifyListeners(event); 1425 } 1426 1427 1434 public boolean equals(Object obj) { 1435 1436 if (obj == this) { 1437 return true; 1438 } 1439 1440 if (!(obj instanceof JFreeChart)) { 1441 return false; 1442 } 1443 1444 JFreeChart that = (JFreeChart) obj; 1445 if (!ObjectUtilities.equal(this.title, that.title)) { 1446 return false; 1447 } 1448 if (!ObjectUtilities.equal(this.subtitles, that.subtitles)) { 1449 return false; 1450 } 1451 if (!ObjectUtilities.equal(this.oldLegend, that.oldLegend)) { 1452 return false; 1453 } 1454 if (!ObjectUtilities.equal(this.plot, that.plot)) { 1455 return false; 1456 } 1457 if (!ObjectUtilities.equal( 1458 this.backgroundPaint, that.backgroundPaint 1459 )) { 1460 return false; 1461 } 1462 if (!ObjectUtilities.equal( 1463 this.backgroundImage, that.backgroundImage 1464 )) { 1465 return false; 1466 } 1467 if (this.backgroundImageAlignment != that.backgroundImageAlignment) { 1468 return false; 1469 } 1470 if (this.backgroundImageAlpha != that.backgroundImageAlpha) { 1471 return false; 1472 } 1473 if (this.notify != that.notify) { 1474 return false; 1475 } 1476 1477 return true; 1478 1479 } 1480 1481 1488 private void writeObject(ObjectOutputStream stream) throws IOException { 1489 stream.defaultWriteObject(); 1490 SerialUtilities.writeStroke(this.borderStroke, stream); 1491 SerialUtilities.writePaint(this.borderPaint, stream); 1492 SerialUtilities.writePaint(this.backgroundPaint, stream); 1493 } 1494 1495 1503 private void readObject(ObjectInputStream stream) 1504 throws IOException , ClassNotFoundException { 1505 stream.defaultReadObject(); 1506 this.borderStroke = SerialUtilities.readStroke(stream); 1507 this.borderPaint = SerialUtilities.readPaint(stream); 1508 this.backgroundPaint = SerialUtilities.readPaint(stream); 1509 this.progressListeners = new EventListenerList (); 1510 this.changeListeners = new EventListenerList (); 1511 this.renderingHints = new RenderingHints ( 1512 RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON 1513 ); 1514 1515 if (this.title != null) { 1517 this.title.addChangeListener(this); 1518 } 1519 1520 for (int i = 0; i < getSubtitleCount(); i++) { 1521 getSubtitle(i).addChangeListener(this); 1522 } 1523 1524 if (this.oldLegend != null) { 1525 this.oldLegend.addChangeListener(this); 1526 } 1527 1528 this.plot.addChangeListener(this); 1531 1533 } 1534 1535 1540 public static void main(String [] args) { 1541 System.out.println(JFreeChart.INFO.toString()); 1542 } 1543 1544 1552 public Object clone() throws CloneNotSupportedException { 1553 JFreeChart chart = (JFreeChart) super.clone(); 1554 1555 chart.renderingHints = (RenderingHints ) this.renderingHints.clone(); 1556 1560 if (this.title != null) { 1561 chart.title = (TextTitle) this.title.clone(); 1562 chart.title.addChangeListener(chart); 1563 } 1564 1565 chart.subtitles = new ArrayList (); 1566 for (int i = 0; i < getSubtitleCount(); i++) { 1567 Title subtitle = (Title) getSubtitle(i).clone(); 1568 chart.subtitles.add(subtitle); 1569 subtitle.addChangeListener(chart); 1570 } 1571 1572 if (this.oldLegend != null) { 1573 chart.oldLegend = (OldLegend) this.oldLegend.clone(); 1574 chart.oldLegend.registerChart(chart); 1575 chart.oldLegend.addChangeListener(chart); 1576 } 1577 1578 if (this.plot != null) { 1579 chart.plot = (Plot) this.plot.clone(); 1580 chart.plot.addChangeListener(chart); 1581 } 1582 1583 1589 chart.progressListeners = new EventListenerList (); 1590 chart.changeListeners = new EventListenerList (); 1591 1593 return chart; 1594 } 1595 1596} 1597 1598 1602class JFreeChartInfo extends ProjectInfo { 1603 1604 1607 public JFreeChartInfo() { 1608 1609 String baseResourceClass 1611 = "org.jfree.chart.resources.JFreeChartResources"; 1612 ResourceBundle resources = ResourceBundle.getBundle(baseResourceClass); 1613 1614 setName(resources.getString("project.name")); 1615 setVersion(resources.getString("project.version")); 1616 setInfo(resources.getString("project.info")); 1617 setCopyright(resources.getString("project.copyright")); 1618 setLogo(null); setLicenceName("LGPL"); 1620 setLicenceText(Licences.getInstance().getLGPL()); 1621 1622 setContributors(Arrays.asList( 1623 new Contributor[]{ 1624 new Contributor("Eric Alexander", "-"), 1625 new Contributor( 1626 "Richard Atkinson", "richard_c_atkinson@ntlworld.com" 1627 ), 1628 new Contributor("David Basten", "-"), 1629 new Contributor("David Berry", "-"), 1630 new Contributor("Anthony Boulestreau", "-"), 1631 new Contributor("Jeremy Bowman", "-"), 1632 new Contributor("Nicolas Brodu", "-"), 1633 new Contributor("David Browning", "-"), 1634 new Contributor("S???ren Caspersen", "-"), 1635 new Contributor("Chuanhao Chiu", "-"), 1636 new Contributor("Brian Cole", "-"), 1637 new Contributor("Pascal Collet", "-"), 1638 new Contributor("Martin Cordova", "-"), 1639 new Contributor("Paolo Cova", "-"), 1640 new Contributor("Mike Duffy", "-"), 1641 new Contributor("Don Elliott", "-"), 1642 new Contributor("Jonathan Gabbai", "-"), 1643 new Contributor( 1644 "David Gilbert", "david.gilbert@object-refinery.com" 1645 ), 1646 new Contributor("Serge V. Grachov", "-"), 1647 new Contributor("Daniel Gredler", "-"), 1648 new Contributor("Hans-Jurgen Greiner", "-"), 1649 new Contributor("Joao Guilherme Del Valle", "-"), 1650 new Contributor("Aiman Han", "-"), 1651 new Contributor("Cameron Hayne", "-"), 1652 new Contributor("Jon Iles", "-"), 1653 new Contributor("Wolfgang Irler", "-"), 1654 new Contributor("Xun Kang", "-"), 1655 new Contributor("Bill Kelemen", "-"), 1656 new Contributor("Norbert Kiesel", "-"), 1657 new Contributor("Gideon Krause", "-"), 1658 new Contributor("Arnaud Lelievre", "-"), 1659 new Contributor("Wolfgang Lenhard", "-"), 1660 new Contributor("David Li", "-"), 1661 new Contributor("Tin Luu", "-"), 1662 new Contributor("Craig MacFarlane", "-"), 1663 new Contributor("Achilleus Mantzios", "-"), 1664 new Contributor("Thomas Meier", "-"), 1665 new Contributor("Jim Moore", "-"), 1666 new Contributor("Jonathan Nash", "-"), 1667 new Contributor("Barak Naveh", "-"), 1668 new Contributor("David M. O'Donnell", "-"), 1669 new Contributor("Krzysztof Paz", "-"), 1670 new Contributor("Tomer Peretz", "-"), 1671 new Contributor("Andrzej Porebski", "-"), 1672 new Contributor("Xavier Poinsard", "-"), 1673 new Contributor("Viktor Rajewski", "-"), 1674 new Contributor("Eduardo Ramalho", "-"), 1675 new Contributor("Michael Rauch", "-"), 1676 new Contributor("Cameron Riley", "-"), 1677 new Contributor("Dan Rivett", "d.rivett@ukonline.co.uk"), 1678 new Contributor("Scott Sams", "-"), 1679 new Contributor("Michel Santos", "-"), 1680 new Contributor("Thierry Saura", "-"), 1681 new Contributor("Andreas Schneider", "-"), 1682 new Contributor("Jean-Luc SCHWAB", "-"), 1683 new Contributor("Bryan Scott", "-"), 1684 new Contributor("Tobias Selb", "-"), 1685 new Contributor("Mofeed Shahin", "-"), 1686 new Contributor("Greg Steckman", "-"), 1687 new Contributor("Roger Studner", "-"), 1688 new Contributor("Irv Thomae", "-"), 1689 new Contributor("Eric Thomas", "-"), 1690 new Contributor("Rich Unger", "-"), 1691 new Contributor("Daniel van Enckevort", "-"), 1692 new Contributor("Laurence Vanhelsuwe", "-"), 1693 new Contributor("Sylvain Vieujot", "-"), 1694 new Contributor("Mark Watson", "www.markwatson.com"), 1695 new Contributor("Alex Weber", "-"), 1696 new Contributor("Matthew Wright", "-"), 1697 new Contributor("Benoit Xhenseval", "-"), 1698 new Contributor( 1699 "Christian W. Zuckschwerdt", 1700 "Christian.Zuckschwerdt@Informatik.Uni-Oldenburg.de" 1701 ), 1702 new Contributor("Hari", "-"), 1703 new Contributor("Sam (oldman)", "-"), 1704 } 1705 )); 1706 1707 addLibrary(JCommon.INFO); 1708 1709 } 1710 1711 1716 public Image getLogo() { 1717 1718 Image logo = super.getLogo(); 1719 if (logo == null) { 1720 URL imageURL = ClassLoader.getSystemResource( 1721 "org/jfree/chart/gorilla.jpg" 1722 ); 1723 if (imageURL != null) { 1724 ImageIcon temp = new ImageIcon (imageURL); 1725 logo = temp.getImage(); 1727 setLogo(logo); 1728 } 1729 } 1730 return logo; 1731 1732 } 1733 1734} 1735 | Popular Tags |