1 90 91 package org.jfree.chart.renderer.category; 92 93 import java.awt.AlphaComposite ; 94 import java.awt.Composite ; 95 import java.awt.Font ; 96 import java.awt.GradientPaint ; 97 import java.awt.Graphics2D ; 98 import java.awt.Paint ; 99 import java.awt.Shape ; 100 import java.awt.Stroke ; 101 import java.awt.geom.Line2D ; 102 import java.awt.geom.Point2D ; 103 import java.awt.geom.Rectangle2D ; 104 import java.io.Serializable ; 105 106 import org.jfree.chart.LegendItem; 107 import org.jfree.chart.LegendItemCollection; 108 import org.jfree.chart.axis.CategoryAxis; 109 import org.jfree.chart.axis.ValueAxis; 110 import org.jfree.chart.entity.CategoryItemEntity; 111 import org.jfree.chart.entity.EntityCollection; 112 import org.jfree.chart.event.RendererChangeEvent; 113 import org.jfree.chart.labels.CategoryItemLabelGenerator; 114 import org.jfree.chart.labels.CategorySeriesLabelGenerator; 115 import org.jfree.chart.labels.CategoryToolTipGenerator; 116 import org.jfree.chart.labels.ItemLabelPosition; 117 import org.jfree.chart.labels.StandardCategorySeriesLabelGenerator; 118 import org.jfree.chart.plot.CategoryMarker; 119 import org.jfree.chart.plot.CategoryPlot; 120 import org.jfree.chart.plot.DrawingSupplier; 121 import org.jfree.chart.plot.IntervalMarker; 122 import org.jfree.chart.plot.Marker; 123 import org.jfree.chart.plot.PlotOrientation; 124 import org.jfree.chart.plot.PlotRenderingInfo; 125 import org.jfree.chart.plot.ValueMarker; 126 import org.jfree.chart.renderer.AbstractRenderer; 127 import org.jfree.chart.urls.CategoryURLGenerator; 128 import org.jfree.data.Range; 129 import org.jfree.data.category.CategoryDataset; 130 import org.jfree.data.general.DatasetUtilities; 131 import org.jfree.text.TextUtilities; 132 import org.jfree.ui.GradientPaintTransformer; 133 import org.jfree.ui.LengthAdjustmentType; 134 import org.jfree.ui.RectangleAnchor; 135 import org.jfree.ui.RectangleInsets; 136 import org.jfree.util.ObjectList; 137 import org.jfree.util.ObjectUtilities; 138 import org.jfree.util.PublicCloneable; 139 140 146 public abstract class AbstractCategoryItemRenderer extends AbstractRenderer 147 implements CategoryItemRenderer, Cloneable , PublicCloneable, Serializable { 148 149 150 private static final long serialVersionUID = 1247553218442497391L; 151 152 153 private CategoryPlot plot; 154 155 156 private CategoryItemLabelGenerator itemLabelGenerator; 157 158 159 private ObjectList itemLabelGeneratorList; 160 161 162 private CategoryItemLabelGenerator baseItemLabelGenerator; 163 164 165 private CategoryToolTipGenerator toolTipGenerator; 166 167 168 private ObjectList toolTipGeneratorList; 169 170 171 private CategoryToolTipGenerator baseToolTipGenerator; 172 173 174 private CategoryURLGenerator itemURLGenerator; 175 176 177 private ObjectList itemURLGeneratorList; 178 179 180 private CategoryURLGenerator baseItemURLGenerator; 181 182 183 private CategorySeriesLabelGenerator legendItemLabelGenerator; 184 185 186 private CategorySeriesLabelGenerator legendItemToolTipGenerator; 187 188 189 private CategorySeriesLabelGenerator legendItemURLGenerator; 190 191 192 private transient int rowCount; 193 194 195 private transient int columnCount; 196 197 204 protected AbstractCategoryItemRenderer() { 205 this.itemLabelGenerator = null; 206 this.itemLabelGeneratorList = new ObjectList(); 207 this.toolTipGenerator = null; 208 this.toolTipGeneratorList = new ObjectList(); 209 this.itemURLGenerator = null; 210 this.itemURLGeneratorList = new ObjectList(); 211 this.legendItemLabelGenerator 212 = new StandardCategorySeriesLabelGenerator(); 213 } 214 215 222 public int getPassCount() { 223 return 1; 224 } 225 226 233 public CategoryPlot getPlot() { 234 return this.plot; 235 } 236 237 244 public void setPlot(CategoryPlot plot) { 245 if (plot == null) { 246 throw new IllegalArgumentException ("Null 'plot' argument."); 247 } 248 this.plot = plot; 249 } 250 251 253 264 public CategoryItemLabelGenerator getItemLabelGenerator(int row, 265 int column) { 266 return getSeriesItemLabelGenerator(row); 267 } 268 269 276 public CategoryItemLabelGenerator getSeriesItemLabelGenerator(int series) { 277 278 if (this.itemLabelGenerator != null) { 280 return this.itemLabelGenerator; 281 } 282 283 CategoryItemLabelGenerator generator = (CategoryItemLabelGenerator) 285 this.itemLabelGeneratorList.get(series); 286 if (generator == null) { 287 generator = this.baseItemLabelGenerator; 288 } 289 return generator; 290 291 } 292 293 299 public void setItemLabelGenerator(CategoryItemLabelGenerator generator) { 300 this.itemLabelGenerator = generator; 301 notifyListeners(new RendererChangeEvent(this)); 302 } 303 304 311 public void setSeriesItemLabelGenerator(int series, 312 CategoryItemLabelGenerator generator) { 313 this.itemLabelGeneratorList.set(series, generator); 314 notifyListeners(new RendererChangeEvent(this)); 315 } 316 317 322 public CategoryItemLabelGenerator getBaseItemLabelGenerator() { 323 return this.baseItemLabelGenerator; 324 } 325 326 332 public void setBaseItemLabelGenerator(CategoryItemLabelGenerator generator) 333 { 334 this.baseItemLabelGenerator = generator; 335 notifyListeners(new RendererChangeEvent(this)); 336 } 337 338 340 352 public CategoryToolTipGenerator getToolTipGenerator(int row, int column) { 353 354 CategoryToolTipGenerator result = null; 355 if (this.toolTipGenerator != null) { 356 result = this.toolTipGenerator; 357 } 358 else { 359 result = getSeriesToolTipGenerator(row); 360 if (result == null) { 361 result = this.baseToolTipGenerator; 362 } 363 } 364 return result; 365 } 366 367 373 public CategoryToolTipGenerator getToolTipGenerator() { 374 return this.toolTipGenerator; 375 } 376 377 384 public void setToolTipGenerator(CategoryToolTipGenerator generator) { 385 this.toolTipGenerator = generator; 386 notifyListeners(new RendererChangeEvent(this)); 387 } 388 389 397 public CategoryToolTipGenerator getSeriesToolTipGenerator(int series) { 398 return (CategoryToolTipGenerator) this.toolTipGeneratorList.get(series); 399 } 400 401 409 public void setSeriesToolTipGenerator(int series, 410 CategoryToolTipGenerator generator) { 411 this.toolTipGeneratorList.set(series, generator); 412 notifyListeners(new RendererChangeEvent(this)); 413 } 414 415 420 public CategoryToolTipGenerator getBaseToolTipGenerator() { 421 return this.baseToolTipGenerator; 422 } 423 424 431 public void setBaseToolTipGenerator(CategoryToolTipGenerator generator) { 432 this.baseToolTipGenerator = generator; 433 notifyListeners(new RendererChangeEvent(this)); 434 } 435 436 438 448 public CategoryURLGenerator getItemURLGenerator(int row, int column) { 449 return getSeriesItemURLGenerator(row); 450 } 451 452 459 public CategoryURLGenerator getSeriesItemURLGenerator(int series) { 460 461 if (this.itemURLGenerator != null) { 463 return this.itemURLGenerator; 464 } 465 466 CategoryURLGenerator generator 468 = (CategoryURLGenerator) this.itemURLGeneratorList.get(series); 469 if (generator == null) { 470 generator = this.baseItemURLGenerator; 471 } 472 return generator; 473 474 } 475 476 481 public void setItemURLGenerator(CategoryURLGenerator generator) { 482 this.itemURLGenerator = generator; 483 } 484 485 491 public void setSeriesItemURLGenerator(int series, 492 CategoryURLGenerator generator) { 493 this.itemURLGeneratorList.set(series, generator); 494 } 495 496 501 public CategoryURLGenerator getBaseItemURLGenerator() { 502 return this.baseItemURLGenerator; 503 } 504 505 510 public void setBaseItemURLGenerator(CategoryURLGenerator generator) { 511 this.baseItemURLGenerator = generator; 512 } 513 514 520 public int getRowCount() { 521 return this.rowCount; 522 } 523 524 530 public int getColumnCount() { 531 return this.columnCount; 532 } 533 534 555 public CategoryItemRendererState initialise(Graphics2D g2, 556 Rectangle2D dataArea, 557 CategoryPlot plot, 558 int rendererIndex, 559 PlotRenderingInfo info) { 560 561 setPlot(plot); 562 CategoryDataset data = plot.getDataset(rendererIndex); 563 if (data != null) { 564 this.rowCount = data.getRowCount(); 565 this.columnCount = data.getColumnCount(); 566 } 567 else { 568 this.rowCount = 0; 569 this.columnCount = 0; 570 } 571 return new CategoryItemRendererState(info); 572 573 } 574 575 584 public Range findRangeBounds(CategoryDataset dataset) { 585 return DatasetUtilities.findRangeBounds(dataset); 586 } 587 588 597 public void drawBackground(Graphics2D g2, 598 CategoryPlot plot, 599 Rectangle2D dataArea) { 600 601 plot.drawBackground(g2, dataArea); 602 603 } 604 605 614 public void drawOutline(Graphics2D g2, 615 CategoryPlot plot, 616 Rectangle2D dataArea) { 617 618 plot.drawOutline(g2, dataArea); 619 620 } 621 622 635 public void drawDomainGridline(Graphics2D g2, 636 CategoryPlot plot, 637 Rectangle2D dataArea, 638 double value) { 639 640 Line2D line = null; 641 PlotOrientation orientation = plot.getOrientation(); 642 643 if (orientation == PlotOrientation.HORIZONTAL) { 644 line = new Line2D.Double (dataArea.getMinX(), value, 645 dataArea.getMaxX(), value); 646 } 647 else if (orientation == PlotOrientation.VERTICAL) { 648 line = new Line2D.Double (value, dataArea.getMinY(), value, 649 dataArea.getMaxY()); 650 } 651 652 Paint paint = plot.getDomainGridlinePaint(); 653 if (paint == null) { 654 paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT; 655 } 656 g2.setPaint(paint); 657 658 Stroke stroke = plot.getDomainGridlineStroke(); 659 if (stroke == null) { 660 stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE; 661 } 662 g2.setStroke(stroke); 663 664 g2.draw(line); 665 666 } 667 668 679 public void drawRangeGridline(Graphics2D g2, 680 CategoryPlot plot, 681 ValueAxis axis, 682 Rectangle2D dataArea, 683 double value) { 684 685 Range range = axis.getRange(); 686 if (!range.contains(value)) { 687 return; 688 } 689 690 PlotOrientation orientation = plot.getOrientation(); 691 double v = axis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); 692 Line2D line = null; 693 if (orientation == PlotOrientation.HORIZONTAL) { 694 line = new Line2D.Double (v, dataArea.getMinY(), v, 695 dataArea.getMaxY()); 696 } 697 else if (orientation == PlotOrientation.VERTICAL) { 698 line = new Line2D.Double (dataArea.getMinX(), v, 699 dataArea.getMaxX(), v); 700 } 701 702 Paint paint = plot.getRangeGridlinePaint(); 703 if (paint == null) { 704 paint = CategoryPlot.DEFAULT_GRIDLINE_PAINT; 705 } 706 g2.setPaint(paint); 707 708 Stroke stroke = plot.getRangeGridlineStroke(); 709 if (stroke == null) { 710 stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE; 711 } 712 g2.setStroke(stroke); 713 714 g2.draw(line); 715 716 } 717 718 727 public void drawDomainMarker(Graphics2D g2, 728 CategoryPlot plot, 729 CategoryAxis axis, 730 CategoryMarker marker, 731 Rectangle2D dataArea) { 732 733 Comparable category = marker.getKey(); 734 CategoryDataset dataset = plot.getDataset(plot.getIndexOf(this)); 735 int columnIndex = dataset.getColumnIndex(category); 736 if (columnIndex < 0) { 737 return; 738 } 739 740 final Composite savedComposite = g2.getComposite(); 741 g2.setComposite(AlphaComposite.getInstance( 742 AlphaComposite.SRC_OVER, marker.getAlpha())); 743 744 PlotOrientation orientation = plot.getOrientation(); 745 Rectangle2D bounds = null; 746 if (marker.getDrawAsLine()) { 747 double v = axis.getCategoryMiddle(columnIndex, 748 dataset.getColumnCount(), dataArea, 749 plot.getDomainAxisEdge()); 750 Line2D line = null; 751 if (orientation == PlotOrientation.HORIZONTAL) { 752 line = new Line2D.Double (dataArea.getMinX(), v, 753 dataArea.getMaxX(), v); 754 } 755 else if (orientation == PlotOrientation.VERTICAL) { 756 line = new Line2D.Double (v, dataArea.getMinY(), v, 757 dataArea.getMaxY()); 758 } 759 g2.setPaint(marker.getPaint()); 760 g2.setStroke(marker.getStroke()); 761 g2.draw(line); 762 bounds = line.getBounds2D(); 763 } 764 else { 765 double v0 = axis.getCategoryStart(columnIndex, 766 dataset.getColumnCount(), dataArea, 767 plot.getDomainAxisEdge()); 768 double v1 = axis.getCategoryEnd(columnIndex, 769 dataset.getColumnCount(), dataArea, 770 plot.getDomainAxisEdge()); 771 Rectangle2D area = null; 772 if (orientation == PlotOrientation.HORIZONTAL) { 773 area = new Rectangle2D.Double (dataArea.getMinX(), v0, 774 dataArea.getWidth(), (v1 - v0)); 775 } 776 else if (orientation == PlotOrientation.VERTICAL) { 777 area = new Rectangle2D.Double (v0, dataArea.getMinY(), 778 (v1 - v0), dataArea.getHeight()); 779 } 780 g2.setPaint(marker.getPaint()); 781 g2.fill(area); 782 bounds = area; 783 } 784 785 String label = marker.getLabel(); 786 RectangleAnchor anchor = marker.getLabelAnchor(); 787 if (label != null) { 788 Font labelFont = marker.getLabelFont(); 789 g2.setFont(labelFont); 790 g2.setPaint(marker.getLabelPaint()); 791 Point2D coordinates = calculateDomainMarkerTextAnchorPoint( 792 g2, orientation, dataArea, bounds, marker.getLabelOffset(), 793 marker.getLabelOffsetType(), anchor); 794 TextUtilities.drawAlignedString(label, g2, 795 (float) coordinates.getX(), (float) coordinates.getY(), 796 marker.getLabelTextAnchor()); 797 } 798 g2.setComposite(savedComposite); 799 } 800 801 810 public void drawRangeMarker(Graphics2D g2, 811 CategoryPlot plot, 812 ValueAxis axis, 813 Marker marker, 814 Rectangle2D dataArea) { 815 816 if (marker instanceof ValueMarker) { 817 ValueMarker vm = (ValueMarker) marker; 818 double value = vm.getValue(); 819 Range range = axis.getRange(); 820 821 if (!range.contains(value)) { 822 return; 823 } 824 825 final Composite savedComposite = g2.getComposite(); 826 g2.setComposite(AlphaComposite.getInstance( 827 AlphaComposite.SRC_OVER, marker.getAlpha())); 828 829 PlotOrientation orientation = plot.getOrientation(); 830 double v = axis.valueToJava2D(value, dataArea, 831 plot.getRangeAxisEdge()); 832 Line2D line = null; 833 if (orientation == PlotOrientation.HORIZONTAL) { 834 line = new Line2D.Double (v, dataArea.getMinY(), v, 835 dataArea.getMaxY()); 836 } 837 else if (orientation == PlotOrientation.VERTICAL) { 838 line = new Line2D.Double (dataArea.getMinX(), v, 839 dataArea.getMaxX(), v); 840 } 841 842 g2.setPaint(marker.getPaint()); 843 g2.setStroke(marker.getStroke()); 844 g2.draw(line); 845 846 String label = marker.getLabel(); 847 RectangleAnchor anchor = marker.getLabelAnchor(); 848 if (label != null) { 849 Font labelFont = marker.getLabelFont(); 850 g2.setFont(labelFont); 851 g2.setPaint(marker.getLabelPaint()); 852 Point2D coordinates = calculateRangeMarkerTextAnchorPoint( 853 g2, orientation, dataArea, line.getBounds2D(), 854 marker.getLabelOffset(), LengthAdjustmentType.EXPAND, 855 anchor); 856 TextUtilities.drawAlignedString(label, g2, 857 (float) coordinates.getX(), (float) coordinates.getY(), 858 marker.getLabelTextAnchor()); 859 } 860 g2.setComposite(savedComposite); 861 } 862 else if (marker instanceof IntervalMarker) { 863 864 IntervalMarker im = (IntervalMarker) marker; 865 double start = im.getStartValue(); 866 double end = im.getEndValue(); 867 Range range = axis.getRange(); 868 if (!(range.intersects(start, end))) { 869 return; 870 } 871 872 final Composite savedComposite = g2.getComposite(); 873 g2.setComposite(AlphaComposite.getInstance( 874 AlphaComposite.SRC_OVER, marker.getAlpha())); 875 876 double start2d = axis.valueToJava2D(start, dataArea, 877 plot.getRangeAxisEdge()); 878 double end2d = axis.valueToJava2D(end, dataArea, 879 plot.getRangeAxisEdge()); 880 881 PlotOrientation orientation = plot.getOrientation(); 882 Rectangle2D rect = null; 883 if (orientation == PlotOrientation.HORIZONTAL) { 884 rect = new Rectangle2D.Double (Math.min(start2d, end2d), 885 dataArea.getMinY(), Math.abs(end2d - start2d), 886 dataArea.getHeight()); 887 } 888 else if (orientation == PlotOrientation.VERTICAL) { 889 rect = new Rectangle2D.Double (dataArea.getMinX(), 890 Math.min(start2d, end2d), dataArea.getWidth(), 891 Math.abs(end2d - start2d)); 892 } 893 Paint p = marker.getPaint(); 894 if (p instanceof GradientPaint ) { 895 GradientPaint gp = (GradientPaint ) p; 896 GradientPaintTransformer t = im.getGradientPaintTransformer(); 897 if (t != null) { 898 gp = t.transform(gp, rect); 899 } 900 g2.setPaint(gp); 901 } 902 else { 903 g2.setPaint(p); 904 } 905 g2.fill(rect); 906 907 if (im.getOutlinePaint() != null && im.getOutlineStroke() != null) { 909 double x0 = rect.getMinX(); 910 double x1 = rect.getMaxX(); 911 double y0 = rect.getMinY(); 912 double y1 = rect.getMaxY(); 913 if (orientation == PlotOrientation.VERTICAL) { 914 Line2D line = new Line2D.Double (x0, y0, x1, y0); 915 g2.setPaint(im.getOutlinePaint()); 916 g2.setStroke(im.getOutlineStroke()); 917 g2.draw(line); 918 line.setLine(x0, y1, x1, y1); 919 g2.draw(line); 920 } 921 else { Line2D line = new Line2D.Double (x0, y0, x0, y1); 923 g2.setPaint(im.getOutlinePaint()); 924 g2.setStroke(im.getOutlineStroke()); 925 g2.draw(line); 926 line.setLine(x1, y0, x1, y1); 927 g2.draw(line); 928 } 929 } 930 931 String label = marker.getLabel(); 932 RectangleAnchor anchor = marker.getLabelAnchor(); 933 if (label != null) { 934 Font labelFont = marker.getLabelFont(); 935 g2.setFont(labelFont); 936 g2.setPaint(marker.getLabelPaint()); 937 Point2D coordinates = calculateRangeMarkerTextAnchorPoint( 938 g2, orientation, dataArea, rect, 939 marker.getLabelOffset(), marker.getLabelOffsetType(), 940 anchor); 941 TextUtilities.drawAlignedString(label, g2, 942 (float) coordinates.getX(), (float) coordinates.getY(), 943 marker.getLabelTextAnchor()); 944 } 945 g2.setComposite(savedComposite); 946 947 } 948 949 } 950 951 965 protected Point2D calculateDomainMarkerTextAnchorPoint(Graphics2D g2, 966 PlotOrientation orientation, 967 Rectangle2D dataArea, 968 Rectangle2D markerArea, 969 RectangleInsets markerOffset, 970 LengthAdjustmentType labelOffsetType, 971 RectangleAnchor anchor) { 972 973 Rectangle2D anchorRect = null; 974 if (orientation == PlotOrientation.HORIZONTAL) { 975 anchorRect = markerOffset.createAdjustedRectangle(markerArea, 976 LengthAdjustmentType.CONTRACT, labelOffsetType); 977 } 978 else if (orientation == PlotOrientation.VERTICAL) { 979 anchorRect = markerOffset.createAdjustedRectangle(markerArea, 980 labelOffsetType, LengthAdjustmentType.CONTRACT); 981 } 982 return RectangleAnchor.coordinates(anchorRect, anchor); 983 984 } 985 986 999 protected Point2D calculateRangeMarkerTextAnchorPoint(Graphics2D g2, 1000 PlotOrientation orientation, 1001 Rectangle2D dataArea, 1002 Rectangle2D markerArea, 1003 RectangleInsets markerOffset, 1004 LengthAdjustmentType labelOffsetType, 1005 RectangleAnchor anchor) { 1006 1007 Rectangle2D anchorRect = null; 1008 if (orientation == PlotOrientation.HORIZONTAL) { 1009 anchorRect = markerOffset.createAdjustedRectangle(markerArea, 1010 labelOffsetType, LengthAdjustmentType.CONTRACT); 1011 } 1012 else if (orientation == PlotOrientation.VERTICAL) { 1013 anchorRect = markerOffset.createAdjustedRectangle(markerArea, 1014 LengthAdjustmentType.CONTRACT, labelOffsetType); 1015 } 1016 return RectangleAnchor.coordinates(anchorRect, anchor); 1017 1018 } 1019 1020 1028 public LegendItem getLegendItem(int datasetIndex, int series) { 1029 1030 CategoryPlot p = getPlot(); 1031 if (p == null) { 1032 return null; 1033 } 1034 1035 CategoryDataset dataset; 1036 dataset = p.getDataset(datasetIndex); 1037 String label = this.legendItemLabelGenerator.generateLabel(dataset, 1038 series); 1039 String description = label; 1040 String toolTipText = null; 1041 if (this.legendItemToolTipGenerator != null) { 1042 toolTipText = this.legendItemToolTipGenerator.generateLabel( 1043 dataset, series); 1044 } 1045 String urlText = null; 1046 if (this.legendItemURLGenerator != null) { 1047 urlText = this.legendItemURLGenerator.generateLabel(dataset, 1048 series); 1049 } 1050 Shape shape = getSeriesShape(series); 1051 Paint paint = getSeriesPaint(series); 1052 Paint outlinePaint = getSeriesOutlinePaint(series); 1053 Stroke outlineStroke = getSeriesOutlineStroke(series); 1054 1055 LegendItem item = new LegendItem(label, description, toolTipText, 1056 urlText, shape, paint, outlineStroke, outlinePaint); 1057 item.setSeriesIndex(series); 1058 item.setDatasetIndex(datasetIndex); 1059 return item; 1060 } 1061 1062 1069 public boolean equals(Object obj) { 1070 1071 if (obj == this) { 1072 return true; 1073 } 1074 if (!(obj instanceof AbstractCategoryItemRenderer)) { 1075 return false; 1076 } 1077 if (!super.equals(obj)) { 1078 return false; 1079 } 1080 1081 AbstractCategoryItemRenderer that = (AbstractCategoryItemRenderer) obj; 1082 1083 if (!ObjectUtilities.equal(this.itemLabelGenerator, 1084 that.itemLabelGenerator)) { 1085 return false; 1086 } 1087 if (!ObjectUtilities.equal(this.itemLabelGeneratorList, 1088 that.itemLabelGeneratorList)) { 1089 return false; 1090 } 1091 if (!ObjectUtilities.equal(this.baseItemLabelGenerator, 1092 that.baseItemLabelGenerator)) { 1093 return false; 1094 } 1095 if (!ObjectUtilities.equal(this.toolTipGenerator, 1096 that.toolTipGenerator)) { 1097 return false; 1098 } 1099 if (!ObjectUtilities.equal(this.toolTipGeneratorList, 1100 that.toolTipGeneratorList)) { 1101 return false; 1102 } 1103 if (!ObjectUtilities.equal(this.baseToolTipGenerator, 1104 that.baseToolTipGenerator)) { 1105 return false; 1106 } 1107 if (!ObjectUtilities.equal(this.itemURLGenerator, 1108 that.itemURLGenerator)) { 1109 return false; 1110 } 1111 if (!ObjectUtilities.equal(this.itemURLGeneratorList, 1112 that.itemURLGeneratorList)) { 1113 return false; 1114 } 1115 if (!ObjectUtilities.equal(this.baseItemURLGenerator, 1116 that.baseItemURLGenerator)) { 1117 return false; 1118 } 1119 1120 return true; 1121 1122 } 1123 1124 1129 public int hashCode() { 1130 int result = super.hashCode(); 1131 return result; 1132 } 1133 1134 1139 public DrawingSupplier getDrawingSupplier() { 1140 DrawingSupplier result = null; 1141 CategoryPlot cp = getPlot(); 1142 if (cp != null) { 1143 result = cp.getDrawingSupplier(); 1144 } 1145 return result; 1146 } 1147 1148 1161 protected void drawItemLabel(Graphics2D g2, 1162 PlotOrientation orientation, 1163 CategoryDataset dataset, 1164 int row, int column, 1165 double x, double y, 1166 boolean negative) { 1167 1168 CategoryItemLabelGenerator generator 1169 = getItemLabelGenerator(row, column); 1170 if (generator != null) { 1171 Font labelFont = getItemLabelFont(row, column); 1172 Paint paint = getItemLabelPaint(row, column); 1173 g2.setFont(labelFont); 1174 g2.setPaint(paint); 1175 String label = generator.generateLabel(dataset, row, column); 1176 ItemLabelPosition position = null; 1177 if (!negative) { 1178 position = getPositiveItemLabelPosition(row, column); 1179 } 1180 else { 1181 position = getNegativeItemLabelPosition(row, column); 1182 } 1183 Point2D anchorPoint = calculateLabelAnchorPoint( 1184 position.getItemLabelAnchor(), x, y, orientation); 1185 TextUtilities.drawRotatedString(label, g2, 1186 (float) anchorPoint.getX(), (float) anchorPoint.getY(), 1187 position.getTextAnchor(), 1188 position.getAngle(), position.getRotationAnchor()); 1189 } 1190 1191 } 1192 1193 1203 public Object clone() throws CloneNotSupportedException { 1204 1205 AbstractCategoryItemRenderer clone 1206 = (AbstractCategoryItemRenderer) super.clone(); 1207 1208 if (this.itemLabelGenerator != null) { 1209 if (this.itemLabelGenerator instanceof PublicCloneable) { 1210 PublicCloneable pc = (PublicCloneable) this.itemLabelGenerator; 1211 clone.itemLabelGenerator 1212 = (CategoryItemLabelGenerator) pc.clone(); 1213 } 1214 else { 1215 throw new CloneNotSupportedException ( 1216 "ItemLabelGenerator not cloneable." 1217 ); 1218 } 1219 } 1220 1221 if (this.itemLabelGeneratorList != null) { 1222 clone.itemLabelGeneratorList 1223 = (ObjectList) this.itemLabelGeneratorList.clone(); 1224 } 1225 1226 if (this.baseItemLabelGenerator != null) { 1227 if (this.baseItemLabelGenerator instanceof PublicCloneable) { 1228 PublicCloneable pc 1229 = (PublicCloneable) this.baseItemLabelGenerator; 1230 clone.baseItemLabelGenerator 1231 = (CategoryItemLabelGenerator) pc.clone(); 1232 } 1233 else { 1234 throw new CloneNotSupportedException ( 1235 "ItemLabelGenerator not cloneable." 1236 ); 1237 } 1238 } 1239 1240 if (this.toolTipGenerator != null) { 1241 if (this.toolTipGenerator instanceof PublicCloneable) { 1242 PublicCloneable pc = (PublicCloneable) this.toolTipGenerator; 1243 clone.toolTipGenerator = (CategoryToolTipGenerator) pc.clone(); 1244 } 1245 else { 1246 throw new CloneNotSupportedException ( 1247 "Tool tip generator not cloneable."); 1248 } 1249 } 1250 1251 if (this.toolTipGeneratorList != null) { 1252 clone.toolTipGeneratorList 1253 = (ObjectList) this.toolTipGeneratorList.clone(); 1254 } 1255 1256 if (this.baseToolTipGenerator != null) { 1257 if (this.baseToolTipGenerator instanceof PublicCloneable) { 1258 PublicCloneable pc 1259 = (PublicCloneable) this.baseToolTipGenerator; 1260 clone.baseToolTipGenerator 1261 = (CategoryToolTipGenerator) pc.clone(); 1262 } 1263 else { 1264 throw new CloneNotSupportedException ( 1265 "Base tool tip generator not cloneable."); 1266 } 1267 } 1268 1269 if (this.itemURLGenerator != null) { 1270 if (this.itemURLGenerator instanceof PublicCloneable) { 1271 PublicCloneable pc = (PublicCloneable) this.itemURLGenerator; 1272 clone.itemURLGenerator = (CategoryURLGenerator) pc.clone(); 1273 } 1274 else { 1275 throw new CloneNotSupportedException ( 1276 "Item URL generator not cloneable."); 1277 } 1278 } 1279 1280 if (this.itemURLGeneratorList != null) { 1281 clone.itemURLGeneratorList 1282 = (ObjectList) this.itemURLGeneratorList.clone(); 1283 } 1284 1285 if (this.baseItemURLGenerator != null) { 1286 if (this.baseItemURLGenerator instanceof PublicCloneable) { 1287 PublicCloneable pc 1288 = (PublicCloneable) this.baseItemURLGenerator; 1289 clone.baseItemURLGenerator = (CategoryURLGenerator) pc.clone(); 1290 } 1291 else { 1292 throw new CloneNotSupportedException ( 1293 "Base item URL generator not cloneable."); 1294 } 1295 } 1296 1297 return clone; 1298 } 1299 1300 1308 protected CategoryAxis getDomainAxis(CategoryPlot plot, int index) { 1309 CategoryAxis result = plot.getDomainAxis(index); 1310 if (result == null) { 1311 result = plot.getDomainAxis(); 1312 } 1313 return result; 1314 } 1315 1316 1324 protected ValueAxis getRangeAxis(CategoryPlot plot, int index) { 1325 ValueAxis result = plot.getRangeAxis(index); 1326 if (result == null) { 1327 result = plot.getRangeAxis(); 1328 } 1329 return result; 1330 } 1331 1332 1338 public LegendItemCollection getLegendItems() { 1339 if (this.plot == null) { 1340 return new LegendItemCollection(); 1341 } 1342 LegendItemCollection result = new LegendItemCollection(); 1343 int index = this.plot.getIndexOf(this); 1344 CategoryDataset dataset = this.plot.getDataset(index); 1345 if (dataset != null) { 1346 int seriesCount = dataset.getRowCount(); 1347 for (int i = 0; i < seriesCount; i++) { 1348 if (isSeriesVisibleInLegend(i)) { 1349 LegendItem item = getLegendItem(index, i); 1350 if (item != null) { 1351 result.add(item); 1352 } 1353 } 1354 } 1355 1356 } 1357 return result; 1358 } 1359 1360 1365 public CategorySeriesLabelGenerator getLegendItemLabelGenerator() { 1366 return this.legendItemLabelGenerator; 1367 } 1368 1369 1374 public void setLegendItemLabelGenerator( 1375 CategorySeriesLabelGenerator generator) { 1376 if (generator == null) { 1377 throw new IllegalArgumentException ("Null 'generator' argument."); 1378 } 1379 this.legendItemLabelGenerator = generator; 1380 } 1381 1382 1387 public CategorySeriesLabelGenerator getLegendItemToolTipGenerator() { 1388 return this.legendItemToolTipGenerator; 1389 } 1390 1391 1396 public void setLegendItemToolTipGenerator( 1397 CategorySeriesLabelGenerator generator) { 1398 this.legendItemToolTipGenerator = generator; 1399 } 1400 1401 1406 public CategorySeriesLabelGenerator getLegendItemURLGenerator() { 1407 return this.legendItemURLGenerator; 1408 } 1409 1410 1415 public void setLegendItemURLGenerator( 1416 CategorySeriesLabelGenerator generator) { 1417 this.legendItemURLGenerator = generator; 1418 } 1419 1420 1430 protected void addItemEntity(EntityCollection entities, 1431 CategoryDataset dataset, int row, int column, 1432 Shape hotspot) { 1433 1434 String tip = null; 1435 CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); 1436 if (tipster != null) { 1437 tip = tipster.generateToolTip(dataset, row, column); 1438 } 1439 String url = null; 1440 CategoryURLGenerator urlster = getItemURLGenerator(row, column); 1441 if (urlster != null) { 1442 url = urlster.generateURL(dataset, row, column); 1443 } 1444 CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, 1445 dataset, row, dataset.getColumnKey(column), column); 1446 entities.add(entity); 1447 1448 } 1449 1450} 1451 | Popular Tags |