1 | public class StandardCategorySeriesLabelGenerator implements ↵ | | 1 | public class StandardXYSeriesLabelGenerator implements ↵
|
2 | CategorySeriesLabelGenerator, ↵ | | 2 | XYSeriesLabelGenerator, ↵
|
3 | Cloneable, PublicCloneable, Serializable {↵ | | 3 | Cloneable, PublicCloneable, Serializable {↵
|
|
4 | /** For serialization. */↵ | | 4 | /** For serialization. */↵
|
5 | private static final long serialVersionUID = 4630760091523940820L;↵ | | 5 | private static final long serialVersionUID = 1916017081848400024L;↵
|
6 | ↵ | | 6 | ↵
|
7 | /** The default item label format. */↵ | | 7 | /** The default item label format. */↵
|
8 | public static final String DEFAULT_LABEL_FORMAT = "{0}";↵ | | 8 | public static final String DEFAULT_LABEL_FORMAT = "{0}";↵
|
9 | ↵ | | 9 | ↵
|
10 | /** The format pattern. */↵ | | 10 | /** The format pattern. */↵
|
11 | private String formatPattern;↵ | | 11 | private String formatPattern;↵
|
|
12 | /**↵ | | 12 | /**↵
|
13 | * Creates a default series label generator (uses ↵ | | 13 | * Creates a default series label generator (uses ↵
|
14 | * {@link #DEFAULT_LABEL_FORMAT}).↵ | | 14 | * {@link #DEFAULT_LABEL_FORMAT}).↵
|
15 | */↵ | | 15 | */↵
|
16 | public StandardCategorySeriesLabelGenerator() {↵ | | 16 | public StandardXYSeriesLabelGenerator() {↵
|
17 | this(DEFAULT_LABEL_FORMAT);↵ | | 17 | this(DEFAULT_LABEL_FORMAT);↵
|
18 | }↵ | | 18 | }↵
|
19 | ↵ | | 19 | ↵
|
20 | /**↵ | | 20 | /**↵
|
21 | * Creates a new series label generator.↵ | | 21 | * Creates a new series label generator.↵
|
22 | * ↵ | | 22 | * ↵
|
23 | * @param format the format pattern (<code>null</code> not permitted).↵ | | 23 | * @param format the format pattern (<code>null</code> not permitted).↵
|
24 | */↵ | | 24 | */↵
|
25 | public StandardCategorySeriesLabelGenerator(String format) {↵ | | 25 | public StandardXYSeriesLabelGenerator(String format) {↵
|
26 | if (format == null) {↵ | | 26 | if (format == null) {↵
|
27 | throw new IllegalArgumentException("Null 'format' argument.");↵ | | 27 | throw new IllegalArgumentException("Null 'format' argument.");↵
|
28 | }↵ | | 28 | }↵
|
29 | this.formatPattern = format;↵ | | 29 | this.formatPattern = format;↵
|
30 | }↵ | | 30 | }↵
|
|
31 | /**↵ | | 31 | /**↵
|
32 | * Generates a label for the specified series.↵ | | 32 | * Generates a label for the specified series. This label will be↵
|
| | | 33 | * used for the chart legend.↵
|
33 | * ↵ | | 34 | * ↵
|
34 | * @param dataset the dataset (<code>null</code> not permitted).↵ | | 35 | * @param dataset the dataset (<code>null</code> not permitted).↵
|
35 | * @param series the series.↵ | | 36 | * @param series the series.↵
|
36 | * ↵ | | 37 | * ↵
|
37 | * @return A series label.↵ | | 38 | * @return A series label.↵
|
38 | */↵ | | 39 | */↵
|
39 | public String generateLabel(CategoryDataset dataset, int series) {↵ | | 40 | public String generateLabel(XYDataset dataset, int series) {↵
|
40 | if (dataset == null) {↵ | | 41 | if (dataset == null) {↵
|
41 | throw new IllegalArgumentException("Null 'dataset' argument.");↵ | | 42 | throw new IllegalArgumentException("Null 'dataset' argument.");↵
|
42 | }↵ | | 43 | }↵
|
43 | String label = MessageFormat.format(↵ | | 44 | String label = MessageFormat.format(↵
|
44 | this.formatPattern, ↵ | | 45 | this.formatPattern, ↵
|
45 | createItemArray(dataset, series)↵ | | 46 | createItemArray(dataset, series)↵
|
46 | );↵ | | 47 | );↵
|
47 | return label;↵ | | 48 | return label;↵
|
48 | }↵ | | 49 | }↵
|
|
49 | /**↵ | | 50 | /**↵
|
50 | * Creates the array of items that can be passed to the ↵ | | 51 | * Creates the array of items that can be passed to the ↵
|
51 | * {@link MessageFormat} class for creating labels.↵ | | 52 | * {@link MessageFormat} class for creating labels.↵
|
52 | *↵ | | 53 | *↵
|
53 | * @param dataset the dataset (<code>null</code> not permitted).↵ | | 54 | * @param dataset the dataset (<code>null</code> not permitted).↵
|
54 | * @param series the series (zero-based index).↵ | | 55 | * @param series the series (zero-based index).↵
|
55 | *↵ | | 56 | *↵
|
56 | * @return The items (never <code>null</code>).↵ | | 57 | * @return The items (never <code>null</code>).↵
|
57 | */↵ | | 58 | */↵
|
58 | protected Object[] createItemArray(CategoryDataset dataset, int series) {↵ | | 59 | protected Object[] createItemArray(XYDataset dataset, int series) {↵
|
59 | Object[] result = new Object[1];↵ | | 60 | Object[] result = new Object[1];↵
|
60 | result[0] = dataset.getRowKey(series).toString();↵ | | 61 | result[0] = dataset.getSeriesKey(series).toString();↵
|
61 | return result;↵ | | 62 | return result;↵
|
62 | }↵ | | 63 | }↵
|
|
63 | /**↵ | | 64 | /**↵
|
64 | * Returns an independent copy of the generator.↵ | | 65 | * Returns an independent copy of the generator. This is unnecessary, ↵
|
| | | 66 | * because instances are immutable anyway, but we retain this ↵
|
| | | 67 | * behaviour for backwards compatibility.↵
|
65 | * ↵ | | 68 | * ↵
|
66 | * @return A clone.↵ | | 69 | * @return A clone.↵
|
67 | * ↵ | | 70 | * ↵
|
68 | * @throws CloneNotSupportedException if cloning is not supported.↵ | | 71 | * @throws CloneNotSupportedException if cloning is not supported.↵
|
69 | */↵ | | 72 | */↵
|
70 | public Object clone() throws CloneNotSupportedException { ↵ | | 73 | public Object clone() throws CloneNotSupportedException { ↵
|
71 | return super.clone();↵ | | 74 | return super.clone();↵
|
72 | }↵ | | 75 | }↵
|
73 | ↵ | | 76 | ↵
|
74 | /**↵ | | 77 | /**↵
|
75 | * Tests this object for equality with an arbitrary object.↵ | | 78 | * Tests this object for equality with an arbitrary object.↵
|
76 | *↵ | | 79 | *↵
|
77 | * @param obj the other object (<code>null</code> permitted).↵ | | 80 | * @param obj the other object (<code>null</code> permitted).↵
|
78 | *↵ | | 81 | *↵
|
79 | * @return A boolean.↵ | | 82 | * @return A boolean.↵
|
80 | */↵ | | 83 | */↵
|
81 | public boolean equals(Object obj) {↵ | | 84 | public boolean equals(Object obj) {↵
|
82 | if (obj == this) {↵ | | 85 | if (obj == this) {↵
|
83 | return true;↵ | | 86 | return true;↵
|
84 | }↵ | | 87 | }↵
|
85 | if (!(obj instanceof StandardCategorySeriesLabelGenerator)) {↵ | | 88 | if (!(obj instanceof StandardXYSeriesLabelGenerator)) {↵
|
86 | return false;↵ | | 89 | return false;↵
|
87 | }↵ | | 90 | }↵
|
88 | StandardCategorySeriesLabelGenerator that ↵ | | 91 | StandardXYSeriesLabelGenerator that ↵
|
89 | = (StandardCategorySeriesLabelGenerator) obj;↵ | | 92 | = (StandardXYSeriesLabelGenerator) obj;↵
|
90 | if (!this.formatPattern.equals(that.formatPattern)) {↵ | | 93 | if (!this.formatPattern.equals(that.formatPattern)) {↵
|
91 | return false;↵ | | 94 | return false;↵
|
92 | }↵ | | 95 | }↵
|
93 | return true;↵ | | 96 | return true;↵
|
94 | }↵ | | 97 | }↵
|
95 | ↵ | | 98 | ↵
|
96 | /**↵ | | 99 | /**↵
|
97 | * Returns a hash code for this instance.↵ | | 100 | * Returns a hash code for this instance.↵
|
98 | * ↵ | | 101 | * ↵
|
99 | * @return A hash code.↵ | | 102 | * @return A hash code.↵
|
100 | */↵ | | 103 | */↵
|
101 | public int hashCode() {↵ | | 104 | public int hashCode() {↵
|
102 | int result = 127;↵ | | 105 | int result = 127;↵
|
103 | result = HashUtilities.hashCode(result, this.formatPattern);↵ | | 106 | result = HashUtilities.hashCode(result, this.formatPattern);↵
|
104 | return result | | 107 | return result
|