View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2005 Christian W. Hargraves (engrean@hotmail.com)
4   
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon.ui;
20  
21  import java.awt.CardLayout;
22  import java.awt.Dimension;
23  import java.awt.event.ActionEvent;
24  import java.awt.event.ActionListener;
25  import java.awt.event.KeyEvent;
26  import java.io.File;
27  
28  import javax.swing.*;
29  import javax.swing.event.ChangeEvent;
30  import javax.swing.event.ChangeListener;
31  
32  import net.sf.jameleon.launch.JameleonMain;
33  import net.sf.jameleon.util.JameleonUtility;
34  import net.sf.jameleon.util.Configurator;
35  import net.sf.jameleon.util.JameleonDefaultValues;
36  
37  public class JameleonUI extends JFrame implements JameleonMain{
38  	private static final long serialVersionUID = 1L;
39  	protected static final int TREE_TABS_WIDTH = 195;
40  	protected static final int WINDOW_HEIGHT = 450;
41      protected static final int WINDOW_WIDHT = 600;
42      protected String title = "Jameleon";
43  
44      public static void main(String[] args){
45          final JameleonUI ui = new JameleonUI();
46          ui.startJameleon();
47      }
48  
49      public void startJameleon(){
50          SwingUtilities.invokeLater(new Runnable() {
51              public void run() {
52                  genUI();
53              }
54          });
55      }
56  
57      public JameleonUI(){
58          super();
59          setTitle(title);
60          setUpFrame();
61      }
62  
63      public JameleonUI(String title){
64          super(title);
65          this.title = title;
66          setUpFrame();
67      }
68  
69      private void setUpFrame(){
70          setName(title);
71          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
72      }
73  
74      public void genUI(){
75          JameleonTagsPanel jtPanel = new JameleonTagsPanel();
76          final JPanel rightPanels = new JPanel(new CardLayout());
77          final TestCasePane tcPanel = new TestCasePane(this);
78  
79          rightPanels.add(tcPanel, "Test Cases");
80          rightPanels.add(jtPanel, "Function Tags");
81  
82          rightPanels.setPreferredSize(new Dimension(WINDOW_WIDHT, WINDOW_HEIGHT));
83  
84          SpringUtilities.makeCompactGrid(jtPanel,
85                                          7, 2,   //rows, cols
86                                          6, 6,   //initX, initY
87                                          6, 6);  //xPad, yPad
88  
89  
90          final JTabbedPane treeTabs = new JTabbedPane(JTabbedPane.BOTTOM);
91          treeTabs.setPreferredSize(new Dimension(TREE_TABS_WIDTH, WINDOW_HEIGHT));
92  
93          TestCaseTree tct = new TestCaseTree(tcPanel);
94          JScrollPane sp2 = new JScrollPane(tct);
95          treeTabs.addTab("Test Cases", sp2);
96          genMenu(tct);
97  
98          FunctionalPointTree jt = new FunctionalPointTree(jtPanel);
99          JScrollPane sp = new JScrollPane(jt);
100         treeTabs.addTab("Function Tags", sp);
101 
102         treeTabs.addChangeListener(new ChangeListener(){
103                 public void stateChanged(ChangeEvent e) {
104                     String componentName = treeTabs.getTitleAt(treeTabs.getSelectedIndex());
105                     CardLayout rcl = (CardLayout) rightPanels.getLayout();
106                     rcl.show( rightPanels, componentName);
107                 }
108                 });
109 
110         JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeTabs, rightPanels);
111         splitPane.setDividerSize(4);
112         getContentPane().add(splitPane);
113         pack();
114         setVisible(true);
115     }
116 
117     protected void genMenu(final TestCaseTree tct){
118         final JFrame owner =  this;
119         JMenuBar menuBar = new JMenuBar();
120         JMenu tools = new JMenu("Tools");
121         tools.setMnemonic(KeyEvent.VK_T);
122         JMenuItem options = new JMenuItem("Options...", KeyEvent.VK_O);
123         options.addActionListener(new ActionListener(){
124                 public void actionPerformed(ActionEvent e) {
125                     new ConfigDialog(owner);
126                     tct.generateScriptsTree();
127                 }
128                 });
129         tools.add(options);
130         JMenuItem deleteResults = new JMenuItem("Delete Results", KeyEvent.VK_D);
131         final JameleonUI ui = this;
132         deleteResults.addActionListener(new ActionListener(){
133                 public void actionPerformed(ActionEvent e) {
134                     String baseDir = Configurator.getInstance().getValue("baseDir", JameleonDefaultValues.BASE_DIR.getPath());
135                     String resDir = Configurator.getInstance().getValue("resultsDir", JameleonDefaultValues.RESULTS_DIR);
136                     File resDirF = new File(baseDir, resDir);
137                     JameleonUtility.deleteDirStructure(resDirF);
138                     JOptionPane.showMessageDialog(ui, "Results have been deleted");
139 
140                 }
141                 });
142         tools.add(deleteResults);
143         JMenu help = new JMenu("Help");
144         help.setMnemonic(KeyEvent.VK_H);
145         JMenuItem about = new JMenuItem("About", KeyEvent.VK_A);
146         about.addActionListener(new ActionListener(){
147                 public void actionPerformed(ActionEvent e) {
148                     new AboutDialog(owner);
149                 }
150                 });
151         help.add(about);
152         menuBar.add(tools);
153         menuBar.add(help);
154         setJMenuBar(menuBar);
155     }
156 
157 }