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 static final FirstPanel INSTANCE
= FirstPanel
.init();
29 private String startpath
;
30 private ModuleInfo mi
;
32 private JButton moduleButton
, goButton
, msaEditorButton
, criticButton
;
33 private JTextField moduletext
;
34 private JTextArea log
;
35 private JFileChooser fc
;
36 private JCheckBox filebox
, screenbox
, mibox
, criticbox
, defaultpathbox
;
38 private boolean tofile
= true, toscreen
= true;
39 private PrintWriter logfile
;
42 GridBagLayout gridbag
= new GridBagLayout();
45 GridBagConstraints cst
= new GridBagConstraints();
47 goButton
= new JButton("Go");
48 goButton
.addActionListener(this);
49 goButton
.setActionCommand("go");
51 moduleButton
= new JButton("Choose ModulePath");
52 moduleButton
.addActionListener(this);
54 msaEditorButton
= new JButton("MsaEditor");
55 msaEditorButton
.addActionListener(this);
57 criticButton
= new JButton("Critic");
58 criticButton
.addActionListener(this);
60 moduletext
= new JTextField(30);
62 filebox
= new JCheckBox("Output to logfile", true);
63 filebox
.addItemListener(this);
65 screenbox
= new JCheckBox("Specify logfile", false);
66 screenbox
.addItemListener(this);
68 mibox
= new JCheckBox("Print ModuleInfo", false);
69 mibox
.addItemListener(this);
70 MigrationTool
.printModuleInfo
= false;
72 criticbox
= new JCheckBox("Run Critic", true);
73 criticbox
.addItemListener(this);
74 MigrationTool
.doCritic
= true;
76 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
77 defaultpathbox
.addItemListener(this);
78 MigrationTool
.defaultoutput
= true;
80 JPanel modulePanel
= new JPanel();
81 modulePanel
.add(moduleButton
);
82 modulePanel
.add(moduletext
);
83 modulePanel
.add(goButton
);
84 //modulePanel.add(msaEditorButton);
87 //cst.gridwidth = GridBagConstraints.REMAINDER;
88 gridbag
.setConstraints(modulePanel
, cst
);
93 gridbag
.setConstraints(criticButton
, cst
);
96 JPanel checkboxPanel
= new JPanel();
97 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
98 checkboxPanel
.add(filebox
);
99 checkboxPanel
.add(screenbox
);
100 checkboxPanel
.add(mibox
);
101 checkboxPanel
.add(criticbox
);
102 checkboxPanel
.add(defaultpathbox
);
105 //cst.gridheight = 2;
106 gridbag
.setConstraints(checkboxPanel
, cst
);
109 log
= new JTextArea(10,20);
110 log
.setMargin(new Insets(5,5,5,5));
111 log
.setEditable(false);
112 JScrollPane logScrollPane
= new JScrollPane(log
);
115 cst
.fill
= GridBagConstraints
.BOTH
;
116 gridbag
.setConstraints(logScrollPane
, cst
);
119 fc
= new JFileChooser();
120 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
123 //---------------------------------------------------------------------------------------//
125 public boolean yesOrNo(String question
) {
126 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
129 public void print(String message
) {
130 if (toscreen
== true) {
132 System
.out
.print(message
);
134 if (tofile
== true) {
135 logfile
.append(message
);
139 public void println(String message
) {
140 print(message
+ "\n");
143 public void println(Set
<String
> hash
) {
144 if (toscreen
== true) {
145 log
.append(hash
+ "\n");
146 System
.out
.println(hash
);
148 if (tofile
== true) {
149 logfile
.append(hash
+ "\n");
153 public String
choose(String message
, Object
[] choicelist
) {
154 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
157 public String
getInput(String message
) {
158 return (String
)JOptionPane
.showInputDialog(message
);
161 //---------------------------------------------------------------------------------------//
163 public String
getFilepath(String title
) {
164 fc
.setDialogTitle(title
);
165 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
166 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
167 return fc
.getSelectedFile().getAbsolutePath();
172 //---------------------------------------------------------------------------------------//
174 public void actionPerformed(ActionEvent e
) {
175 if ( e
.getSource() == moduleButton
) {
176 startpath
= getFilepath("Please choose a starting path");
177 moduletext
.setText(startpath
);
179 if ( e
.getSource() == goButton
) {
181 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(startpath
.replaceAll(Common
.strseparate
, "$1") + File
.separator
+ "migration.log")));
182 MigrationTool
.triger(startpath
);
184 } catch (Exception en
) {
185 println(en
.getMessage());
188 if ( e
.getSource() == msaEditorButton
) {
190 MsaTreeEditor
.init(mi
, this);
191 } catch (Exception en
) {
192 println(en
.getMessage());
195 if ( e
.getSource() == criticButton
) {
197 Critic
.fireAt(startpath
);
198 } catch (Exception en
) {
199 println(en
.getMessage());
204 public void itemStateChanged(ItemEvent e
) {
205 if (e
.getSource() == filebox
) {
206 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
207 System
.out
.println("filebox DESELECTED");
208 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
209 System
.out
.println("filebox SELECTED");
211 } else if (e
.getSource() == screenbox
) {
212 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
213 System
.out
.println("screenbox DESELECTED");
214 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
215 System
.out
.println("screenbox SELECTED");
217 } else if (e
.getSource() == mibox
) {
218 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
219 MigrationTool
.printModuleInfo
= false;
220 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
221 MigrationTool
.printModuleInfo
= true;
223 } else if (e
.getSource() == criticbox
) {
224 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
225 MigrationTool
.doCritic
= false;
226 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
227 MigrationTool
.doCritic
= true;
229 } else if (e
.getSource() == defaultpathbox
) {
230 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
231 MigrationTool
.defaultoutput
= false;
232 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
233 MigrationTool
.defaultoutput
= true;
238 //---------------------------------------------------------------------------------------//
240 private static final FirstPanel
init() {
242 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
243 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
244 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
245 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
246 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
247 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
248 } catch (Exception e
) {
249 System
.out
.println(e
.getMessage());
252 JFrame frame
= new JFrame("MigrationTools");
253 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
255 FirstPanel fp
= new FirstPanel();
256 //fp.setLayout(new GridBagLayout());
257 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
259 frame
.setContentPane(fp
);
262 frame
.setVisible(true);
267 public static final FirstPanel
getInstance() {