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.util.CommonException;
33
34 import de.desy.acop.displayers.AcopTable;
35 import de.desy.acop.displayers.table.AcopTableParameters;
36 import de.desy.acop.displayers.table.TableColumnType;
37 import de.desy.acop.transport.AccessMode;
38 import de.desy.acop.transport.ConnectionParameters;
39
40 public class TableExample {
41
42 public static void main(String[] args) {
43 //How to connect table with remote properties?
44 //First we create an instance of the AcopTable object.
45 AcopTable table = new AcopTable();
46
47 //Let's make a table which displays the names and values of a multi-channel
48 //array or spectrum. For this we will require two columns, which will be
49 //specified by two AcopTableParameters. For each of these parameters
50 //we have to define connection points. Therefore we have to create
51 //ConnectionParameters which specify this array:
52 ConnectionParameters connectionParameters = new ConnectionParameters("TINE",
53 "context", "server", "device", "property", AccessMode.POLL, 1000);
54 //These parameters describe a remote property 'context/server/device/property'
55 //in the TINE control system. We will request a constant monitoring,
56 //therefore AccessMode.POLL was used. Polling rate is set to 1000 milliseconds,
57 //which means that value on the table will be updated every 1000 milliseconds.
58 //Now we make AcopTableParameters. First for the names of the devices.
59 AcopTableParameters namesParameters = new AcopTableParameters(
60 connectionParameters, TableColumnType.NAME, "Devices");
61 //Here we used a TableColumnType.NAME. Now we have to create parameters for
62 //the values, where we use the TableColumnType.VALUE
63 AcopTableParameters valuesParameters = new AcopTableParameters(
64 connectionParameters, TableColumnType.VALUE, "Values");
65 //We could also display all values as bits by using TableColumnType.BIT.
66 //When making a column with names we could also use TableColumnType.STRING.
67 //However, when dealing with static names (devices names do not change in time)
68 //it is better to use the NAME type. STRING type could be used when monitoring
69 //a channel with string values.
70
71 //Parameters are then attached to the table. Connection is created automatically.
72 try {
73 table.setDisplayerParameters(new AcopTableParameters[]{
74 namesParameters, valuesParameters});
75 } catch (CommonException e1) {
76 e1.printStackTrace();
77 } catch (PropertyVetoException e1) {
78 e1.printStackTrace();
79 }
80 //If no exception occurred, table should show the remote value.
81
82 //Anytime we can add additional columns displaying any channel we want.
83 //Let's say that we want to display a channel but we want the values of that
84 //channel are too large to be readable. We can use logarithmic converter
85 //and instead of 'x' the table will show 'log_10(x)'.
86 ConnectionParameters cp = new ConnectionParameters("TINE",
87 "context", "server", "device", "property", AccessMode.POLL, 1000);
88 LogarithmicConverter logConverter = new LogarithmicConverter(10);
89 AcopTableParameters atp = new AcopTableParameters(cp,
90 TableColumnType.VALUE, logConverter, "Log(value)");
91 try {
92 table.addDisplayerParameters(atp);
93 } catch (PropertyVetoException e) {
94 e.printStackTrace();
95 } catch (CommonException e) {
96 e.printStackTrace();
97 }
98 //Instead of logarithmic converter we can also choose LinearConverter,
99 //MultiplierConverter, ExponentialConverter or PotentialConverter. We can also
100 //construct a chain of converter combining different mathematical operations:
101 try {
102 LinearConverter linConverter = new LinearConverter(5,4);
103 ConverterChain chain = new ConverterChain(new Converter[]{logConverter, linConverter});
104 AcopTableParameters atp1 = new AcopTableParameters(cp,
105 TableColumnType.VALUE, chain, "5 (log_10(value)) + 4");
106 table.addDisplayerParameters(atp1);
107 } catch (PropertyVetoException e) {
108 e.printStackTrace();
109 } catch (CommonException e) {
110 e.printStackTrace();
111 }
112 //The fourth column in the table will now show 5 (log_10(x)) + 4.
113
114 //Table can show any number of rows one desires. If we are monitoring
115 //a channel which originally has 50 devices, but we are only interested
116 //in the first 10, we set the number of rows.
117 table.setNumberOfRows(10);
118
119 //In runtime we can by default drag the columns around, allowing us to
120 //rearrange the table when we want to put two separated columns together.
121 //We can decide that the user will not be allowed to do that.
122 table.setReorderingAllowed(false);
123
124 //We can also set background/foreground colors.
125 table.setBackground(Color.BLUE);
126 table.setForeground(Color.WHITE);
127 }
128 }