source: trunk/src/org/expeditee/items/widgets/charts/AbstractXY.java@ 284

Last change on this file since 284 was 242, checked in by ra33, 16 years ago
File size: 2.7 KB
Line 
1package org.expeditee.items.widgets.charts;
2
3import java.awt.Color;
4import java.util.Collection;
5import java.util.HashSet;
6
7import org.expeditee.gui.AttributeValuePair;
8import org.expeditee.items.Item;
9import org.expeditee.items.Text;
10import org.jfree.data.xy.XYDataset;
11import org.jfree.data.xy.XYSeries;
12import org.jfree.data.xy.XYSeriesCollection;
13
14public abstract class AbstractXY extends AbstractValueAxis {
15
16 private XYSeriesCollection _data;
17
18 protected XYDataset getChartData() {
19 _data = new XYSeriesCollection();
20 return _data;
21 }
22
23 public AbstractXY(Text source, String[] args) {
24 super(source, args);
25 }
26
27 /**
28 * @param dataFrame
29 */
30 @Override
31 protected void clearData() {
32 _data.removeAllSeries();
33 }
34
35 @Override
36 protected boolean addCategoryData(String categoryName,
37 Collection<Text> items, boolean swap) {
38 XYSeries newSeries = new XYSeries(categoryName);
39 Color categoryColor = null;
40 boolean foundData = false;
41 Collection<Item> seen = new HashSet<Item>();
42 for (Text i : items) {
43 if (i.isLineEnd() || seen.contains(i)) {
44 continue;
45 }
46
47 Text t = (Text) i;
48 AttributeValuePair avp = new AttributeValuePair(t.getText());
49 if (avp != null) {
50 Double attribute = null;
51 Double value = null;
52 try {
53 value = avp.getDoubleValue();
54 attribute = avp.getDoubleAttribute();
55 } catch (Exception e) {
56
57 }
58 // If the data is not valid move to the next item
59 if (attribute == null && value != null) {
60 String stringAttribute = avp.getAttribute();
61 if (stringAttribute == null)
62 continue;
63 // Check if there is another item within the same
64 // enclosure
65 Collection<Item> sameEnclosure = t
66 .getItemsInSameEnclosure();
67 seen.addAll(sameEnclosure);
68 for (Item enclosed : sameEnclosure) {
69 if (enclosed instanceof Text && enclosed != t) {
70 AttributeValuePair avp2 = new AttributeValuePair(
71 enclosed.getText());
72 String stringAtt2 = avp2.getAttribute();
73 Double value2 = null;
74 try {
75 value2 = avp2.getDoubleValue();
76 } catch (Exception e) {
77 }
78 if (stringAtt2 != null && value2 != null) {
79 if (String.CASE_INSENSITIVE_ORDER.compare(
80 stringAttribute, stringAtt2) < 0) {
81 attribute = value;
82 value = value2;
83 } else {
84 attribute = value2;
85 }
86 break;
87 }
88 }
89 }
90 }
91
92 if (value == null)
93 continue;
94 if (swap) {
95 newSeries.add(value, attribute);
96 } else {
97 newSeries.add(attribute, value);
98 }
99 foundData = true;
100 if (categoryColor == null) {
101 categoryColor = i.getColor();
102 }
103 }
104 }
105 if (foundData) {
106 _data.addSeries(newSeries);
107 _paints.put(categoryName, categoryColor);
108 }
109 return foundData;
110 }
111}
Note: See TracBrowser for help on using the repository browser.