source: trunk/src/org/expeditee/items/widgets/charts/AbstractCategory.java@ 376

Last change on this file since 376 was 376, checked in by ra33, 16 years ago
File size: 1.5 KB
Line 
1package org.expeditee.items.widgets.charts;
2
3import java.awt.Color;
4import java.util.Collection;
5
6import org.expeditee.gui.AttributeValuePair;
7import org.expeditee.items.Text;
8import org.jfree.data.category.DefaultCategoryDataset;
9
10public abstract class AbstractCategory extends AbstractValueAxis {
11
12 private DefaultCategoryDataset _data;
13
14 protected DefaultCategoryDataset getChartData() {
15 if (_data == null)
16 _data = new DefaultCategoryDataset();
17 return _data;
18 }
19
20 public AbstractCategory(Text source, String[] args) {
21 super(source, args);
22 }
23
24 @Override
25 protected void clearData() {
26 _data.clear();
27 }
28
29 @Override
30 protected boolean addCategoryData(String categoryName,
31 Collection<Text> items, boolean swap) {
32 boolean foundData = false;
33 Color newColor = null;
34 for (Text i : items) {
35 try {
36 if (!i.isLineEnd()) {
37 Text t = (Text) i;
38 AttributeValuePair avp = new AttributeValuePair(t.getText());
39 if (avp != null) {
40 if (swap) {
41 String attribute = avp.getAttribute();
42 _data.setValue(avp.getDoubleValue(), attribute,
43 categoryName);
44 if (_paints.get(attribute) == null) {
45 _paints.put(attribute, i.getBackgroundColor());
46 }
47 } else {
48 _data.setValue(avp.getDoubleValue(), categoryName,
49 avp.getAttribute());
50 }
51 foundData = true;
52 if (newColor == null)
53 newColor = i.getBackgroundColor();
54 }
55 }
56 } catch (Exception e) {
57
58 }
59 }
60 if (foundData && !swap) {
61 _paints.put(categoryName, newColor);
62 }
63 return foundData;
64 }
65}
Note: See TracBrowser for help on using the repository browser.