1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.desy.acop.displayers.chart;
24
25 import java.awt.Dimension;
26 import java.awt.GridBagConstraints;
27 import java.awt.GridBagLayout;
28 import java.awt.Insets;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.beans.Customizer;
32 import java.beans.PropertyChangeEvent;
33 import java.beans.PropertyChangeListener;
34
35 import javax.swing.BorderFactory;
36 import javax.swing.JButton;
37 import javax.swing.JCheckBox;
38 import javax.swing.JPanel;
39 import javax.swing.border.TitledBorder;
40
41 import de.desy.acop.chart.AcopDisplayMode;
42 import de.desy.acop.chart.AcopGraphStyleEnum;
43 import de.desy.acop.displayers.AcopChartReorg;
44 import de.desy.acop.displayers.AcopTrendChart;
45 import de.desy.acop.displayers.tools.RecentTimespanSelector;
46
47
48
49
50
51
52
53
54 public class AcopTrendChartSettingsCustomizer extends JPanel implements Customizer {
55
56 private static final long serialVersionUID = 1L;
57
58 protected AcopTrendChart acopChartReorg;
59
60 private JButton autoscaleXButton;
61 private JButton autoscaleYButton;
62 protected JPanel stylePanel;
63 private JCheckBox axisTraceBox;
64 private ScalePanel scalePanel;
65 private ChartOptionsPanel chartOptionsPanel;
66 private JCheckBox allDataBox;
67 private RecentTimespanSelector selector;
68 private JPanel timespanPanel;
69
70
71
72
73
74 public AcopTrendChartSettingsCustomizer() {
75 initialize();
76 }
77
78 protected void initialize() {
79 setLayout(new GridBagLayout());
80
81 add(getScalePanel(),new GridBagConstraints(0,0,1,1,0,1,GridBagConstraints.NORTHWEST,GridBagConstraints.VERTICAL,new Insets(1,1,1,1),0,0));
82 add(getTimespanPanel(),new GridBagConstraints(1,0,1,1,1,1,GridBagConstraints.NORTHWEST,GridBagConstraints.VERTICAL,new Insets(1,1,1,1),0,0));
83 add(getStylePanel(),new GridBagConstraints(0,1,2,1,0,1,GridBagConstraints.NORTHWEST,GridBagConstraints.VERTICAL,new Insets(1,1,1,1),0,0));
84
85 }
86
87 protected JPanel getTimespanPanel() {
88 if (timespanPanel == null) {
89 timespanPanel = new JPanel(new GridBagLayout());
90 timespanPanel.add(getAllDataBox(), new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(1,1,1,1),0,0));
91 timespanPanel.add(getSelector(), new GridBagConstraints(0,1,1,1,1,1,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(1,1,1,1),0,0));
92 timespanPanel.setBorder(BorderFactory.createTitledBorder("Timespan"));
93 }
94 return timespanPanel;
95 }
96
97 protected RecentTimespanSelector getSelector() {
98 if (selector == null) {
99 selector = new RecentTimespanSelector();
100 selector.addPropertyChangeListener(RecentTimespanSelector.TIME_SPAN, new PropertyChangeListener() {
101 public void propertyChange(PropertyChangeEvent evt) {
102 if (acopChartReorg == null) return;
103 acopChartReorg.setTimeSpan((Double) evt.getNewValue());
104 }});
105 }
106 return selector;
107 }
108
109 protected ScalePanel getScalePanel() {
110 if (scalePanel == null) {
111 scalePanel = new ScalePanel();
112 scalePanel.setDefaultMax(150);
113 scalePanel.setDefaultMin(0);
114 scalePanel.setMax(150);
115 scalePanel.setMin(0);
116 scalePanel.setRelativeScaleMode(true);
117 AcopGraphStyleEnum[] styles = new AcopGraphStyleEnum[]{AcopGraphStyleEnum.TimeLin, AcopGraphStyleEnum.TimeLog};
118 scalePanel.setAvailableStyles(styles);
119 scalePanel.setStyleComboRenderer(new StyleComboRenderer());
120 scalePanel.addPropertyChangeListener(new PropertyChangeListener(){
121 public void propertyChange(PropertyChangeEvent evt) {
122 if (acopChartReorg == null) return;
123 String propertyName = evt.getPropertyName();
124 if ("autoScale".equals(propertyName)) {
125 scalePanel.setMinMaxEnabled(!scalePanel.isAutoScale());
126 acopChartReorg.setYAutoScale(scalePanel.isAutoScale());
127 } else if ("max".equals(propertyName)) {
128 acopChartReorg.setYRangeMax(scalePanel.getMax());
129 } else if ("min".equals(propertyName)) {
130 acopChartReorg.setYRangeMin(scalePanel.getMin());
131 } else if ("style".equals(propertyName)) {
132 acopChartReorg.setYLogScale(scalePanel.getStyle() == AcopGraphStyleEnum.TimeLog);
133 }
134 }
135 });
136 scalePanel.setBorder(BorderFactory.createTitledBorder("Scale"));
137 }
138
139 return scalePanel;
140 }
141
142 protected ChartOptionsPanel getChartOptionsPanel() {
143 if (chartOptionsPanel == null) {
144 chartOptionsPanel = new ChartOptionsPanel();
145 chartOptionsPanel.setBorder(null);
146 chartOptionsPanel.addPropertyChangeListener(new PropertyChangeListener(){
147 public void propertyChange(PropertyChangeEvent evt) {
148 if (acopChartReorg == null) return;
149 String propertyName = evt.getPropertyName();
150 if ("useBestScale".equals(propertyName)) {
151 acopChartReorg.setBestScale(chartOptionsPanel.isUseBestScale());
152 } else if ("showGrid".equals(propertyName)) {
153 acopChartReorg.setShowGrid(chartOptionsPanel.isShowGrid());
154 } else if ("lineDisplayMode".equals(propertyName)) {
155 if (chartOptionsPanel.getLineDisplayMode() != null) {
156 acopChartReorg.setDisplayMode(chartOptionsPanel.getLineDisplayMode());
157 }
158 } else if ("chubbyLines".equals(propertyName)) {
159 acopChartReorg.setChubbyLines(chartOptionsPanel.isChubbyLines());
160 }
161 }
162 });
163 chartOptionsPanel.setShowGrid(true);
164 chartOptionsPanel.setUseBestScale(true);
165
166 }
167 return chartOptionsPanel;
168 }
169
170 protected JButton getAutoscaleXButton() {
171 if (autoscaleXButton == null) {
172 autoscaleXButton = new JButton("Autoscale Horizontal");
173 autoscaleXButton.setToolTipText("Autoscale Horizontal Axis");
174 autoscaleXButton.setPreferredSize(new Dimension(180, 25));
175 autoscaleXButton.addActionListener(new ActionListener() {
176 public void actionPerformed(ActionEvent e) {
177 if (acopChartReorg != null) {
178 acopChartReorg.autoScaleXOnce();
179 }
180 }});
181 }
182
183 return autoscaleXButton;
184 }
185
186 protected JButton getAutoscaleYButton() {
187 if (autoscaleYButton == null) {
188 autoscaleYButton = new JButton("Autoscale Vertical");
189 autoscaleYButton.setToolTipText("Autoscale Vertical Axis");
190 autoscaleYButton.setPreferredSize(new Dimension(180, 25));
191 autoscaleYButton.addActionListener(new ActionListener() {
192 public void actionPerformed(ActionEvent e) {
193 if (acopChartReorg != null) {
194 acopChartReorg.autoScaleYOnce();
195 }
196 }});
197 }
198
199 return autoscaleYButton;
200 }
201
202 protected JPanel getStylePanel() {
203 if (stylePanel == null) {
204 stylePanel = new JPanel();
205 stylePanel.setBorder(new TitledBorder("Style"));
206 stylePanel.setLayout(new GridBagLayout());
207 stylePanel.add(getAxisTraceBox(),new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(0,4,0,4),0,0));
208 stylePanel.add(getChartOptionsPanel(), new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0,0,0,0),0,0));
209 }
210
211 return stylePanel;
212 }
213
214 protected JCheckBox getAxisTraceBox() {
215 if (axisTraceBox == null) {
216 axisTraceBox = new JCheckBox("Axis Trace Visible");
217 axisTraceBox.setToolTipText("Toggles Axis Trace On / Off");
218 axisTraceBox.addActionListener(new ActionListener() {
219 public void actionPerformed(ActionEvent e) {
220 if (acopChartReorg != null) {
221 acopChartReorg.setAxisTraceVisible(axisTraceBox.isSelected());
222 }
223 }});
224 }
225
226 return axisTraceBox;
227 }
228
229
230
231
232 public void setObject(Object bean) {
233 acopChartReorg = (AcopTrendChart) bean;
234 addListener();
235 getAllDataBox().setSelected(acopChartReorg.isAutoScaleToLiveData());
236 selector.setEnabled(false);
237 }
238
239 protected void addListener() {
240 if (acopChartReorg == null) return;
241 acopChartReorg.addPropertyChangeListener(new PropertyChangeListener() {
242
243 public void propertyChange(PropertyChangeEvent evt) {
244 String propertyName = evt.getPropertyName();
245 if (propertyName.equals(AcopChartReorg.LINE_STYLE)) {
246 Object style = evt.getNewValue();
247 if (style == null) getChartOptionsPanel().setLineDisplayMode(AcopDisplayMode.PolyLine);
248 else getChartOptionsPanel().setLineDisplayMode((AcopDisplayMode) style);
249 } else if (propertyName.equals(AcopChartReorg.CHUBBY_LINES)) {
250 getChartOptionsPanel().setChubbyLines((Boolean) evt.getNewValue());
251 } else if (propertyName.equals(AcopChartReorg.AXIS_TRACE_VISIBLE)) {
252 getAxisTraceBox().setSelected((Boolean) evt.getNewValue());
253 } else if (propertyName.equals(AcopChartReorg.Y_AUTOSCALE)) {
254 getScalePanel().setAutoScale((Boolean) evt.getNewValue());
255 } else if (propertyName.equals(AcopChartReorg.Y_LOG_SCALE)) {
256 getScalePanel().setStyle((Boolean) evt.getNewValue() ? AcopGraphStyleEnum.TimeLog : AcopGraphStyleEnum.TimeLin);
257 } else if (propertyName.equals(AcopChartReorg.Y_RANGE_MAX)) {
258 getScalePanel().setMax((Double) evt.getNewValue(), false);
259 } else if (propertyName.equals(AcopChartReorg.Y_RANGE_MIN)) {
260 getScalePanel().setMin((Double) evt.getNewValue(), false);
261 } else if (propertyName.equals("printText")) {
262 getChartOptionsPanel().setTextSelected((Boolean)evt.getNewValue());
263 } else if (propertyName.equals("bestScale")) {
264 getChartOptionsPanel().setUseBestScale((Boolean)evt.getNewValue());
265 } else if (propertyName.equals("showGrid")) {
266 getChartOptionsPanel().setShowGrid((Boolean)evt.getNewValue());
267 } else if (propertyName.equals(AcopChartReorg.X_RANGE_MIN) || propertyName.equals(AcopChartReorg.X_RANGE_MAX)) {
268 selector.setTimeSpan(acopChartReorg.getXRangeMax()-acopChartReorg.getXRangeMin());
269 }
270
271 }});
272 }
273
274 private JCheckBox getAllDataBox() {
275 if (allDataBox == null) {
276 allDataBox = new JCheckBox("Autoscale to Live Data");
277 allDataBox.setToolTipText("Adjusts displayed time span to include new live data");
278 allDataBox.addActionListener(new ActionListener() {
279 public void actionPerformed(ActionEvent e) {
280 if (acopChartReorg != null) {
281 acopChartReorg.setAutoScaleToLiveData(allDataBox.isSelected());
282 }
283 selector.setEnabled(!allDataBox.isSelected());
284 }});
285 }
286
287 return allDataBox;
288 }
289
290 }