3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.migration
;
16 import java
.awt
.event
.*;
21 public final class FirstPanel
extends JPanel
implements ActionListener
, ItemListener
, UI
{
23 * Define class Serial Version UID
25 private static final long serialVersionUID
= 207759413522910399L;
27 private String modulepath
;
28 private ModuleInfo mi
;
30 private JButton moduleButton
, goButton
, msaEditorButton
, criticButton
;
31 private JTextField moduletext
;
32 private JTextArea log
;
33 private JFileChooser fc
;
34 private JCheckBox filebox
, screenbox
, mibox
, criticbox
, defaultpathbox
;
36 private boolean tofile
= true, toscreen
= true;
37 private PrintWriter logfile
;
39 FirstPanel() throws Exception
{
40 GridBagLayout gridbag
= new GridBagLayout();
43 GridBagConstraints cst
= new GridBagConstraints();
45 goButton
= new JButton("Go");
46 goButton
.addActionListener(this);
47 goButton
.setActionCommand("go");
49 moduleButton
= new JButton("Choose ModulePath");
50 moduleButton
.addActionListener(this);
52 msaEditorButton
= new JButton("MsaEditor");
53 msaEditorButton
.addActionListener(this);
55 criticButton
= new JButton("Critic");
56 criticButton
.addActionListener(this);
58 moduletext
= new JTextField(30);
60 filebox
= new JCheckBox("Output to logfile", true);
61 filebox
.addItemListener(this);
63 screenbox
= new JCheckBox("Specify logfile", false);
64 screenbox
.addItemListener(this);
66 mibox
= new JCheckBox("Print ModuleInfo", false);
67 mibox
.addItemListener(this);
68 ModuleInfo
.printModuleInfo
= false;
70 criticbox
= new JCheckBox("Run Critic", true);
71 criticbox
.addItemListener(this);
72 ModuleInfo
.doCritic
= true;
74 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
75 defaultpathbox
.addItemListener(this);
76 ModuleInfo
.defaultoutput
= true;
78 JPanel modulePanel
= new JPanel();
79 modulePanel
.add(moduleButton
);
80 modulePanel
.add(moduletext
);
81 modulePanel
.add(goButton
);
82 //modulePanel.add(msaEditorButton);
85 //cst.gridwidth = GridBagConstraints.REMAINDER;
86 gridbag
.setConstraints(modulePanel
, cst
);
91 gridbag
.setConstraints(criticButton
, cst
);
94 JPanel checkboxPanel
= new JPanel();
95 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
96 checkboxPanel
.add(filebox
);
97 checkboxPanel
.add(screenbox
);
98 checkboxPanel
.add(mibox
);
99 checkboxPanel
.add(criticbox
);
100 checkboxPanel
.add(defaultpathbox
);
103 //cst.gridheight = 2;
104 gridbag
.setConstraints(checkboxPanel
, cst
);
107 log
= new JTextArea(10,20);
108 log
.setMargin(new Insets(5,5,5,5));
109 log
.setEditable(false);
110 JScrollPane logScrollPane
= new JScrollPane(log
);
113 cst
.fill
= GridBagConstraints
.BOTH
;
114 gridbag
.setConstraints(logScrollPane
, cst
);
117 fc
= new JFileChooser();
118 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
121 //---------------------------------------------------------------------------------------//
123 public boolean yesOrNo(String question
) {
124 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
127 public void print(String message
) {
128 if (toscreen
== true) {
130 System
.out
.print(message
);
132 if (tofile
== true) {
133 logfile
.append(message
);
137 public void println(String message
) {
138 print(message
+ "\n");
141 public void println(Set
<String
> hash
) {
142 if (toscreen
== true) {
143 log
.append(hash
+ "\n");
144 System
.out
.println(hash
);
146 if (tofile
== true) {
147 logfile
.append(hash
+ "\n");
151 public String
choose(String message
, Object
[] choicelist
) {
152 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
155 public String
getInput(String message
) {
156 return (String
)JOptionPane
.showInputDialog(message
);
159 //---------------------------------------------------------------------------------------//
161 public String
getFilepath(String title
) {
162 fc
.setDialogTitle(title
);
163 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
164 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
165 return fc
.getSelectedFile().getAbsolutePath();
170 //---------------------------------------------------------------------------------------//
172 public void actionPerformed(ActionEvent e
) {
173 if ( e
.getSource() == moduleButton
) {
174 modulepath
= getFilepath("Please choose a starting path");
175 moduletext
.setText(modulepath
);
177 if ( e
.getSource() == goButton
) {
179 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "migration.log")));
180 ModuleInfo
.triger(modulepath
);
182 } catch (Exception en
) {
183 println(en
.getMessage());
186 if ( e
.getSource() == msaEditorButton
) {
188 MsaTreeEditor
.init(mi
, this);
189 } catch (Exception en
) {
190 println(en
.getMessage());
193 if ( e
.getSource() == criticButton
) {
195 Critic
.fireAt(modulepath
);
196 } catch (Exception en
) {
197 println(en
.getMessage());
202 public void itemStateChanged(ItemEvent e
) {
203 if (e
.getSource() == filebox
) {
204 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
205 System
.out
.println("filebox DESELECTED");
206 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
207 System
.out
.println("filebox SELECTED");
209 } else if (e
.getSource() == screenbox
) {
210 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
211 System
.out
.println("screenbox DESELECTED");
212 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
213 System
.out
.println("screenbox SELECTED");
215 } else if (e
.getSource() == mibox
) {
216 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
217 ModuleInfo
.printModuleInfo
= false;
218 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
219 ModuleInfo
.printModuleInfo
= true;
221 } else if (e
.getSource() == criticbox
) {
222 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
223 ModuleInfo
.doCritic
= false;
224 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
225 ModuleInfo
.doCritic
= true;
227 } else if (e
.getSource() == defaultpathbox
) {
228 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
229 ModuleInfo
.defaultoutput
= false;
230 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
231 ModuleInfo
.defaultoutput
= true;
236 //---------------------------------------------------------------------------------------//
238 public static FirstPanel
init() throws Exception
{
240 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
241 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
242 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
243 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
244 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
245 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
247 JFrame frame
= new JFrame("MigrationTools");
248 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
250 FirstPanel fp
= new FirstPanel();
251 //fp.setLayout(new GridBagLayout());
252 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
254 frame
.setContentPane(fp
);
257 frame
.setVisible(true);