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.MultiplierConverter;
29 import com.cosylab.util.CommonException;
30
31 import de.desy.acop.chart.AcopDisplayMode;
32 import de.desy.acop.chart.AcopDrawStyleEnum;
33 import de.desy.acop.chart.AcopFFTEnum;
34 import de.desy.acop.displayers.AcopChart;
35 import de.desy.acop.displayers.tools.AcopGraphParameters;
36 import de.desy.acop.transport.AccessMode;
37 import de.desy.acop.transport.ConnectionParameters;
38
39 public class ChartExample {
40 public static void main(String[] args) {
41 //How to connect chart with remote properties?
42 //First we create an instance of the AcopChart object.
43 AcopChart chart = new AcopChart();
44
45 //We require AcopGraphParameters which describe the remote property
46
47 //Let's display a few graphs in this chart. First we need to define the
48 //connection point for each graph. This is done by constructing
49 //ConnectionParameters
50 ConnectionParameters cp = new ConnectionParameters("TINE", "context",
51 "server", "device", "property", AccessMode.POLL, 1000);
52 //These parameters describe a remote property 'context/server/device/property'
53 //in the TINE control system. We will request a constant monitoring,
54 //therefore AccessMode.POLL was used. Polling rate is set to 1000 milliseconds,
55 //which means that value on the table will be updated every 1000 milliseconds.
56
57 //Now we make AcopGraphParameters. We will set the color of the graph
58 //to red, use no fft, and display data in the histogram with solid lines
59 //of width 2. We can set the fft, drawStyle and mode properties to any
60 //value included in the enumerations. The last two parameters describe
61 //that we don't intend to show trend.
62 AcopGraphParameters parameters = new AcopGraphParameters(cp, Color.RED,
63 AcopFFTEnum.NoFFT.ordinal(), AcopDrawStyleEnum.PS_SOLID.ordinal(),
64 AcopDisplayMode.SimpleHistogram.ordinal(), 2, false,0);
65
66 //Parameters are then attached to the chart. Connection is created automatically.
67 try {
68 chart.addDisplayerParameters(parameters);
69 } catch (CommonException e1) {
70 e1.printStackTrace();
71 } catch (PropertyVetoException e1) {
72 e1.printStackTrace();
73 }
74 //If no exception occurred, chart should show the remote value.
75
76 //AcopChart is able to display multiple connections. We will construct new
77 //AcopGraphParameters for the same property and will use a converter for this
78 //graph. However now we don't want to show all devices in the multi-channel.
79 //We only want to show the first 20 device. This can be set by configuring
80 //ConnectionParameters (the last parameter in the constructor).
81 ConnectionParameters cp1 = new ConnectionParameters("TINE", "context",
82 "server", "device", "property", AccessMode.POLL, 1000, 20);
83 AcopGraphParameters parameters1 = new AcopGraphParameters(cp1,
84 Color.BLUE, AcopFFTEnum.NoFFT.ordinal(), AcopDrawStyleEnum.PS_SOLID.ordinal(),
85 AcopDisplayMode.PolyLine.ordinal(), 1, false, 0,
86 new MultiplierConverter(2));
87 //Here we used a MultiplierConverter which will multiply the value for a
88 //factor '2'. This graph will be shown as the polyline.
89 try {
90 chart.addDisplayerParameters(parameters1);
91 } catch (CommonException e1) {
92 e1.printStackTrace();
93 } catch (PropertyVetoException e1) {
94 e1.printStackTrace();
95 }
96
97 //Now we want to display a trend line in the graph. We will construct new
98 //AcopGraphParameters with a trend length of 1000. This means that the
99 //graph will show 1000 points. When the number of points exceeds this number
100 //the first value will be removed.
101 AcopGraphParameters parameters2 = new AcopGraphParameters(cp,
102 Color.BLUE, AcopFFTEnum.NoFFT.ordinal(), AcopDrawStyleEnum.PS_SOLID.ordinal(),
103 AcopDisplayMode.PolyLine.ordinal(), 1, true, 1000);
104 //It does not make sense displaying a histogram and trend on the same chart,
105 //therefore we have to remove all previous graphs. To remove a single
106 //parameters we can use the removeDisplayerParameters method.
107 chart.removeDisplayerParameters(parameters);
108 //To remove all parameters at once, we can also use method setDisplayerParameters.
109 try {
110 chart.setDisplayerParameters(new AcopGraphParameters[]{parameters2});
111 } catch (CommonException e) {
112 e.printStackTrace();
113 } catch (PropertyVetoException e) {
114 e.printStackTrace();
115 }
116
117 //When adding parameters to the chart, chart will adjust the vertical boundaries
118 //with the values which are read from the remote property information. We are
119 //not sattisfied with this values and want to set different boundaries.
120 chart.setYMax(30);
121 chart.setYMin(-30);
122 //Another option is to allow the chart to adjust its boundaries by itself
123 //for best visualization.
124 chart.setYBestScale(true);
125 chart.setXBestScale(true);
126
127 //We can also enable horizontal and or vertical grid
128 chart.setXGrid(true);
129 chart.setYGrid(true);
130 //And if we aren't satisfied with the looks of the grid, we can customize it.
131 //We can set it's color, the width of grid's lines and also the type of lines
132 chart.setGridColor(Color.WHITE);
133 chart.setGridWidth(2);
134 chart.setGridStyle(AcopDrawStyleEnum.PS_DASH_DOT.ordinal());
135
136 //And finally, if we want, we can change the color of background and foreground.
137 chart.setBackground(Color.BLACK);
138 }
139
140 }