1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
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  		
65  	}
66  
67  	
68  
69  
70  	
71  
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  			
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  			
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                     
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                       
117                       e1.printStackTrace();
118                     }
119                     break;
120                   }
121                 }
122               }
123             });
124             
125             
126             
127             
128             t.setAccessProtocol("Simulate");
129             t.setDeviceContext("TEST"); 
130             t.setDeviceGroup("TEST");  
131             t.setDeviceName("Test1");  
132             t.setDeviceProperty("RandomData");  
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             
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 }