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