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

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

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