KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > analyser > lib > gui > GuiPanelAnalyser


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2003 France Telecom R&D
4 * Copyright (C) 2003 INRIA
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * CLIF $Name: $
21 *
22 * Contact: clif@objectweb.org
23 */

24
25
26 /**
27  * Implementation of a graphic user interface for Manual Analyser
28  *
29  * @author Damien Croizer
30 */

31
32 package org.objectweb.clif.analyser.lib.gui;
33
34 import java.awt.GridBagConstraints JavaDoc;
35 import java.awt.GridBagLayout JavaDoc;
36 import java.awt.GridLayout JavaDoc;
37 import java.awt.event.ActionEvent JavaDoc;
38 import java.awt.event.ActionListener JavaDoc;
39
40 import javax.swing.JButton JavaDoc;
41 import javax.swing.JComboBox JavaDoc;
42 import javax.swing.JLabel JavaDoc;
43 import javax.swing.JPanel JavaDoc;
44 import javax.swing.JScrollPane JavaDoc;
45 import javax.swing.JSplitPane JavaDoc;
46 import javax.swing.JTable JavaDoc;
47 import javax.swing.JTree JavaDoc;
48 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
49 import javax.swing.event.*;
50
51 import javax.swing.tree.*;
52 import javax.swing.JTextField JavaDoc;
53 import javax.swing.JFrame JavaDoc;
54 import ptolemy.plot.Plot;
55 import javax.swing.Timer JavaDoc;
56 import javax.swing.event.TableModelEvent JavaDoc;
57 import javax.swing.event.TableModelListener JavaDoc;
58 import org.objectweb.clif.analyser.Analyser;
59 import org.objectweb.clif.analyser.View;
60 import org.objectweb.clif.analyser.lib.gui.GuiPanelOutput;
61 import java.util.StringTokenizer JavaDoc;
62
63
64 public class GuiPanelAnalyser extends JPanel JavaDoc implements ActionListener JavaDoc, TreeSelectionListener{
65     
66     private Analyser a;
67     private JFrame JavaDoc frame = new JFrame JavaDoc();
68
69     private JTextField JavaDoc nameField = new JTextField JavaDoc(20);
70     private JTextField JavaDoc testIdField = new JTextField JavaDoc(20);
71     private JComboBox JavaDoc testCombo = null;
72     private JComboBox JavaDoc paramXCombo = null;
73     private JComboBox JavaDoc paramYCombo = null;
74     private JComboBox JavaDoc bladeCombo = null;
75     private JComboBox JavaDoc fonctionCombo = null;
76
77
78     private JTextField JavaDoc machineField = new JTextField JavaDoc(20);
79     private JTextField JavaDoc threadField = new JTextField JavaDoc(20);
80     private JTextField JavaDoc intervalField = new JTextField JavaDoc(20);
81
82     private JButton JavaDoc creerButton = new JButton JavaDoc("Create view");
83     private JButton JavaDoc updateButton = new JButton JavaDoc("Update Test Tree");
84     private JButton JavaDoc optionButton = new JButton JavaDoc("Options");
85
86
87     private JLabel JavaDoc nameLabel = new JLabel JavaDoc("View name");
88     private JLabel JavaDoc testIdLabel = new JLabel JavaDoc("Test name");
89     private JLabel JavaDoc paramXLabel = new JLabel JavaDoc("X axis param");
90     private JLabel JavaDoc paramYLabel = new JLabel JavaDoc("Y axis param");
91     private JLabel JavaDoc machineLabel = new JLabel JavaDoc("Blade name");
92     private JLabel JavaDoc threadLabel = new JLabel JavaDoc("V. client number");
93     private JLabel JavaDoc intervalLabel = new JLabel JavaDoc("Time interval");
94
95     private JPanel JavaDoc panelDroite = new JPanel JavaDoc();
96     private JPanel JavaDoc panelGauche = new JPanel JavaDoc();
97         private JPanel JavaDoc panelHaut = new JPanel JavaDoc();
98     private JPanel JavaDoc panelBas = new JPanel JavaDoc();
99
100
101     private JTree JavaDoc tree ;
102     private DefaultMutableTreeNode JavaDoc top;
103     private String JavaDoc[][] vues = new String JavaDoc[100][100];
104     GridBagConstraints JavaDoc cTree = new GridBagConstraints JavaDoc();
105
106     private JScrollPane JavaDoc treePane;
107         private JScrollPane JavaDoc graphPane;
108
109     private JSplitPane JavaDoc splitPane = null;
110     private JSplitPane JavaDoc splitPaneGauche = null;
111     private GuiPanelOutput message = new GuiPanelOutput();
112
113
114     /**
115      * The constructor which builds the Manual Analyser graphical interface.
116      *
117      */

118     public GuiPanelAnalyser() {
119
120         a = new Analyser(this);
121         GridBagLayout JavaDoc gbg = new GridBagLayout JavaDoc();
122         GridBagConstraints JavaDoc cg = new GridBagConstraints JavaDoc();
123
124         this.setLayout(new GridLayout JavaDoc(1, 1));
125         panelBas.setLayout(gbg);
126         cg.gridx = 0;
127         cg.gridy = 0;
128         cg.gridheight = 1;
129         cg.gridwidth = 1;
130         cg.weightx = 300;
131         cg.weighty = 300;
132         cg.fill = GridBagConstraints.BOTH;
133         cg.anchor = GridBagConstraints.SOUTH;
134         message.setSize(200, 200);
135         message.setOutputText(" ");
136         panelBas.add(message, cg); // message out put
137

138
139         GraphAnalyser graphpane = new GraphAnalyser();
140         graphPane = new JScrollPane JavaDoc(graphpane.init());
141         panelHaut.add(graphPane);
142
143         splitPaneGauche = new JSplitPane JavaDoc(JSplitPane.VERTICAL_SPLIT, panelHaut,panelBas);
144         splitPaneGauche.setOneTouchExpandable(true);
145         panelGauche.add(splitPaneGauche);
146
147
148         GridBagLayout JavaDoc gb = new GridBagLayout JavaDoc();
149         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
150         
151         testCombo = new JComboBox JavaDoc();
152         paramXCombo = new JComboBox JavaDoc();
153         paramYCombo = new JComboBox JavaDoc();
154         bladeCombo = new JComboBox JavaDoc();
155         fonctionCombo = new JComboBox JavaDoc();
156         fonctionCombo.addItem("Maximum");
157         fonctionCombo.addItem("Minimum");
158         fonctionCombo.addItem("Mean");
159         fonctionCombo.addItem("Standard deviation");
160
161         bladeCombo.setEditable(true);
162         paramYCombo.setEditable(true);
163         paramXCombo.setEditable(true);
164         paramYCombo.setActionCommand("PARAMY");
165         paramYCombo.addActionListener(this);
166         testCombo.setActionCommand("TEST");
167         testCombo.addActionListener(this);
168         paramXCombo.setActionCommand("PARAMX");
169         paramXCombo.addActionListener(this);
170     
171         
172
173         treePane = initTree();
174
175         this.setLayout(new GridLayout JavaDoc(1, 1));
176         panelDroite.setLayout(gb);
177     
178     
179         c.gridx = 0;
180         c.gridy = 0;
181         updateButton.setActionCommand("UPDATE");
182         updateButton.addActionListener(this);
183         panelDroite.add(updateButton, c);
184         c.gridx = 1;
185         c.gridy = 0;
186         fonctionCombo.setActionCommand("FONCTION");
187         fonctionCombo.addActionListener(this);
188         panelDroite.add(fonctionCombo, c);
189
190         cTree.gridx = 0;
191         cTree.gridy = 1;
192         cTree.gridheight = 1;
193         cTree.gridwidth = 2;
194         cTree.weightx = 1;
195         cTree.weighty = 2;
196         cTree.fill = GridBagConstraints.BOTH;
197         cTree.anchor = GridBagConstraints.NORTH;
198         panelDroite.add(treePane, cTree); //treepane
199

200         
201         
202         c.gridx = 0;
203         c.gridy = 3;
204         c.gridheight = 1;
205         c.gridwidth = 1;
206         c.weightx = 0;
207         c.weighty = 0;
208         c.fill = GridBagConstraints.NONE;
209         c.anchor = GridBagConstraints.WEST;
210         panelDroite.add(nameLabel, c);
211         c.gridx = 1;
212         c.gridy = 3;
213         c.gridheight = 1;
214         c.gridwidth = 1;
215         c.weightx = 0;
216         c.weighty = 0;
217         c.fill = GridBagConstraints.NONE;
218         c.anchor = GridBagConstraints.WEST;
219         // The following 3 lines are necessary due to a bug of JTextField size in a GridBagLayout
220
nameField.setSize(nameField.getPreferredSize());
221         nameField.setMinimumSize(nameField.getPreferredSize());
222         nameField.setMaximumSize(nameField.getPreferredSize());
223         panelDroite.add(nameField, c);
224
225         c.gridx = 0;
226         c.gridy = 4;
227         c.gridheight = 1;
228         c.gridwidth = 1;
229         c.weightx = 0;
230         c.weighty = 0;
231         c.fill = GridBagConstraints.NONE;
232         c.anchor = GridBagConstraints.WEST;
233         panelDroite.add(testIdLabel, c);
234         c.gridx = 1;
235         c.gridy = 4;
236         c.gridheight = 1;
237         c.gridwidth = 1;
238         c.weightx = 0;
239         c.weighty = 0;
240         c.fill = GridBagConstraints.NONE;
241         c.anchor = GridBagConstraints.WEST;
242         panelDroite.add(testCombo, c);
243
244         c.gridx = 0;
245         c.gridy = 5;
246         c.gridheight = 1;
247         c.gridwidth = 1;
248         c.weightx = 0;
249         c.weighty = 0;
250         c.fill = GridBagConstraints.NONE;
251         c.anchor = GridBagConstraints.WEST;
252         panelDroite.add(paramXLabel, c);
253         c.gridx = 1;
254         c.gridy = 5;
255         c.gridheight = 1;
256         c.gridwidth = 1;
257         c.weightx = 0;
258         c.weighty = 0;
259         c.fill = GridBagConstraints.NONE;
260         c.anchor = GridBagConstraints.WEST;
261         panelDroite.add(paramXCombo, c);
262         
263         c.gridx = 0;
264         c.gridy = 6;
265         c.gridheight = 1;
266         c.gridwidth = 1;
267         c.weightx = 0;
268         c.weighty = 0;
269         c.fill = GridBagConstraints.NONE;
270         c.anchor = GridBagConstraints.WEST;
271         panelDroite.add(paramYLabel, c);
272         c.gridx = 1;
273         c.gridy = 6;
274         c.gridheight = 1;
275         c.gridwidth = 1;
276         c.weightx = 0;
277         c.weighty = 0;
278         c.fill = GridBagConstraints.NONE;
279         c.anchor = GridBagConstraints.WEST;
280         panelDroite.add(paramYCombo, c);
281         
282         c.gridx = 0;
283         c.gridy = 7;
284         c.gridheight = 1;
285         c.gridwidth = 1;
286         c.weightx = 0;
287         c.weighty = 0;
288         c.fill = GridBagConstraints.NONE;
289         c.anchor = GridBagConstraints.WEST;
290         panelDroite.add(machineLabel, c);
291         c.gridx = 1;
292         c.gridy = 7;
293         c.gridheight = 1;
294         c.gridwidth = 1;
295         c.weightx = 0;
296         c.weighty = 0;
297         c.fill = GridBagConstraints.NONE;
298         c.anchor = GridBagConstraints.WEST;
299         panelDroite.add(bladeCombo, c);
300
301         c.gridx = 0;
302         c.gridy = 8;
303         c.gridheight = 1;
304         c.gridwidth = 1;
305         c.weightx = 0;
306         c.weighty = 0;
307         c.fill = GridBagConstraints.NONE;
308         c.anchor = GridBagConstraints.WEST;
309         panelDroite.add(threadLabel, c);
310         c.gridx = 1;
311         c.gridy = 8;
312         c.gridheight = 1;
313         c.gridwidth = 1;
314         c.weightx = 0;
315         c.weighty = 0;
316         c.fill = GridBagConstraints.NONE;
317         c.anchor = GridBagConstraints.WEST;
318         // The following 3 lines are necessary due to a bug of JTextField size in a GridBagLayout
319
threadField.setSize(threadField.getPreferredSize());
320         threadField.setMinimumSize(threadField.getPreferredSize());
321         threadField.setMaximumSize(threadField.getPreferredSize());
322         panelDroite.add(threadField, c);
323
324         c.gridx = 0;
325         c.gridy = 9;
326         c.gridheight = 1;
327         c.gridwidth = 1;
328         c.weightx = 0;
329         c.weighty = 0;
330         c.fill = GridBagConstraints.NONE;
331         c.anchor = GridBagConstraints.WEST;
332         panelDroite.add(intervalLabel, c);
333         c.gridx = 1;
334         c.gridy = 9;
335         c.gridheight = 1;
336         c.gridwidth = 1;
337         c.weightx = 0;
338         c.weighty = 0;
339         c.fill = GridBagConstraints.NONE;
340         c.anchor = GridBagConstraints.WEST;
341         // The following 3 lines are necessary due to a bug of JTextField size in a GridBagLayout
342
intervalField.setSize(intervalField.getPreferredSize());
343         intervalField.setMinimumSize(intervalField.getPreferredSize());
344         intervalField.setMaximumSize(intervalField.getPreferredSize());
345         panelDroite.add(intervalField, c);
346
347
348         c.gridx = 0;
349         c.gridy = 10;
350         optionButton.setActionCommand("OPTION");
351         optionButton.addActionListener(this);
352         panelDroite.add(optionButton, c);
353         c.gridx = 1;
354         c.gridy = 10;
355         creerButton.setActionCommand("CREER");
356         creerButton.addActionListener(this);
357         panelDroite.add(creerButton, c);
358
359
360
361
362
363
364     
365         splitPane = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT, panelGauche,panelDroite);
366         splitPane.setDividerLocation(600);
367         splitPane.setOneTouchExpandable(true);
368         add(splitPane);
369
370     }
371
372     /**
373      * This method is called each time the user interacts with a button.<br>
374      * Depending on the button clicked, we dispatch the event.
375      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
376      */

377     public void actionPerformed(ActionEvent JavaDoc e) {
378     
379     String JavaDoc command = e.getActionCommand();
380     
381     if (command.equals("CREER"))
382         {
383         GuiInitDialog dlg = new GuiInitDialog(frame,"option");
384         int option = (new Integer JavaDoc(dlg.ask())).intValue();
385         View createView = a.creer(nameField.getText(), testCombo.getSelectedItem().toString(), bladeCombo.getSelectedItem().toString(),new Integer JavaDoc(threadField.getText()).intValue(), paramXCombo.getSelectedItem().toString(), paramYCombo.getSelectedItem().toString(),intervalField.getText(),option);
386         if(createView != null) tracer(createView);
387         else System.out.println("View corrupted...");
388         }
389
390
391     else if (command.equals("UPDATE"))
392         {
393         //testCombo.removeAllItems();
394
a.update();
395         }
396     else if (command.equals("OPTION"))
397         {
398     
399         }
400     else if (command.equals("FONCTION"))
401         {
402 if(fonctionCombo.getSelectedIndex()==0) Analyser.max(testCombo.getSelectedItem().toString(),nameField.getText());
403 else if(fonctionCombo.getSelectedIndex()==1) Analyser.min(testCombo.getSelectedItem().toString(),nameField.getText());
404 else if(fonctionCombo.getSelectedIndex()==2) Analyser.moyenne(testCombo.getSelectedItem().toString(),nameField.getText());
405 else if(fonctionCombo.getSelectedIndex()==3) Analyser.ecart(testCombo.getSelectedItem().toString(),nameField.getText());
406         }
407     else if (command.equals("PARAMY"))
408         {
409
410         }
411     else if (command.equals("PARAMX"))
412         {
413
414         }
415     else if (command.equals("TEST"))
416         {
417         String JavaDoc testId = testCombo.getSelectedItem().toString();
418         String JavaDoc archive = "report/" + testId + "/archive.clif";
419         String JavaDoc parsingResult = org.objectweb.clif.analyser.Analyser.parseArchive(archive);
420         updateTestData(parsingResult);
421         }
422
423     }
424     
425   public void updateTestData(String JavaDoc parsingResult)
426     {
427
428     paramXCombo.removeAllItems();
429     paramYCombo.removeAllItems();
430     bladeCombo.removeAllItems();
431     paramXCombo.addItem("Testing time");
432     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(parsingResult,";");
433     intervalField.setText("0-"+ st.nextToken());
434     threadField.setText("-1");
435     StringTokenizer JavaDoc stblade = new StringTokenizer JavaDoc(st.nextToken(),"|");
436     while(stblade.hasMoreElements()) bladeCombo.addItem(stblade.nextToken());
437     StringTokenizer JavaDoc stparam = new StringTokenizer JavaDoc(st.nextToken(),"|");
438     while(stparam.hasMoreElements()) paramYCombo.addItem(stparam.nextToken());
439     }
440
441     public void addTest(String JavaDoc testId)
442     {
443     testCombo.addItem(testId);
444    }
445
446
447
448     public void tracer(View vue)
449     {
450     panelHaut.remove(graphPane);
451     GraphAnalyser graphpane = new GraphAnalyser();
452     graphPane = new JScrollPane JavaDoc(graphpane.update(vue));
453     panelHaut.add(graphPane);
454     panelHaut.validate();
455     
456     }
457
458
459
460
461     public void setView(View vue)
462     {
463     testIdField.setText(vue.getTestId());
464     nameField.setText(vue.getName());
465     machineField.setText(vue.getNommachine());
466     threadField.setText((String JavaDoc) ("" + vue.getNumthread()+ ""));
467     intervalField.setText((String JavaDoc) (vue.getDatedebut() + "-" + vue.getDatefin())) ;
468     //paramYCombo.setSelectedIndex(vue.getParamY());
469
//paramXCombo.setSelectedIndex(vue.getParamX());
470
message.clearText();
471     message.setOutputText(vue.getResult());
472     }
473
474
475     public String JavaDoc getView()
476     {
477     return nameField.getText();
478     }
479
480     public String JavaDoc getTest()
481     {
482     return testCombo.getSelectedItem().toString();
483     }
484
485     public void valueChanged(TreeSelectionEvent e) {
486     DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) tree.getLastSelectedPathComponent();
487     if (node == null) return;
488     if (node.isLeaf()) {
489         View selectedView = a.wichViewNamed(node.getParent().toString(),node.toString());
490         if(selectedView != null)
491         {
492             setView(selectedView);
493             tracer(selectedView);
494         }
495     }
496     }
497
498    
499      public JScrollPane JavaDoc initTree()
500     {
501     top = new DefaultMutableTreeNode JavaDoc("Existing views");
502     createNodes(top);
503     tree = new JTree JavaDoc(top);
504     tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
505     tree.setShowsRootHandles(true);
506     tree.addTreeSelectionListener(this);
507     return (new JScrollPane JavaDoc(tree));
508     
509     }
510
511     private void createNodes(DefaultMutableTreeNode JavaDoc top) {
512         
513     DefaultMutableTreeNode JavaDoc rep = null;
514     DefaultMutableTreeNode JavaDoc file = null;
515     
516     
517     for(int i = 0 ; vues[i][0] != null ; i++)
518         {
519         rep = new DefaultMutableTreeNode JavaDoc((String JavaDoc) vues[i][0]);
520         top.add(rep);
521         for(int j = 1 ; vues[i][j] != null ; j++)
522             {
523             file = new DefaultMutableTreeNode JavaDoc((String JavaDoc) vues[i][j]);
524             rep.add(file);
525             }
526         }
527     }
528     
529
530
531    public void updateViewTree(String JavaDoc[][] existingviews)
532     {
533
534     for(int i = 0 ; existingviews[i][0] != null ; i++)
535         for(int j = 0 ; existingviews[i][j] != null ; j++)
536         {
537             vues[i][j] = existingviews[i][j] ;
538         }
539     
540     panelDroite.remove(treePane);
541
542     treePane = initTree();
543     // treePane.setSize(100, 50);
544
panelDroite.add(treePane,cTree); //treepane
545
panelDroite.validate();
546     
547     
548     
549     }
550     
551     
552     
553     
554 }
555
Popular Tags