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