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;
24
25 import java.beans.PropertyVetoException;
26 import java.util.Map;
27
28 import javax.swing.Action;
29
30 import com.cosylab.gui.InfoDialog;
31 import com.cosylab.gui.WheelswitchDisplayer;
32 import com.cosylab.gui.displayers.DataConsumer;
33 import com.cosylab.gui.displayers.DataState;
34 import com.cosylab.gui.displayers.DisplayerUtilities;
35 import com.cosylab.gui.displayers.DoubleConsumer;
36 import com.cosylab.gui.displayers.DoubleConsumerMulticaster;
37 import com.cosylab.gui.displayers.DoubleSeqConsumer;
38 import com.cosylab.gui.util.UserSettingsProtection;
39 import com.cosylab.util.CommonException;
40
41 import de.desy.acop.displayers.tools.AcopDisplayer;
42 import de.desy.acop.displayers.tools.AcopDisplayerTransferHandler;
43 import de.desy.acop.displayers.tools.AcopInfoDialog;
44 import de.desy.acop.transport.ConnectionParameters;
45 import de.desy.acop.transport.adapters.AcopTransportDataSource;
46 import de.desy.acop.transport.adapters.AdapterFactory;
47 import de.desy.acop.transport.adapters.AdapterFactoryService;
48 import de.desy.tine.definitions.TArrayType;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public class AcopWheelswitch extends WheelswitchDisplayer implements
73 AcopDisplayer {
74
75 private static final long serialVersionUID = -3337991208984786063L;
76 private ConnectionParameters connectionParameters;
77 private int arrayIndex=0;
78 private AcopInfoDialog dialog;
79
80
81
82
83
84 public AcopWheelswitch() {
85 super();
86 setTiltingEnabled(true);
87 new AcopDisplayerTransferHandler(this);
88 UserSettingsProtection.setProtection(this,DisplayerUtilities.COMMON_NUMERIC_DISPLAYER_PROPERTIES,false);
89 }
90
91
92
93
94
95 public void updateValue(long timestamp, double[] value) throws CommonException {
96 updateValue(timestamp, DisplayerUtilities.extract(arrayIndex,value));
97 }
98
99
100
101
102 @Override
103 public DataConsumer getDataConsumer(Class type)
104 {
105 if (type == DoubleConsumer.class || type == DoubleSeqConsumer.class) {
106 return this;
107 }
108
109 return DoubleConsumerMulticaster.createDataConsumer(type, this);
110 }
111
112
113
114
115
116 @Override
117 public void setCharacteristics(Map characteristics) {
118 super.setCharacteristics(characteristics);
119
120 Object o = characteristics.get("arrayType");
121 if (o != null) {
122 if (((TArrayType)o).isChannel()) {
123 try {
124 UserSettingsProtection.setUnprotected(this,"arrayIndex",0);
125 } catch (Exception e) {
126 e.printStackTrace();
127 }
128 }
129 }
130 }
131
132
133
134
135
136 public ConnectionParameters getConnectionParameters() {
137 return connectionParameters;
138 }
139
140
141
142
143
144 public void setConnectionParameters(ConnectionParameters param) throws CommonException, PropertyVetoException {
145 if (param!=null && connectionParameters != null) {
146 if(param.equals(connectionParameters)) return;
147 }
148 updateDataState(new DataState(DataState.UNDEFINED));
149
150 ConnectionParameters old = connectionParameters;
151 this.connectionParameters = param;
152 AdapterFactory factory = AdapterFactoryService.getInstance().getAdapterFactory();
153 if (getDataSource() != null)
154 factory.releaseDataSource((AcopTransportDataSource) getDataSource());
155 if (param == null) {
156 setDataSource(null);
157 setTitle("No Connection");
158 } else {
159 if (param.getPropertySize() == ConnectionParameters.AUTO_PROPERTY_SIZE) {
160 param = param.deriveWithPropertySize(1);
161 }
162 AcopTransportDataSource ds = factory.createDataSource(param);
163 setDataSource(ds);
164 }
165
166 firePropertyChange(CONNECTION_PARAMETERS_PROPERTY,old, connectionParameters);
167 }
168
169
170
171
172
173 public int getArrayIndex() {
174 return arrayIndex;
175 }
176
177
178
179
180
181 public void setArrayIndex(int arrayIndex) {
182 if (this.arrayIndex == arrayIndex) return;
183 int oldValue = this.arrayIndex;
184 this.arrayIndex = arrayIndex;
185 firePropertyChange("arrayIndex", oldValue, this.arrayIndex);
186 }
187
188
189
190
191
192 @Override
193 public InfoDialog getInfoDialog() {
194 if (dialog == null) {
195 dialog = new AcopInfoDialog(this);
196 }
197 return dialog;
198 }
199
200
201
202
203
204 public void setPropertiesPopupEnabled(boolean enable) {
205 Action[] actions = getPopupManager().getActions();
206 for (Action a : actions) {
207 if (a != null && "Preferences...".equals(a.getValue(Action.NAME))) {
208 a.setEnabled(enable);
209 return;
210 }
211 }
212 }
213
214
215
216
217
218 public boolean isPropertiesPopupEnabled() {
219 Action[] actions = getPopupManager().getActions();
220 for (Action a : actions) {
221 if (a != null && "Preferences...".equals(a.getValue(Action.NAME))) {
222 return a.isEnabled();
223 }
224 }
225 return false;
226 }
227 }
228