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