1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components;
21
22 import java.beans.Customizer;
23
24 import javax.swing.BoxLayout;
25 import javax.swing.ButtonGroup;
26 import javax.swing.ButtonModel;
27 import javax.swing.JComponent;
28 import javax.swing.JPanel;
29 import javax.swing.JRadioButton;
30
31 import com.cosylab.gui.components.range2.RescalingValuePolicy;
32 import com.cosylab.gui.components.range2.ShiftValuePolicy;
33 import com.cosylab.gui.components.range2.TrimValuePolicy;
34
35 public class PiperCustomizer extends AbstractDisplayerPanelCustomizer {
36 private static final long serialVersionUID = 1L;
37 public static final String VALUE_DISPLAY = "Value Display";
38 public static final String VALUE_POLICY = "Value Range Policy";
39 private static final String UNITS = "units";
40 private static final String UNITS_VISIBLE = "unitsVisible";
41 private static final String FORMAT = "format";
42 private static final String GRAPH_MIN = "minimum";
43 private static final String GRAPH_MAX = "maximum";
44 private static final String ENHANCED = "enhanced";
45 private static final String STRETCH = "stretch";
46 private static final String TILTING_ENABLED = "tiltingEnabled";
47 private static final String RESIZABLE = "resizable";
48 public static final String TITLE = "title";
49 public static final String[] VISUAL_BASIC_PROPERTIES = {TITLE, RESIZABLE, ENHANCED, TILTING_ENABLED, STRETCH };
50 public static String[] VALUE_DISPLAY_PROPERTIES = {
51 GRAPH_MIN, GRAPH_MAX, UNITS,UNITS_VISIBLE, FORMAT
52 };
53
54
55 public static String[] ASPECTS = { VISUAL_BASIC, VALUE_DISPLAY, VALUE_POLICY };
56
57
58
59
60 private class WPanel extends JPanel implements Customizer
61 {
62 private static final long serialVersionUID = 1L;
63 private Piper displayer;
64 private JRadioButton trimButton;
65 private JRadioButton rescalingButton;
66 private JRadioButton shiftButton;
67 private ButtonGroup bg;
68
69
70
71
72 public WPanel()
73 {
74 bg = new ButtonGroup();
75
76 trimButton = new JRadioButton("Trim Value Range");
77 rescalingButton = new JRadioButton("Rescale Value Range");
78 shiftButton = new JRadioButton("Shift Value Range");
79
80 bg.add(trimButton);
81 bg.add(rescalingButton);
82 bg.add(shiftButton);
83
84 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
85 add(trimButton);
86 add(rescalingButton);
87 add(shiftButton);
88 }
89
90
91
92
93
94
95
96
97
98
99
100 public JComponent getEditorComponent(Object object, String aspect)
101 throws IllegalArgumentException
102 {
103 if (aspect.equals(VALUE_POLICY)) {
104 displayer = (Piper)object;
105 initialize();
106
107 return this;
108 }
109
110 return null;
111 }
112
113 private void initialize()
114 {
115 if (displayer == null) {
116 return;
117 }
118
119 if (displayer.getValuePolicy() instanceof RescalingValuePolicy) {
120 rescalingButton.setSelected(true);
121 }
122 if (displayer.getValuePolicy() instanceof TrimValuePolicy) {
123 trimButton.setSelected(true);
124 }
125 if (displayer.getValuePolicy() instanceof ShiftValuePolicy) {
126 shiftButton.setSelected(true);
127 }
128 }
129
130
131
132
133
134
135
136
137
138 public boolean canEdit(Object object, String aspect)
139 {
140 return aspect.equals(VALUE_POLICY);
141 }
142
143
144
145
146 public void applySettings()
147 {
148 ButtonModel bm = bg.getSelection();
149
150 if (bm == null) {
151 return;
152 }
153
154 if (bm == shiftButton.getModel()) {
155 displayer.setValuePolicy(new ShiftValuePolicy());
156 } else if (bm == rescalingButton.getModel()) {
157 displayer.setValuePolicy(new RescalingValuePolicy());
158 } else if (bm == trimButton.getModel()) {
159 displayer.setValuePolicy(new TrimValuePolicy());
160 } else {
161 throw new AssertionError();
162 }
163
164 initialize();
165 }
166
167
168
169
170 public void revertSettings()
171 {
172 }
173
174
175
176
177 public void stopEditing()
178 {
179 }
180
181 public void setObject(Object bean) {
182 displayer = (Piper) bean;
183 }
184 }
185
186 public PiperCustomizer() {
187 addCustomizerTable(VISUAL_BASIC, VISUAL_BASIC_PROPERTIES);
188 addCustomizerTable(VALUE_DISPLAY, VALUE_DISPLAY_PROPERTIES);
189 addCustomizer(VALUE_POLICY, new WPanel());
190 setSize(331, 185);
191 }
192 }