source: trunk/src/org/expeditee/items/widgets/charts/AbstractPie.java@ 294

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