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);
62 screenbox
= new JCheckBox("Specify logfile", false);
63 screenbox
.addItemListener(this);
64 mibox
= new JCheckBox("Show ModuleInfo", false);
65 mibox
.addItemListener(this);
66 criticbox
= new JCheckBox("Run Critic", true);
67 criticbox
.addItemListener(this);
68 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
69 defaultpathbox
.addItemListener(this);
71 JPanel modulePanel
= new JPanel();
72 modulePanel
.add(moduleButton
);
73 modulePanel
.add(moduletext
);
74 modulePanel
.add(goButton
);
75 //modulePanel.add(msaEditorButton);
78 //cst.gridwidth = GridBagConstraints.REMAINDER;
79 gridbag
.setConstraints(modulePanel
, cst
);
84 gridbag
.setConstraints(criticButton
, cst
);
87 JPanel checkboxPanel
= new JPanel();
88 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
89 checkboxPanel
.add(filebox
);
90 checkboxPanel
.add(screenbox
);
91 checkboxPanel
.add(mibox
);
92 checkboxPanel
.add(criticbox
);
93 checkboxPanel
.add(defaultpathbox
);
97 gridbag
.setConstraints(checkboxPanel
, cst
);
100 log
= new JTextArea(10,20);
101 log
.setMargin(new Insets(5,5,5,5));
102 log
.setEditable(false);
103 JScrollPane logScrollPane
= new JScrollPane(log
);
106 cst
.fill
= GridBagConstraints
.BOTH
;
107 gridbag
.setConstraints(logScrollPane
, cst
);
110 fc
= new JFileChooser();
111 fc
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
114 //---------------------------------------------------------------------------------------//
116 public boolean yesOrNo(String question
) {
117 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
120 public void print(String message
) {
121 if (toscreen
== true) {
123 System
.out
.print(message
);
125 if (tofile
== true) {
126 logfile
.append(message
);
130 public void println(String message
) {
131 print(message
+ "\n");
134 public void println(Set
<String
> hash
) {
135 if (toscreen
== true) {
136 log
.append(hash
+ "\n");
137 System
.out
.println(hash
);
139 if (tofile
== true) {
140 logfile
.append(hash
+ "\n");
144 public String
choose(String message
, Object
[] choicelist
) {
145 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
148 public String
getInput(String message
) {
149 return (String
)JOptionPane
.showInputDialog(message
);
152 //---------------------------------------------------------------------------------------//
154 public String
getFilepath() {
155 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
156 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
157 return fc
.getSelectedFile().getAbsolutePath();
162 //---------------------------------------------------------------------------------------//
164 public void actionPerformed(ActionEvent e
) {
165 if ( e
.getSource() == moduleButton
) {
166 modulepath
= getFilepath();
168 if ( e
.getSource() == goButton
) {
170 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "migration.log")));
171 ModuleInfo
.triger(modulepath
);
173 } catch (Exception en
) {
174 println(en
.getMessage());
177 if ( e
.getSource() == msaEditorButton
) {
179 MsaTreeEditor
.init(mi
, this);
180 } catch (Exception en
) {
181 println(en
.getMessage());
184 if ( e
.getSource() == criticButton
) {
186 Critic
.fireAt(modulepath
);
187 } catch (Exception en
) {
188 println(en
.getMessage());
193 public void itemStateChanged(ItemEvent e
) {
194 if (e
.getSource() == filebox
) {
195 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
196 System
.out
.println("filebox DESELECTED");
197 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
198 System
.out
.println("filebox SELECTED");
200 } else if (e
.getSource() == screenbox
) {
201 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
202 System
.out
.println("screenbox DESELECTED");
203 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
204 System
.out
.println("screenbox SELECTED");
206 } else if (e
.getSource() == mibox
) {
207 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
208 System
.out
.println("mibox DESELECTED");
209 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
210 System
.out
.println("mibox SELECTED");
212 } else if (e
.getSource() == criticbox
) {
213 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
214 System
.out
.println("criticbox DESELECTED");
215 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
216 System
.out
.println("criticbox SELECTED");
218 } else if (e
.getSource() == defaultpathbox
) {
219 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
220 System
.out
.println("defaultpathbox DESELECTED");
221 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
222 System
.out
.println("defaultpathbox SELECTED");
227 //---------------------------------------------------------------------------------------//
229 public static FirstPanel
init() throws Exception
{
231 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
232 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
233 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
234 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
235 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
236 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
238 JFrame frame
= new JFrame("MigrationTools");
239 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
241 FirstPanel fp
= new FirstPanel();
242 //fp.setLayout(new GridBagLayout());
243 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
245 frame
.setContentPane(fp
);
248 frame
.setVisible(true);