source: trunk/src/org/expeditee/items/widgets/charts/AbstractCategory.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: 2.3 KB
Line 
1/**
2 * AbstractCategory.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;
23
24import org.expeditee.gui.AttributeValuePair;
25import org.expeditee.items.Text;
26import org.jfree.data.category.DefaultCategoryDataset;
27
28public abstract class AbstractCategory extends AbstractValueAxis {
29
30 private DefaultCategoryDataset _data;
31
32 protected DefaultCategoryDataset getChartData() {
33 if (_data == null)
34 _data = new DefaultCategoryDataset();
35 return _data;
36 }
37
38 public AbstractCategory(Text source, String[] args) {
39 super(source, args);
40 }
41
42 @Override
43 protected void clearData() {
44 _data.clear();
45 }
46
47 @Override
48 protected boolean addCategoryData(String categoryName,
49 Collection<Text> items, boolean swap) {
50 boolean foundData = false;
51 Color newColor = null;
52 for (Text i : items) {
53 try {
54 if (!i.isLineEnd()) {
55 Text t = (Text) i;
56 AttributeValuePair avp = new AttributeValuePair(t.getText());
57 if (avp != null) {
58 if (swap) {
59 String attribute = avp.getAttribute();
60 _data.setValue(avp.getDoubleValue(), attribute,
61 categoryName);
62 if (_paints.get(attribute) == null) {
63 _paints.put(attribute, i.getBackgroundColor());
64 }
65 } else {
66 _data.setValue(avp.getDoubleValue(), categoryName,
67 avp.getAttribute());
68 }
69 foundData = true;
70 if (newColor == null)
71 newColor = i.getBackgroundColor();
72 }
73 }
74 } catch (Exception e) {
75
76 }
77 }
78 if (foundData && !swap) {
79 _paints.put(categoryName, newColor);
80 }
81 return foundData;
82 }
83}
Note: See TracBrowser for help on using the repository browser.