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  import javax.swing.JFrame;
25  import java.awt.*;
26  import java.awt.event.*;
27  import java.util.*;
28  import javax.swing.JComponent;
29  import javax.swing.JPanel;
30  import javax.swing.SwingUtilities;
31  import de.desy.acop.chart.Acop;
32  import de.desy.acop.chart.AcopEvent;
33  import de.desy.acop.transport.AccessMode;
34  import de.desy.acop.transport.AcopTransport;
35  import de.desy.acop.transport.AcopTransportEvent;
36  import de.desy.acop.transport.AcopTransportListener;
37  import de.desy.acop.transport.tine.AcopTransportTine;
38  
39  import java.math.*;
40  import java.util.Random;
41  /**
42   * @version 	1.0
43   * @author
44   */
45  public class AcopDebug extends JFrame
46  {
47    static AcopDebug f;
48    AWindow aWindow;
49    static Button aButton;
50    AMouse aMouse;
51    AAcop aAcop;
52    AAcop aAcop1;
53    static Label acopLabel;
54    static Acop a;
55    static Acop a1;
56    public static void main(String args[]) 
57    {
58      try 
59      {
60        f = new AcopDebug("ACOP Test Frame");
61  //      f.setBounds(100, 100, 600, 500);
62        f.getContentPane().setLayout(null);
63        f.setSize(600,500);
64        a.setBounds(f.getBounds().x + 20,
65                    f.getBounds().y + 20,
66                    f.getBounds().width-50,
67                    f.getBounds().height/2-50);
68        a1.setBounds(f.getBounds().x + 20,
69                    f.getBounds().y + f.getBounds().height/2 + 20,
70                    f.getBounds().width-50,
71                    f.getBounds().height/2-50);
72  //      a.setBounds(10,10,400,300);
73        a.setVisible(true);
74        a.setRandomData(true);
75        a.setYMax(1000);
76        a.setXMax(150);
77        a1.setVisible(true);
78        a1.setRandomData(true);
79        a1.setYMax(1000);
80        a1.setXMax(150);
81        acopLabel = new Label("This is just a label on the frame");
82        acopLabel.setBounds(f.getBounds().x + 20,f.getBounds().y + 20,400,10);
83        aButton.setBounds(f.getBounds().x + 420,f.getBounds().y + 20,60,20);
84        f.getContentPane().add(acopLabel);
85        f.getContentPane().add(aButton);
86        f.getContentPane().add(a);
87        f.getContentPane().add(a1);
88        f.setVisible(true);
89        f.show();
90      }
91      catch (Exception e) 
92      {
93        System.out.println(">>> Exception in main");
94        e.printStackTrace();
95      }
96    }
97    public AcopDebug(String title)
98    {
99      super(title);
100     aWindow = new AWindow();
101     aMouse = new AMouse();
102     aButton = new Button("Test");
103     aButton.addMouseListener(aMouse);
104     a = new de.desy.acop.chart.Acop();     
105     a1 = new de.desy.acop.chart.Acop();
106     aAcop = new AAcop();
107     aAcop1 = new AAcop();
108     a.addAcopListener(aAcop);
109     //a.setAcopTransport(new AcopTransport());
110     a.getAcopTransport().addAcopTransportProtocol(new AcopTransportTine());
111     a.getAcopTransport().addAcopTransportListener(aAcop);
112     this.addWindowListener(aWindow);
113     a1.addAcopListener(aAcop);
114     //a1.setAcopTransport(new AcopTransport());
115     a1.getAcopTransport().addAcopTransportProtocol(new AcopTransportTine());
116     a1.getAcopTransport().addAcopTransportListener(aAcop);
117   }
118   class AMouse extends java.awt.event.MouseAdapter
119   {
120     public void mouseClicked(java.awt.event.MouseEvent evt)
121     {
122       Object object = evt.getSource();
123       if (object == aButton)
124         aButton_mouseClicked(evt);
125     }
126   }
127   void aButton_mouseClicked(java.awt.event.MouseEvent evt)
128   {
129     System.out.println("Button pressed");
130     for (int i=0; i<141; i++)
131     {
132       x[i] = i;
133     }
134     AcopTransport at = a.getAcopTransport();
135     a.setYMax(50);
136     a.setYMin(-50);
137     at.setAccessProtocol("TINE");
138     at.setAccessRate("1000");
139     at.setDeviceContext("HERA");
140     at.setDeviceGroup("HEPBPM");
141     at.setDeviceName("WL197 MX");
142     at.setDeviceProperty("ORBIT.X"); 
143     a.setForeground(Color.BLUE);
144     at.setAccessMode(AccessMode.POLL);
145     a.setDisplayMode(4);
146     a.setRandomData(false);
147     int id = at.attachLink(y,141,null,0);
148     at.setDeviceProperty("ORBIT.Y"); 
149     at.setDeviceName("WL164 MY");
150     id = at.attachLink(z,141,null,0);
151 
152     at = a1.getAcopTransport();
153     a1.setYMax(50);
154     a1.setYMin(-50);
155     at.setAccessProtocol("TINE");
156     at.setAccessRate("1000");
157     at.setDeviceContext("HERA");
158     at.setDeviceGroup("HEPBPM");
159     at.setDeviceProperty("ORBIT.Y"); 
160     at.setDeviceName("WL164 MY");
161     a1.setForeground(Color.GREEN);
162     at.setAccessMode(AccessMode.POLL);
163     a1.setDisplayMode(4);
164     id = at.attachLink(z,141,null,0);
165     a1.setRandomData(false);
166   }
167   class AButton extends Button
168   {
169     AButton(String s)
170     {
171       super(s);
172     }
173     /**
174 		 * @see java.awt.Component#addMouseListener(MouseListener)
175 		 */
176 		public synchronized void addMouseListener(MouseListener l)
177 		{
178 			super.addMouseListener(l);
179 		}
180 
181   }
182   class AWindow extends java.awt.event.WindowAdapter
183   {
184     public void windowClosing(java.awt.event.WindowEvent evt)
185     {
186       Object object = evt.getSource();
187       if (object == f) 
188       {
189         f_WindowClosing(evt);
190         System.exit(0);
191       }
192     }
193   }
194   void f_WindowClosing(java.awt.event.WindowEvent evt)
195   {
196     setVisible(false);     // hide the Frame
197     a.getAcopTransport().closeLink(-1);
198   }
199   class AAcop implements de.desy.acop.chart.AcopListener, AcopTransportListener
200   {
201     public void acopMouseExit(de.desy.acop.chart.AcopEvent evt)
202     {
203       Object object = evt.getSource();
204       if (object == a) a_AcopMouseExit(evt);
205     }
206 
207     public void acopMouseMove(de.desy.acop.chart.AcopEvent evt)
208     {
209       Object object = evt.getSource();
210       if (object == a) a_AcopMouseMove(evt);
211     }
212 
213     public void acopMouseZoom(de.desy.acop.chart.AcopEvent evt)
214     {
215       Object object = evt.getSource();
216       if (object == a) a_AcopMouseZoom(evt);
217     }
218     public void acopMouseEnter(de.desy.acop.chart.AcopEvent evt)
219     {
220       Object object = evt.getSource();
221       if (object == a) a_AcopMouseEnter(evt);
222     }
223 
224     public void acopReceive(AcopEvent receive)
225     {
226       // deprecated
227     }
228     public void dataEventReceived(AcopTransportEvent event)
229     {
230       Object object = event.getSource();
231       if (object == a.getAcopTransport()) a_AcopReceive(event);
232       if (object == a1.getAcopTransport()) a1_AcopReceive(event);
233     }
234 
235     public void acopMouseClick(de.desy.acop.chart.AcopEvent evt)
236     {
237       Object object = evt.getSource();
238       if (object == a) a_AcopMouseClick(evt);
239     }
240 
241     /* (non-Javadoc)
242      * @see de.desy.acop.chart.AcopListener#AcopMouseDoubleClick(de.desy.acop.chart.AcopEvent)
243      */
244     public void acopMouseDoubleClick(AcopEvent doubleClick)
245     {
246       // TODO Auto-generated method stub
247       
248     }
249 
250 	public void acopMousePressed(AcopEvent pressed) {
251 		// TODO Auto-generated method stub
252 		
253 	}
254   }  
255   void a_AcopMouseEnter(de.desy.acop.chart.AcopEvent evt)
256   {
257   }
258   void a_AcopMouseExit(de.desy.acop.chart.AcopEvent evt)
259   {
260   }
261   float[] x = new float[141];
262   float[] y = new float[141];
263   float[] z = new float[141];
264   Random r = new Random();
265   void a_AcopMouseClick(de.desy.acop.chart.AcopEvent evt)
266   {
267     AcopTransport at = a.getAcopTransport();
268 //    a.setAccessProtocol("Simulate");
269     at.setAccessProtocol("TINE");
270     at.setAccessMode(AccessMode.READ);
271     at.setAccessRate("1000");
272     at.setDeviceContext("TEST");
273     at.setDeviceGroup("SINE");
274     at.setDeviceName("SINEDEV_0");
275     at.setDeviceProperty("SINE"); 
276     int rc = at.execute(y,141,null,0);
277 //    System.out.println("ACOP Clicked");
278     a.setRandomData(false);
279     a.setForeground(Color.RED);
280     for (int i=0; i<141; i++)
281     {
282 //      y[i] = r.nextFloat() * 100;
283       x[i] = i;
284     }
285     a.clearScreen(-1,0);
286     a.draw(y,x,null,null,141,100);
287   }
288   void a_AcopMouseMove(de.desy.acop.chart.AcopEvent evt)
289   {
290   }
291   void a_AcopMouseZoom(de.desy.acop.chart.AcopEvent evt)
292   {
293   }
294   void a_AcopReceive(AcopTransportEvent evt)
295   {
296 //    int[] d = new int[1];
297     a.clearScreen(-1,0);
298     a.setForeground(Color.RED);
299 //    a.draw(y,x,null,null,141,100);
300     a.draw(y);
301 //    a.GetDataSize(d,null,-1);
302 //    acopLabel.setText(a.getStatus() + " " + a.GetDataSize(-1) + " elements " + a.getTimeStamp().toString());
303     a.setForeground(Color.BLUE);
304 //    a.draw(z,x,null,null,141,100);
305     a.draw(z);
306   }
307   void a1_AcopReceive(AcopTransportEvent evt)
308   {
309 //    int[] d = new int[1];
310     a1.clearScreen(-1,1);
311     a1.setForeground(Color.BLUE);
312     a1.draw(z,x,null,null,141,100);
313 //    a.GetDataSize(d,null,-1);
314     AcopTransport at = a1.getAcopTransport();
315     acopLabel.setText(at.getStatus() + " " + at.getDataSize(-1) + " elements " + at.getTimeStamp().toString());
316   }
317 }