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