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

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.5 KB
Line 
1/**
2 * AbstractXY.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items.widgets.charts;
20
21import java.awt.Color;
22import java.util.Collection;
23import java.util.HashSet;
24
25import org.expeditee.gui.AttributeValuePair;
26import org.expeditee.items.Item;
27import org.expeditee.items.Text;
28import org.jfree.data.xy.XYDataset;
29import org.jfree.data.xy.XYSeries;
30import org.jfree.data.xy.XYSeriesCollection;
31
32public abstract class AbstractXY extends AbstractValueAxis {
33
34 private XYSeriesCollection _data;
35
36 protected XYDataset getChartData() {
37 _data = new XYSeriesCollection();
38 return _data;
39 }
40
41 public AbstractXY(Text source, String[] args) {
42 super(source, args);
43 }
44
45 /**
46 * @param dataFrame
47 */
48 @Override
49 protected void clearData() {
50 _data.removeAllSeries();
51 }
52
53 @Override
54 protected boolean addCategoryData(String categoryName,
55 Collection<Text> items, boolean swap) {
56 XYSeries newSeries = new XYSeries(categoryName);
57 Color categoryColor = null;
58 boolean foundData = false;
59 Collection<Item> seen = new HashSet<Item>();
60 for (Text i : items) {
61 if (i.isLineEnd() || seen.contains(i)) {
62 continue;
63 }
64
65 Text t = (Text) i;
66 AttributeValuePair avp = new AttributeValuePair(t.getText());
67 if (avp != null) {
68 Double attribute = null;
69 Double value = null;
70 try {
71 value = avp.getDoubleValue();
72 attribute = avp.getDoubleAttribute();
73 } catch (Exception e) {
74
75 }
76 // If the data is not valid move to the next item
77 if (attribute == null && value != null) {
78 String stringAttribute = avp.getAttribute();
79 if (stringAttribute == null)
80 continue;
81 // Check if there is another item within the same
82 // enclosure
83 Collection<Item> sameEnclosure = t
84 .getItemsInSameEnclosure();
85 seen.addAll(sameEnclosure);
86 for (Item enclosed : sameEnclosure) {
87 if (enclosed instanceof Text && enclosed != t) {
88 AttributeValuePair avp2 = new AttributeValuePair(
89 enclosed.getText());
90 String stringAtt2 = avp2.getAttribute();
91 Double value2 = null;
92 try {
93 value2 = avp2.getDoubleValue();
94 } catch (Exception e) {
95 }
96 if (stringAtt2 != null && value2 != null) {
97 if (String.CASE_INSENSITIVE_ORDER.compare(
98 stringAttribute, stringAtt2) < 0) {
99 attribute = value;
100 value = value2;
101 } else {
102 attribute = value2;
103 }
104 break;
105 }
106 }
107 }
108 }
109
110 if (value == null)
111 continue;
112 if (swap) {
113 newSeries.add(value, attribute);
114 } else {
115 newSeries.add(attribute, value);
116 }
117 foundData = true;
118 if (categoryColor == null) {
119 categoryColor = i.getColor();
120 }
121 }
122 }
123 if (foundData) {
124 _data.addSeries(newSeries);
125 _paints.put(categoryName, categoryColor);
126 }
127 return foundData;
128 }
129}
Note: See TracBrowser for help on using the repository browser.