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.util.CommonException;
29  
30  import de.desy.acop.displayers.AcopLabel;
31  import de.desy.acop.transport.AccessMode;
32  import de.desy.acop.transport.ConnectionParameters;
33  
34  public class LabelExample {
35  
36  	public static void main(String[] args) {
37  		
38  		//How to connect label to a remote property?
39  		//First we create an instance of the AcopLabel object.
40  		AcopLabel label = new AcopLabel();
41  		//We require ConnectionParameters which describe the remote property
42  		ConnectionParameters parameters = new ConnectionParameters("TINE",
43  				"context", "server", "device", "property", AccessMode.POLL, 1000);
44  		//These parameters describe a remote property 'context/server/device/property'
45  		//in the TINE control system. We will request a constant monitoring,
46  		//therefore AccessMode.POLL was used. Polling rate is set to 1000 milliseconds,
47  		//which means that value on the label will be updated every 1000 milliseconds.
48  		//Parameters are then attached to the label. Connection is created automatically.
49  		try {
50  			label.setConnectionParameters(parameters);
51  		} catch (CommonException e) {
52  			e.printStackTrace();
53  		} catch (PropertyVetoException e) {
54  			e.printStackTrace();
55  		}
56  		//If no exception occurred, label should show the remote value.
57  				
58  		//We are using the label to display a multi-channel array but we are only
59  		//interested in the first 3 devices. We create a new ConnectionParameters object
60  		//with specified propertySize.
61  		ConnectionParameters p1 = new ConnectionParameters("TINE",
62  				"context", "server", "device", "property", AccessMode.POLL, 1000, 3);
63  		//And set them on the label.
64  		try {
65  			label.setConnectionParameters(p1);
66  		} catch (CommonException e) {
67  			e.printStackTrace();
68  		} catch (PropertyVetoException e) {
69  			e.printStackTrace();
70  		}
71  		
72  		//Other properties of the label can also simply be adjusted by calling the
73  		//appropriate setter methods. These properties include background/foreground color, 
74  		//columns, title etc.:
75  		label.setBackground(Color.RED);
76  		label.setForeground(Color.GREEN);
77  		label.setColumns(10);
78  	}
79  }