1 /*
2 * Copyright (c) 2006 Stiftung Deutsches Elektronen-Synchroton,
3 * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
4 *
5 * THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
6 * WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
7 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE AND
8 * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
9 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
11 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE DEFECTIVE
12 * IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING, REPAIR OR
13 * CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE.
14 * NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
15 * DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
16 * OR MODIFICATIONS.
17 * THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION, MODIFICATION,
18 * USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE DISTRIBUTION OF THIS
19 * PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU MAY FIND A COPY
20 * AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
21 */
22
23 package de.desy.acop.displayers.tools;
24
25 import java.util.Map;
26
27 import com.cosylab.gui.adapters.Converter;
28 import com.cosylab.gui.displayers.DisplayerParameters;
29 import com.cosylab.gui.displayers.DoubleDisplayer;
30
31 import de.desy.acop.transport.ConnectionParameters;
32
33 /**
34 * <code>AcopDisplayerParameters</code> are parameters displayer parameters intended
35 * to be used in combination with <code>AcopDisplayer</code>. This parameters holds
36 * reference to the remote connection point as well as other parameters that
37 * define the look and presentation of the value on the displayer, such as minimum and
38 * maximum value, format etc.
39 *
40 * @author <a href="mailto:jaka.bobnar@cosylab.com">Jaka Bobnar</a>
41 * @version $Id: Templates.xml,v 1.10 2004/01/13 16:17:13 jbobnar Exp $
42 * @see AcopDisplayer
43 */
44 public class AcopDisplayerParameters extends DisplayerParameters {
45
46 private static final long serialVersionUID = 2758958154017521990L;
47
48 /**
49 * Constructs new AcopDisplayerParameters.
50 *
51 */
52 public AcopDisplayerParameters() {
53 this(null, 0, Double.NaN, Double.NaN, null, null);
54 }
55
56 /**
57 * Constructs new AcopDisplayerParameters with the provided connection point.
58 *
59 * @param parameters remote connection point
60 */
61 public AcopDisplayerParameters(ConnectionParameters parameters) {
62 this(parameters, 0, Double.NaN, Double.NaN, null, null);
63 }
64
65 /**
66 * Constructs new AcopDisplayerParameters with the provided connection point
67 * and index in the array of incomming data.
68 *
69 * @param parameters remote connectin point
70 * @param index array data index
71 */
72 public AcopDisplayerParameters(ConnectionParameters parameters, int index) {
73 this(parameters, index, Double.NaN, Double.NaN, null, null);
74 }
75
76 /**
77 * Constructs new AcopDisplayerParameters using the provided parameters.
78 *
79 * @param parameters remote connection point
80 * @param index array data index
81 * @param min minimum value
82 * @param max maximum value
83 * @param units physical units
84 * @param format C-style format
85 */
86 public AcopDisplayerParameters(ConnectionParameters parameters, int index, double min, double max, String units, String format) {
87 this(parameters.getRemoteName(), 6, parameters, index, min, max, units, format);
88 }
89
90 /**
91 * Constructs new AcopDisplayerParameters using the provided parameters.
92 *
93 * @param name the name of the parameters
94 * @param size initial number of all parameters
95 * @param parameters remote connection point
96 * @param index array data index
97 * @param min maximum value
98 * @param max minimum value
99 * @param units physical units
100 * @param format C-style format
101 */
102 protected AcopDisplayerParameters(String name, int size, ConnectionParameters parameters, int index, double min, double max, String units, String format) {
103 super(parameters!=null ? parameters.getRemoteName(): name, size, min, max, units, format);
104
105 values.put(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY,parameters);
106 values.put(AcopDisplayer.ARRAY_INDEX_PROPERTY,index);
107 }
108
109 /**
110 * Constructs new AcopDisplayerParameters gathering the essential data from
111 * the provided displayer.
112 *
113 * @param name the name of the parameters
114 * @param size the number of all parameters
115 * @param adisp source for connection related parameters
116 * @param ddisp source for display related parameters
117 */
118 protected AcopDisplayerParameters(String name, int size, AcopDisplayer adisp, DoubleDisplayer ddisp) {
119 super(name, size, ddisp);
120
121 values.put(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY,adisp.getConnectionParameters());
122 values.put(AcopDisplayer.ARRAY_INDEX_PROPERTY,adisp.getArrayIndex());
123 }
124
125 /**
126 * Constructs new AcopDisplayerParameters gathering the essential data from
127 * the provided displayer.
128 *
129 * @param adisp source for connection related parameters
130 * @param ddisp source for display related parameters
131 */
132 public AcopDisplayerParameters(AcopDisplayer adisp, DoubleDisplayer ddisp) {
133 this(adisp.getConnectionParameters() != null ? adisp.getConnectionParameters().getRemoteName() : null, 6, adisp, ddisp);
134 }
135
136 /**
137 * Constructs new AcopDisplayerParameters using the provided parameters.
138 *
139 * @param parameters remote connection point
140 * @param index array data index
141 * @param converter converter associated with the data source
142 */
143 public AcopDisplayerParameters(ConnectionParameters parameters, int index, Converter converter) {
144 this(parameters, index, Double.NaN, Double.NaN, null, null, converter);
145 }
146
147 /**
148 * Constructs new AcopDisplayerParameters using the provided parameters.
149 *
150 * @param parameters remote connection point
151 * @param index array data index
152 * @param min minimum value
153 * @param max maximum value
154 * @param units physical units
155 * @param format C-style format
156 * @param converter converter associated with the data source
157 */
158 public AcopDisplayerParameters(ConnectionParameters parameters, int index, double min, double max, String units, String format, Converter converter) {
159 this(parameters!=null ? parameters.getRemoteName() : "", 6, parameters, index, min, max, units, format, converter);
160 }
161
162 /**
163 * Contructs new AcopDisplayerParameters using the provided parameters.
164 *
165 * @param name the name of the parameters
166 * @param size number of all parameters
167 * @param parameters remote connection point
168 * @param index array data index
169 * @param min minimum value
170 * @param max maximum value
171 * @param units physical units
172 * @param format C-style format
173 * @param converter converter associated with the data source
174 */
175 protected AcopDisplayerParameters(String name, int size, ConnectionParameters parameters, int index, double min, double max, String units, String format, Converter converter) {
176 this(name, size, parameters, index, min, max, units, format);
177 values.put(AcopDisplayer.CONVERTER_PROPERTY, converter);
178 }
179
180 /**
181 * Returns the converter associated with this parameters.
182 *
183 * @return the converter
184 */
185 public Converter getConverter() {
186 return (Converter) values.get(AcopDisplayer.CONVERTER_PROPERTY);
187 }
188
189
190
191 /**
192 * Creates new instance of AcopDisplayerParameters.
193 *
194 * @param name the name of this parameters
195 * @param vaues additional parameters - all necessary parameters should be included
196 * in this map
197 */
198 protected AcopDisplayerParameters(String name, Map<String,Object> values) {
199 super(name, values);
200 }
201
202 /* (non-Javadoc)
203 * @see java.lang.Object#hashCode()
204 */
205 @Override
206 public int hashCode() {
207 return toString().hashCode();
208 }
209
210 /* (non-Javadoc)
211 * @see java.lang.Comparable#compareTo(java.lang.Object)
212 */
213 public int compareTo(Object o) {
214 if (!(o instanceof AcopDisplayerParameters)) return -1;
215 return this.toString().compareTo(o.toString());
216 }
217
218 /**
219 * Returns the connection parameters.
220 * @return the remote connection point
221 */
222 public ConnectionParameters getConnectionParameters() {
223 return (ConnectionParameters)values.get(AcopDisplayer.CONNECTION_PARAMETERS_PROPERTY);
224 }
225
226 /**
227 * Returns the array index.
228 *
229 * @return the arrayIndex
230 */
231 public int getArrayIndex() {
232 return getInt(AcopDisplayer.ARRAY_INDEX_PROPERTY);
233 }
234
235 /**
236 * Returns new AcopDisplayerParameters which resebles this object but has
237 * a different array index.
238 *
239 * @param arrayIndex new array index
240 * @return new acop displayer parameters
241 */
242 public AcopDisplayerParameters deriveWith(int arrayIndex) {
243 AcopDisplayerParameters a=new AcopDisplayerParameters(name,values);
244 values.put(AcopDisplayer.ARRAY_INDEX_PROPERTY,arrayIndex);
245 return a;
246 }
247
248 }