source: trunk/src/org/expeditee/items/widgets/charts/AbstractPie.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: 4.4 KB
Line 
1/**
2 * AbstractPie.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.BasicStroke;
22import java.awt.Color;
23
24import org.expeditee.gui.AttributeValuePair;
25import org.expeditee.gui.Frame;
26import org.expeditee.items.Text;
27import org.jfree.chart.labels.PieSectionLabelGenerator;
28import org.jfree.chart.plot.PiePlot;
29import org.jfree.chart.plot.Plot;
30import org.jfree.data.general.DefaultPieDataset;
31import org.jfree.ui.RectangleInsets;
32
33public abstract class AbstractPie extends AbstractChart {
34
35 protected DefaultPieDataset _data;
36
37 private PieSectionLabelGenerator _labelGenerator;
38
39 protected DefaultPieDataset getChartData() {
40 if (_data == null)
41 _data = new DefaultPieDataset();
42 return _data;
43 }
44
45 public AbstractPie(Text source, String[] args) {
46 super(source, args);
47 }
48
49 @Override
50 protected void init() {
51 super.init();
52 _labelGenerator = ((PiePlot) getChart().getPlot()).getLabelGenerator();
53 }
54
55 /**
56 * @param dataFrame
57 */
58 @Override
59 protected void refreshPlot(Frame dataFrame, Plot plot) {
60 if (dataFrame.hasAnnotation("labels")) {
61 ((PiePlot) plot).setLabelGenerator(_labelGenerator);
62 } else {
63 ((PiePlot) plot).setLabelGenerator(null);
64 }
65 }
66
67 @Override
68 protected void clearData() {
69 _data.clear();
70 }
71
72 /**
73 * @param dataFrame
74 */
75 @Override
76 protected void refreshData(Frame dataFrame) {
77 for (Text t : dataFrame.getBodyTextItems(false)) {
78 // Ignore line ends for pie charts
79 //TODO find out HOW text became null when i was doing a graph!!
80 String text = t.getText();
81 if (t.isLineEnd() || text == null)
82 continue;
83 AttributeValuePair avp = new AttributeValuePair(text);
84 if (avp != null && avp.hasPair()) {
85 try {
86 _data.setValue(avp.getAttribute(), avp.getDoubleValue());
87 _paints.put(avp.getAttribute(), t.getBackgroundColor());
88 } catch (NumberFormatException nfe) {
89
90 }
91 }
92 }
93 }
94
95 @Override
96 public void setSourceBorderColor(Color c) {
97 super.setSourceBorderColor(c);
98 if (getChart() == null)
99 return;
100 PiePlot plot = ((PiePlot) getChart().getPlot());
101 if (c == null) {
102 plot.setBaseSectionOutlinePaint(Plot.DEFAULT_OUTLINE_PAINT);
103 plot.setLabelLinkPaint(PiePlot.DEFAULT_LABEL_OUTLINE_PAINT);
104 plot.setLabelOutlinePaint(PiePlot.DEFAULT_LABEL_OUTLINE_PAINT);
105 plot.setLabelShadowPaint(PiePlot.DEFAULT_LABEL_SHADOW_PAINT);
106 plot.setShadowPaint(PiePlot.DEFAULT_SHADOW_PAINT);
107 } else {
108 plot.setBaseSectionOutlinePaint(c);
109 plot.setLabelLinkPaint(c);
110 plot.setLabelOutlinePaint(c);
111 Color newC = c.darker();
112 Color faded = new Color(newC.getRed(), newC.getGreen(), newC
113 .getBlue(), 128);
114
115 plot.setLabelShadowPaint(faded);
116 plot.setShadowPaint(c);
117 }
118 }
119
120 @Override
121 public void setSourceColor(Color c) {
122 super.setSourceColor(c);
123 if (getChart() == null)
124 return;
125 PiePlot plot = ((PiePlot) getChart().getPlot());
126 if (c == null) {
127 plot.setLabelPaint(PiePlot.DEFAULT_LABEL_PAINT);
128 } else {
129 plot.setLabelPaint(c);
130 }
131 }
132
133 @Override
134 public void setSourceThickness(float newThickness, boolean setConnected) {
135 super.setSourceThickness(newThickness, setConnected);
136 if (getChart() == null)
137 return;
138 PiePlot plot = ((PiePlot) getChart().getPlot());
139 plot.setBaseSectionOutlineStroke(new BasicStroke(newThickness));
140
141 plot.setLabelLinkStroke(new BasicStroke(newThickness));
142 plot.setLabelOutlineStroke(new BasicStroke(newThickness));
143
144 plot.setLabelFont(plot.getLabelFont().deriveFont(
145 getFontSize(newThickness, PiePlot.DEFAULT_LABEL_FONT
146 .getSize2D())));
147 plot.setLabelPadding(new RectangleInsets(newThickness + 1,
148 newThickness + 1, newThickness + 1, newThickness + 1));
149 plot.setLegendItemShape(Plot.getCircle((newThickness + 1) * 2));
150 }
151}
Note: See TracBrowser for help on using the repository browser.