1 package de.desy.acop.displayers;
2
3 import java.beans.PropertyVetoException;
4
5 import javax.swing.Action;
6
7 import com.cosylab.gui.CheckBoxController;
8 import com.cosylab.gui.InfoDialog;
9 import com.cosylab.gui.displayers.DataConsumer;
10 import com.cosylab.gui.displayers.DataState;
11 import com.cosylab.gui.displayers.DisplayerUtilities;
12 import com.cosylab.gui.displayers.DoubleSeqConsumer;
13 import com.cosylab.gui.util.UserSettingsProtection;
14 import com.cosylab.util.CommonException;
15
16 import de.desy.acop.displayers.tools.AcopDisplayer;
17 import de.desy.acop.displayers.tools.AcopDisplayerTransferHandler;
18 import de.desy.acop.displayers.tools.AcopInfoDialog;
19 import de.desy.acop.transport.ConnectionParameters;
20 import de.desy.acop.transport.adapters.AcopTransportDataSource;
21 import de.desy.acop.transport.adapters.AdapterFactory;
22 import de.desy.acop.transport.adapters.AdapterFactoryService;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class AcopCheckBox extends CheckBoxController implements AcopDisplayer {
49
50 private static final long serialVersionUID = 1647491427169502213L;
51
52 private int arrayIndex=0;
53
54 private ConnectionParameters connectionParameters;
55
56 private InfoDialog dialog;
57
58
59
60
61 public AcopCheckBox() {
62 this(DEFAULT_TEXT);
63 }
64
65
66
67
68
69
70 public AcopCheckBox(String title) {
71 super();
72 new AcopDisplayerTransferHandler(this);
73 UserSettingsProtection.setProtection(this,DisplayerUtilities.COMMON_NUMERIC_DISPLAYER_PROPERTIES,false);
74 }
75
76 @Override
77 public int getArrayIndex() {
78 return arrayIndex;
79 }
80
81 @Override
82 public void setArrayIndex(int index) {
83 if (arrayIndex == index) return;
84 int oldValue = arrayIndex;
85 arrayIndex = index;
86 firePropertyChange("arrayIndex", oldValue, arrayIndex);
87 }
88
89 @Override
90 public InfoDialog getInfoDialog() {
91 if (dialog == null) {
92 dialog = new AcopInfoDialog(this);
93 }
94 return dialog;
95 }
96
97 @Override
98 public void updateValue(long timestamp, double[] value)
99 throws CommonException {
100 updateValue(timestamp, DisplayerUtilities.extract(arrayIndex,value));
101 }
102
103 @SuppressWarnings("unchecked")
104 @Override
105 public DataConsumer getDataConsumer(Class type) {
106 if (type == DoubleSeqConsumer.class){
107 return this;
108 } else return super.getDataConsumer(type);
109 }
110
111 @Override
112 public ConnectionParameters getConnectionParameters() {
113 return connectionParameters;
114 }
115
116 @Override
117 public void setConnectionParameters(ConnectionParameters param)
118 throws CommonException, PropertyVetoException {
119 if (param!=null && connectionParameters != null) {
120 if(param.equals(connectionParameters)) return;
121 }
122 updateDataState(new DataState(DataState.UNDEFINED));
123
124 ConnectionParameters old = connectionParameters;
125 this.connectionParameters = param;
126 AdapterFactory factory = AdapterFactoryService.getInstance().getAdapterFactory();
127 if (getDataSource() != null)
128 factory.releaseDataSource((AcopTransportDataSource) getDataSource());
129 if (param == null) {
130 setDataSource(null);
131 setTitle("No Connection");
132 } else {
133 if (param.getPropertySize() == ConnectionParameters.AUTO_PROPERTY_SIZE) {
134 param = param.deriveWithPropertySize(1);
135 }
136 AcopTransportDataSource ds = factory.createDataSource(param);
137 setDataSource(ds);
138 }
139
140 firePropertyChange(CONNECTION_PARAMETERS_PROPERTY,old, connectionParameters);
141 }
142
143
144
145
146
147 public void setPropertiesPopupEnabled(boolean enable) {
148 Action[] actions = getPopupManager().getActions();
149 for (Action a : actions) {
150 if (a != null && "Preferences...".equals(a.getValue(Action.NAME))) {
151 a.setEnabled(enable);
152 return;
153 }
154 }
155 }
156
157
158
159
160
161 public boolean isPropertiesPopupEnabled() {
162 Action[] actions = getPopupManager().getActions();
163 for (Action a : actions) {
164 if (a != null && "Preferences...".equals(a.getValue(Action.NAME))) {
165 return a.isEnabled();
166 }
167 }
168 return false;
169 }
170
171
172 }