1 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 { 39 40 private boolean record = false; 41 private boolean play = false; 42 private boolean pause = false; 43 private javax.swing.JLabel state; 44 private javax.swing.JLabel msg; 45 46 private javax.swing.JButton monitoringControlButton; 47 private javax.swing.JButton playButton; 48 private javax.swing.JButton pauseButton; 49 private javax.swing.JButton stopButton; 50 private javax.swing.JButton recordButton; 51 private javax.swing.JProgressBar eventReplayProgressBar; 52 53 private javax.swing.JPanel tpb; 54 private javax.swing.JLabel 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 (400, 200)); 63 this.eventListsPanel = eventListsPanel; 64 this.dataObjectController = dataObjectController; 65 final javax.swing.JButton b1 = new javax.swing.JButton ("On"); 66 final javax.swing.JButton b2 = new javax.swing.JButton ("Off"); 67 final javax.swing.JButton b3 = new javax.swing.JButton ("Reset"); 68 b2.setEnabled(false); 69 70 javax.swing.JPanel c = new javax.swing.JPanel (); 71 c.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); 72 c.setLayout(new java.awt.GridLayout (0, 1)); 73 74 javax.swing.JToolBar tools = new javax.swing.JToolBar (); 75 c.add(tools); 76 77 javax.swing.JPanel t = new javax.swing.JPanel (); 78 t.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT)); 79 javax.swing.JLabel s = new javax.swing.JLabel (); 80 s.setForeground(java.awt.Color.black); 81 s.setText("Status : "); 82 t.add(s); 83 state = new javax.swing.JLabel ("Freezed"); 84 t.add(state); 85 c.add(t); 86 87 tpb = new javax.swing.JPanel (); 88 tpb.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT)); 89 javax.swing.JLabel s3 = new javax.swing.JLabel (); 90 s3.setForeground(java.awt.Color.black); 91 s3.setText("Playing status : "); 92 tpb.add(s3); 93 eventReplayProgressBar = new javax.swing.JProgressBar (0, 10); 94 eventReplayProgressBar.setMaximumSize(new java.awt.Dimension (70, 25)); 95 eventReplayProgressBar.setStringPainted(true); 96 tpb.add(eventReplayProgressBar); 97 c.add(tpb); 98 99 javax.swing.JPanel t1 = new javax.swing.JPanel (); 100 t1.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.LEFT)); 101 javax.swing.JLabel s1 = new javax.swing.JLabel (); 102 s1.setForeground(java.awt.Color.black); 103 s1.setText("Recorded messages count : "); 104 t1.add(s1); 105 msg = new javax.swing.JLabel (" 0 "); 106 t1.add(msg); 107 108 b1.addActionListener(new java.awt.event.ActionListener () { 109 public void actionPerformed(java.awt.event.ActionEvent e) { 110 b1.setEnabled(false); 111 b2.setEnabled(true); 112 } 113 }); 114 b2.addActionListener(new java.awt.event.ActionListener () { 115 public void actionPerformed(java.awt.event.ActionEvent e) { 116 b2.setEnabled(false); 117 b1.setEnabled(true); 118 } 119 }); 120 b3.addActionListener(new java.awt.event.ActionListener () { 121 public void actionPerformed(java.awt.event.ActionEvent e) { 122 } 123 }); 124 125 c.add(t1); 126 setContentPane(c); 127 addWindowListener(new java.awt.event.WindowAdapter () { 129 public void windowClosing(java.awt.event.WindowEvent 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 tools) { 232 javax.swing.JButton button = null; 233 javax.swing.Action act = null; 234 235 act = new javax.swing.AbstractAction ("play", null) { 236 public void actionPerformed(java.awt.event.ActionEvent e) { 237 play(); 238 } 239 }; 240 playButton = tools.add(act); 241 playButton.setToolTipText("play"); 242 243 act = new javax.swing.AbstractAction ("pause", null) { 244 public void actionPerformed(java.awt.event.ActionEvent 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 ("stop", null) { 253 public void actionPerformed(java.awt.event.ActionEvent 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 ("record", null) { 262 public void actionPerformed(java.awt.event.ActionEvent 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 ("clean TimeLine", null) { 271 public void actionPerformed(java.awt.event.ActionEvent 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 ("Disable Monitoring", null) { 279 public void actionPerformed(java.awt.event.ActionEvent 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 } 289 } 290 | Popular Tags |