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.demo.example;
24
25 import java.awt.Color;
26 import java.beans.PropertyVetoException;
27
28 import com.cosylab.gui.adapters.Converter;
29 import com.cosylab.gui.adapters.ConverterChain;
30 import com.cosylab.gui.adapters.LinearConverter;
31 import com.cosylab.gui.adapters.LogarithmicConverter;
32 import com.cosylab.gui.components.wheelswitch.RadialWheelswitchFormatter;
33 import com.cosylab.gui.components.wheelswitch.WheelswitchFormatter;
34 import com.cosylab.util.CommonException;
35
36 import de.desy.acop.displayers.AcopWheelswitch;
37 import de.desy.acop.transport.AccessMode;
38 import de.desy.acop.transport.ConnectionParameters;
39
40 public class WheelswitchExample {
41
42 public static void main(String[] args) {
43
44 //How to connect wheelswitch to a remote property?
45 //First we create an instance of the AcopWheelswitch object.
46 AcopWheelswitch wheelswitch = new AcopWheelswitch();
47 //We require ConnectionParameters which describe the remote property
48 ConnectionParameters parameters = new ConnectionParameters("TINE",
49 "context", "server", "device", "property", AccessMode.POLL, 1000);
50 //These parameters describe a remote property 'context/server/device/property'
51 //in the TINE control system. We will request a constant monitoring,
52 //therefore AccessMode.POLL was used. Polling rate is set to 1000 milliseconds,
53 //which means that value on the wheelswitch will be updated every 1000 milliseconds.
54 //Parameters are then attached to the wheelswitch. Connection is created automatically.
55 try {
56 wheelswitch.setConnectionParameters(parameters);
57 } catch (CommonException e) {
58 e.printStackTrace();
59 } catch (PropertyVetoException e) {
60 e.printStackTrace();
61 }
62 //If no exception occurred, wheelswitch should show the remote value.
63
64
65 //The wheelswitch formats the displayed number according to its formatter.
66 //Maybe we want to display the number in radial units.
67 wheelswitch.setFormatter(new RadialWheelswitchFormatter());
68 //Or we want to display a normal decimal number.
69 wheelswitch.setFormatter(new WheelswitchFormatter());
70
71
72 //The incoming values are too large (large exponents) and have a large extent.
73 //We want to show values in more readable form. Let us show the logarithm of
74 //the value. For this we will use a logarithmic converter with logarithm base 10:
75 LogarithmicConverter logConverter = new LogarithmicConverter(10);
76 try {
77 wheelswitch.setConverter(logConverter);
78 } catch (PropertyVetoException e) {
79 e.printStackTrace();
80 }
81 //Instead of real value 'x' wheelswitch will now show log_10(x).
82 //Similarly we can shift the values to be comparable with some other property.
83 //We will use linear converter:
84 LinearConverter linConverter = new LinearConverter(5,4);
85 try {
86 wheelswitch.setConverter(linConverter);
87 } catch (PropertyVetoException e) {
88 e.printStackTrace();
89 }
90 //Instead of value 'x' wheelswitch will now show 5 x + 4. We can even combine both
91 //converters into a single one.
92 try {
93 ConverterChain chain = new ConverterChain(new Converter[]{logConverter, linConverter});
94 wheelswitch.setConverter(chain);
95 } catch (PropertyVetoException e) {
96 e.printStackTrace();
97 }
98 //Slider will now show 5 (log_10(x)) + 4.
99
100 //If we don't want to change the values at all (just use the wheelswitch
101 //as a monitor displayer) we can put in read only mode
102 wheelswitch.setEditable(false);
103
104 //When the value received from the 3rd party exceeds the set value bounds (minimum/maximum),
105 //the wheelswitch may visually indicate this by tilting the border.
106 wheelswitch.setTiltingEnabled(true);
107
108 //Other properties of the wheelswitch can also simply be adjusted by calling the
109 //appropriate setter methods. These properties include maximum/minimum value
110 //background/foreground color, title etc.:
111 wheelswitch.setMaximum(100);
112 wheelswitch.setMinimum(5.2);
113 wheelswitch.setBackground(Color.RED);
114 wheelswitch.setForeground(Color.GREEN);
115 }
116 }