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