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 debugTest;
24  
25  import java.awt.Color;
26  import java.awt.GridBagConstraints;
27  import java.awt.GridBagLayout;
28  import java.awt.Insets;
29  
30  import javax.swing.JFrame;
31  import javax.swing.JPanel;
32  
33  import com.cosylab.util.CommonException;
34  
35  import de.desy.acop.displayers.AcopChart;
36  import de.desy.acop.displayers.tools.AcopChartConsumer;
37  import de.desy.acop.transport.AccessMode;
38  import de.desy.acop.transport.AcopTransport;
39  import de.desy.acop.transport.AcopTransportEvent;
40  import de.desy.acop.transport.AcopTransportListener;
41  
42  public class NewAcopDisplayerTest extends Object {
43  	
44      static class DisplayerData
45      {
46        AcopChartConsumer c;
47        int linkHandle = -1;
48        double[] data = new double[100];
49        public double[] getData() { return data; }
50        public int getLinkHandle() { return linkHandle; }
51        public AcopChartConsumer getAcopDataConsumer() { return c; }
52        public void setLinkHandle(int handle) 
53        { 
54          linkHandle = handle;
55        }
56        public DisplayerData(AcopChartConsumer c)
57        {
58          this.c = c;
59        }
60      }
61      static DisplayerData[] dataSets = new DisplayerData[2];
62  	public NewAcopDisplayerTest() {
63  		super();
64  		// TODO Auto-generated constructor stub
65  	}
66  
67  	/**
68  	 * @param args
69  	 */
70  	/**
71  	 * @param args
72  	 */
73  	public static void main(String[] args) {
74  		try {
75  			
76  			JFrame f= new JFrame();
77  			f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
78  			
79  			JPanel p= new JPanel();
80  			p.setLayout(new GridBagLayout());
81  			
82  			AcopChart dis= new AcopChart();
83  			
84  			// this setting does not seem to be working
85  			dis.setYMin(-10.0);
86  			dis.setYMax(110.0);
87  			
88  			p.add(dis,new GridBagConstraints(0,0,1,1,1.0,1.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(4,4,4,4),0,0));
89  			
90  			f.setContentPane(p);
91  			f.setSize(500,300);
92  			f.setVisible(true);
93  			
94  			// I create first chart data series, everything ok
95  			AcopChartConsumer c= dis.getConsumer("A",AcopChartConsumer.class);
96  			c.setColor(Color.RED);
97              
98              AcopTransport t = c.getAcop().getAcopTransport();
99              t.addAcopTransportListener(new AcopTransportListener()
100             {
101               public void dataEventReceived(AcopTransportEvent e)
102               {
103                 int id = e.getLinkId();
104                 for (int i=0; i<dataSets.length; i++)
105                 {
106                   if (id == dataSets[i].getLinkHandle())
107                   {
108                     //System.out.println("update link " + id);
109                     double ts = dataSets[i].getAcopDataConsumer().getAcop().getAcopTransport().getDataTimeStamp();
110                     try
111                     {
112                       dataSets[i].getAcopDataConsumer().updateValue((long)(ts*1000),dataSets[i].getData());
113                     }
114                     catch (CommonException e1)
115                     {
116                       // TODO Auto-generated catch block
117                       e1.printStackTrace();
118                     }
119                     break;
120                   }
121                 }
122               }
123             });
124             // turning grouping on will interfer with testing the different
125             // updates at different rates, etc. 
126             // (grouped = true would only give one receive event when all member have notified) 
127             //t.setGrouped(true); < don't do this here
128             t.setAccessProtocol("Simulate");
129             t.setDeviceContext("TEST"); // ignored in Simulation mode
130             t.setDeviceGroup("TEST");  // ignored in Simulation mode
131             t.setDeviceName("Test1");  // ignored in Simulation mode
132             t.setDeviceProperty("RandomData");  // ignored in Simulation mode
133             t.setAccessMode(AccessMode.POLL);
134             t.setAccessRate("1000");
135             dataSets[0] = new DisplayerData(c);
136             int id = t.attachLink(dataSets[0].getData());
137             if (id >= 0) dataSets[0].setLinkHandle(id);
138             // second link:
139 			c= dis.getConsumer("B",AcopChartConsumer.class);
140 			c.setColor(Color.BLUE);
141             t.setAccessRate("3000");
142             t.setDeviceName("Test2");
143             dataSets[1] = new DisplayerData(c);
144             id = t.attachLink(dataSets[1].getData());
145             if (id >= 0) dataSets[1].setLinkHandle(id);
146 			
147 		} catch (Exception e) {
148 			e.printStackTrace();
149 		}
150 	}
151 
152 }