1 | /**
|
---|
2 | * AbstractValueAxis.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 |
|
---|
19 | package org.expeditee.items.widgets.charts;
|
---|
20 |
|
---|
21 | import java.awt.BasicStroke;
|
---|
22 | import java.awt.Stroke;
|
---|
23 |
|
---|
24 | import org.expeditee.core.Colour;
|
---|
25 | import org.expeditee.gio.swing.SwingConversions;
|
---|
26 | import org.expeditee.gui.Frame;
|
---|
27 | import org.expeditee.items.Text;
|
---|
28 | import org.jfree.chart.axis.Axis;
|
---|
29 | import org.jfree.chart.plot.Plot;
|
---|
30 | import org.jfree.chart.plot.PlotOrientation;
|
---|
31 | import org.jfree.chart.plot.ValueAxisPlot2;
|
---|
32 |
|
---|
33 | public abstract class AbstractValueAxis extends AbstractChart {
|
---|
34 |
|
---|
35 | public AbstractValueAxis(Text source, String[] args) {
|
---|
36 | super(source, args);
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * @param dataFrame
|
---|
41 | */
|
---|
42 | protected void refreshPlot(Frame dataFrame, Plot simplePlot) {
|
---|
43 | ValueAxisPlot2 plot = (ValueAxisPlot2) simplePlot;
|
---|
44 | if (dataFrame.hasAnnotation("xaxis")) {
|
---|
45 | plot.getDomainAxis()
|
---|
46 | .setLabel(dataFrame.getAnnotationValue("xaxis"));
|
---|
47 | }
|
---|
48 | if (dataFrame.hasAnnotation("yaxis")) {
|
---|
49 | plot.getRangeAxis().setLabel(dataFrame.getAnnotationValue("yaxis"));
|
---|
50 | }
|
---|
51 | if (dataFrame.hasAnnotation("horizontal")) {
|
---|
52 | plot.setOrientation(PlotOrientation.HORIZONTAL);
|
---|
53 | } else {
|
---|
54 | plot.setOrientation(PlotOrientation.VERTICAL);
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public void setSourceColor(Colour c) {
|
---|
60 | super.setSourceColor(c);
|
---|
61 | if (getChart() == null)
|
---|
62 | return;
|
---|
63 |
|
---|
64 | ValueAxisPlot2 plot = ((ValueAxisPlot2) getChart().getPlot());
|
---|
65 | if (c == null) {
|
---|
66 | plot.getDomainAxis().setLabelPaint(Axis.DEFAULT_AXIS_LABEL_PAINT);
|
---|
67 | plot.getRangeAxis().setLabelPaint(Axis.DEFAULT_AXIS_LABEL_PAINT);
|
---|
68 | plot.getDomainAxis().setTickLabelPaint(
|
---|
69 | Axis.DEFAULT_TICK_LABEL_PAINT);
|
---|
70 | plot.getRangeAxis()
|
---|
71 | .setTickLabelPaint(Axis.DEFAULT_TICK_LABEL_PAINT);
|
---|
72 | } else {
|
---|
73 | plot.getDomainAxis().setLabelPaint(SwingConversions.toSwingColor(c));
|
---|
74 | plot.getRangeAxis().setLabelPaint(SwingConversions.toSwingColor(c));
|
---|
75 | plot.getDomainAxis().setTickLabelPaint(SwingConversions.toSwingColor(c));
|
---|
76 | plot.getRangeAxis().setTickLabelPaint(SwingConversions.toSwingColor(c));
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Override
|
---|
81 | public void setSourceBorderColor(Colour c) {
|
---|
82 | super.setSourceBorderColor(c);
|
---|
83 | if (getChart() == null)
|
---|
84 | return;
|
---|
85 | ValueAxisPlot2 plot = ((ValueAxisPlot2) getChart().getPlot());
|
---|
86 | if (c == null) {
|
---|
87 | plot.setDomainGridlinePaint(Plot.DEFAULT_OUTLINE_PAINT);
|
---|
88 | plot.setRangeGridlinePaint(Plot.DEFAULT_OUTLINE_PAINT);
|
---|
89 | plot.getDomainAxis().setTickMarkPaint(Plot.DEFAULT_OUTLINE_PAINT);
|
---|
90 | plot.getRangeAxis().setTickMarkPaint(Plot.DEFAULT_OUTLINE_PAINT);
|
---|
91 | } else {
|
---|
92 | Colour brighter = c.brighter();
|
---|
93 | plot.setDomainGridlinePaint(SwingConversions.toSwingColor(brighter));
|
---|
94 | plot.setRangeGridlinePaint(SwingConversions.toSwingColor(brighter));
|
---|
95 | plot.getDomainAxis().setTickMarkPaint(SwingConversions.toSwingColor(c));
|
---|
96 | plot.getRangeAxis().setTickMarkPaint(SwingConversions.toSwingColor(c));
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public void setSourceThickness(float newThickness, boolean setConnected) {
|
---|
102 | super.setSourceThickness(newThickness, setConnected);
|
---|
103 | if (getChart() == null)
|
---|
104 | return;
|
---|
105 | ValueAxisPlot2 plot = ((ValueAxisPlot2) getChart().getPlot());
|
---|
106 | Stroke solid = new BasicStroke(newThickness);
|
---|
107 | Stroke gridline = new BasicStroke(newThickness / 2,
|
---|
108 | BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f,
|
---|
109 | new float[] { 2 * newThickness, 2 * newThickness }, 0.0f);
|
---|
110 |
|
---|
111 | updateAxis(plot.getDomainAxis(), solid, newThickness);
|
---|
112 | updateAxis(plot.getRangeAxis(), solid, newThickness);
|
---|
113 |
|
---|
114 | plot.setDomainGridlineStroke(gridline);
|
---|
115 | plot.setRangeGridlineStroke(gridline);
|
---|
116 | plot.getRenderer().setBaseStroke(solid);
|
---|
117 |
|
---|
118 | }
|
---|
119 |
|
---|
120 | private void updateAxis(Axis axis, Stroke solid, float thickness) {
|
---|
121 | axis.setAxisLineStroke(solid);
|
---|
122 | axis.setTickMarkStroke(solid);
|
---|
123 | axis.setLabelFont(axis.getLabelFont().deriveFont(getFontSize(thickness, Axis.DEFAULT_AXIS_LABEL_FONT.getSize2D())));
|
---|
124 | axis.setTickLabelFont(axis.getTickLabelFont().deriveFont(getFontSize(thickness, Axis.DEFAULT_TICK_LABEL_FONT.getSize2D())));
|
---|
125 | }
|
---|
126 | }
|
---|