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