KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > ic2d > gui > recording > PlayerFrameTimeLine


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.ic2d.gui.recording;
32
33 import org.objectweb.proactive.ic2d.data.ActiveObject;
34 import org.objectweb.proactive.ic2d.data.DataObjectController;
35 import org.objectweb.proactive.ic2d.gui.EventListsPanel;
36 import org.objectweb.proactive.ic2d.spy.SpyEvent;
37
38 public class PlayerFrameTimeLine extends javax.swing.JFrame JavaDoc {
39
40   private boolean record = false;
41   private boolean play = false;
42   private boolean pause = false;
43   private javax.swing.JLabel JavaDoc state;
44   private javax.swing.JLabel JavaDoc msg;
45
46   private javax.swing.JButton JavaDoc monitoringControlButton;
47   private javax.swing.JButton JavaDoc playButton;
48   private javax.swing.JButton JavaDoc pauseButton;
49   private javax.swing.JButton JavaDoc stopButton;
50   private javax.swing.JButton JavaDoc recordButton;
51   private javax.swing.JProgressBar JavaDoc eventReplayProgressBar;
52
53   private javax.swing.JPanel JavaDoc tpb;
54   private javax.swing.JLabel JavaDoc lpb;
55   private ThreadPlayer threadPlayer;
56   private EventListsPanel eventListsPanel;
57   private DataObjectController dataObjectController;
58
59
60   public PlayerFrameTimeLine(EventListsPanel eventListsPanel, DataObjectController dataObjectController) {
61     super("SpyEvent Player");
62     this.setSize(new java.awt.Dimension JavaDoc(400, 200));
63     this.eventListsPanel = eventListsPanel;
64     this.dataObjectController = dataObjectController;
65     final javax.swing.JButton JavaDoc b1 = new javax.swing.JButton JavaDoc("On");
66     final javax.swing.JButton JavaDoc b2 = new javax.swing.JButton JavaDoc("Off");
67     final javax.swing.JButton JavaDoc b3 = new javax.swing.JButton JavaDoc("Reset");
68     b2.setEnabled(false);
69
70     javax.swing.JPanel JavaDoc c = new javax.swing.JPanel JavaDoc();
71     c.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT);
72     c.setLayout(new java.awt.GridLayout JavaDoc(0, 1));
73     
74     javax.swing.JToolBar JavaDoc tools = new javax.swing.JToolBar JavaDoc();
75     c.add(tools);
76
77     javax.swing.JPanel JavaDoc t = new javax.swing.JPanel JavaDoc();
78     t.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
79     javax.swing.JLabel JavaDoc s = new javax.swing.JLabel JavaDoc();
80     s.setForeground(java.awt.Color.black);
81     s.setText("Status : ");
82     t.add(s);
83     state = new javax.swing.JLabel JavaDoc("Freezed");
84     t.add(state);
85     c.add(t);
86
87     tpb = new javax.swing.JPanel JavaDoc();
88     tpb.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
89     javax.swing.JLabel JavaDoc s3 = new javax.swing.JLabel JavaDoc();
90     s3.setForeground(java.awt.Color.black);
91     s3.setText("Playing status : ");
92     tpb.add(s3);
93     eventReplayProgressBar = new javax.swing.JProgressBar JavaDoc(0, 10);
94     eventReplayProgressBar.setMaximumSize(new java.awt.Dimension JavaDoc(70, 25));
95     eventReplayProgressBar.setStringPainted(true);
96     tpb.add(eventReplayProgressBar);
97     c.add(tpb);
98
99     javax.swing.JPanel JavaDoc t1 = new javax.swing.JPanel JavaDoc();
100     t1.setLayout(new java.awt.FlowLayout JavaDoc(java.awt.FlowLayout.LEFT));
101     javax.swing.JLabel JavaDoc s1 = new javax.swing.JLabel JavaDoc();
102     s1.setForeground(java.awt.Color.black);
103     s1.setText("Recorded messages count : ");
104     t1.add(s1);
105     msg = new javax.swing.JLabel JavaDoc(" 0 ");
106     t1.add(msg);
107
108     b1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
109       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
110         b1.setEnabled(false);
111         b2.setEnabled(true);
112       }
113     });
114     b2.addActionListener(new java.awt.event.ActionListener JavaDoc() {
115       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
116         b2.setEnabled(false);
117         b1.setEnabled(true);
118       }
119     });
120     b3.addActionListener(new java.awt.event.ActionListener JavaDoc() {
121       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
122       }
123     });
124
125     c.add(t1);
126     setContentPane(c);
127     //this.show();
128
addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
129       public void windowClosing(java.awt.event.WindowEvent JavaDoc e) {
130         setVisible(! isVisible());
131       }
132     });
133     createListenerButtons(tools);
134     this.threadPlayer = new ThreadPlayer(eventListsPanel, eventReplayProgressBar);
135     
136     toggleMonitoring();
137     toggleMonitoring();
138   }
139
140
141   public void toggleMonitoring() {
142     if (! dataObjectController.isMonitoring()) {
143       dataObjectController.setMonitoring(true);
144       monitoringControlButton.setText("Disable Monitoring");
145       if (play) stop();
146       state.setText("Freeze");
147       recordButton.setEnabled(true);
148       playButton.setEnabled(false);
149     } else {
150       state.setText("Freezed");
151       monitoringControlButton.setText("Enable Monitoring");
152       dataObjectController.setMonitoring(false);
153       if (record) stop();
154       pauseButton.setEnabled(false);
155       recordButton.setEnabled(false);
156       stopButton.setEnabled(false);
157       playButton.setEnabled(true);
158     }
159   }
160
161
162   public void play() {
163     state.setText("Playing");
164     pause = false;
165     play = true;
166     threadPlayer.play();
167     playButton.setEnabled(false);
168     stopButton.setEnabled(true);
169     pauseButton.setEnabled(true);
170
171   }
172
173
174   public void pause() {
175     pause = true;
176     threadPlayer.pause();
177     pauseButton.setEnabled(false);
178     if (play) {
179       state.setText("Playing: pause");
180       playButton.setEnabled(true);
181     }
182     if (record) {
183       recordButton.setEnabled(true);
184       state.setText("Recording: pause");
185     }
186   }
187
188
189   public void stop() {
190     if (pause)
191       threadPlayer.pause();
192     if (record) {
193       record = false;
194       threadPlayer.record();
195       pauseButton.setEnabled(false);
196       recordButton.setEnabled(true);
197       stopButton.setEnabled(false);
198     }
199     if (play) {
200       play = false;
201       threadPlayer.play();
202       pauseButton.setEnabled(false);
203       playButton.setEnabled(true);
204       stopButton.setEnabled(false);
205     }
206     eventReplayProgressBar.setString("");
207     eventReplayProgressBar.setValue(0);
208     pause = false;
209   }
210
211
212   public void record() {
213     state.setText("Recording");
214     pause = false;
215     record = true;
216     threadPlayer.record();
217     recordButton.setEnabled(false);
218     stopButton.setEnabled(true);
219     pauseButton.setEnabled(true);
220   }
221
222
223   public void recordEvent(ActiveObject activeObject, SpyEvent evt) {
224     int n = threadPlayer.recordEvent(activeObject, evt);
225     if (n > -1) {
226       msg.setText(" " + n);
227     }
228   }
229   
230
231   private void createListenerButtons(javax.swing.JToolBar JavaDoc tools) {
232     javax.swing.JButton JavaDoc button = null;
233     javax.swing.Action JavaDoc act = null;
234
235     act = new javax.swing.AbstractAction JavaDoc("play", null) {
236       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
237         play();
238       }
239     };
240     playButton = tools.add(act);
241     playButton.setToolTipText("play");
242
243     act = new javax.swing.AbstractAction JavaDoc("pause", null) {
244       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
245         pause();
246       }
247     };
248     pauseButton = tools.add(act);
249     pauseButton.setToolTipText("pause");
250     pauseButton.setEnabled(false);
251
252     act = new javax.swing.AbstractAction JavaDoc("stop", null) {
253       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
254         stop();
255       }
256     };
257     stopButton = tools.add(act);
258     stopButton.setToolTipText("stop");
259     stopButton.setEnabled(false);
260
261     act = new javax.swing.AbstractAction JavaDoc("record", null) {
262       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
263         record();
264       }
265     };
266     recordButton = tools.add(act);
267     recordButton.setToolTipText("record");
268     recordButton.setEnabled(false);
269
270     act = new javax.swing.AbstractAction JavaDoc("clean TimeLine", null) {
271       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
272         eventListsPanel.clearAll();
273       }
274     };
275     button = tools.add(act);
276     button.setToolTipText("clean all the list");
277
278     act = new javax.swing.AbstractAction JavaDoc("Disable Monitoring", null) {
279       public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
280         toggleMonitoring();
281       }
282     };
283     monitoringControlButton = tools.add(act);
284     monitoringControlButton.setToolTipText("Disable the monitoring of events to allow the play back");
285
286     //state = new javax.swing.JLabel("Not Listening");
287
//tools.add(state);
288
}
289 }
290
Popular Tags