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
;
15 import java
.awt
.GridBagConstraints
;
16 import java
.awt
.GridBagLayout
;
17 import java
.awt
.Insets
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.awt
.event
.ActionListener
;
20 import java
.awt
.event
.ItemEvent
;
21 import java
.awt
.event
.ItemListener
;
22 import java
.io
.BufferedWriter
;
24 import java
.io
.FileWriter
;
25 import java
.io
.PrintWriter
;
28 import javax
.swing
.BoxLayout
;
29 import javax
.swing
.JButton
;
30 import javax
.swing
.JCheckBox
;
31 import javax
.swing
.JFileChooser
;
32 import javax
.swing
.JFrame
;
33 import javax
.swing
.JOptionPane
;
34 import javax
.swing
.JPanel
;
35 import javax
.swing
.JScrollPane
;
36 import javax
.swing
.JTextArea
;
37 import javax
.swing
.JTextField
;
38 import javax
.swing
.UIManager
;
40 public final class FirstPanel
extends JPanel
implements ActionListener
,
43 * Define class Serial Version UID
45 private static final long serialVersionUID
= 207759413522910399L;
47 private static final FirstPanel INSTANCE
= FirstPanel
.init();
49 private String startpath
= null;
51 private JButton moduleButton
, goButton
, msaEditorButton
, criticButton
,
54 private JTextField moduletext
;
56 private JTextArea log
;
58 private JFileChooser fc
= new JFileChooser();
60 private JCheckBox filebox
, screenbox
, mibox
, criticbox
, defaultpathbox
;
62 private boolean tofile
= true, toscreen
= true;
64 private PrintWriter logfile
;
67 GridBagLayout gridbag
= new GridBagLayout();
70 GridBagConstraints cst
= new GridBagConstraints();
72 goButton
= new JButton("Go");
73 goButton
.addActionListener(this);
74 goButton
.setActionCommand("go");
76 moduleButton
= new JButton("Choose ModulePath");
77 moduleButton
.addActionListener(this);
79 msaEditorButton
= new JButton("MsaEditor");
80 msaEditorButton
.addActionListener(this);
82 criticButton
= new JButton("Critic");
83 criticButton
.addActionListener(this);
85 specifyCommentButton
= new JButton("Comment Style");
86 specifyCommentButton
.addActionListener(this);
88 moduletext
= new JTextField(30);
90 filebox
= new JCheckBox("Output to logfile", true);
91 filebox
.addItemListener(this);
93 screenbox
= new JCheckBox("Specify logfile", false);
94 screenbox
.addItemListener(this);
96 mibox
= new JCheckBox("Print ModuleInfo", false);
97 mibox
.addItemListener(this);
98 MigrationTool
.printModuleInfo
= false;
100 criticbox
= new JCheckBox("Run Critic", true);
101 criticbox
.addItemListener(this);
102 MigrationTool
.doCritic
= true;
104 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
105 defaultpathbox
.addItemListener(this);
106 MigrationTool
.defaultoutput
= true;
108 JPanel modulePanel
= new JPanel();
109 modulePanel
.add(moduleButton
);
110 modulePanel
.add(moduletext
);
111 modulePanel
.add(goButton
);
112 // modulePanel.add(msaEditorButton);
115 // cst.gridwidth = GridBagConstraints.REMAINDER;
116 gridbag
.setConstraints(modulePanel
, cst
);
121 gridbag
.setConstraints(specifyCommentButton
, cst
);
122 add(specifyCommentButton
);
123 // gridbag.setConstraints(criticButton, cst);
124 // add(criticButton);
126 JPanel checkboxPanel
= new JPanel();
127 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
128 checkboxPanel
.add(filebox
);
129 checkboxPanel
.add(screenbox
);
130 checkboxPanel
.add(mibox
);
131 checkboxPanel
.add(criticbox
);
132 checkboxPanel
.add(defaultpathbox
);
135 // cst.gridheight = 2;
136 gridbag
.setConstraints(checkboxPanel
, cst
);
139 log
= new JTextArea(10, 20);
140 log
.setMargin(new Insets(5, 5, 5, 5));
141 log
.setEditable(false);
142 JScrollPane logScrollPane
= new JScrollPane(log
);
145 cst
.fill
= GridBagConstraints
.BOTH
;
146 gridbag
.setConstraints(logScrollPane
, cst
);
150 // ---------------------------------------------------------------------------------------//
152 public boolean yesOrNo(String question
) {
153 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No",
154 JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
157 public void print(String message
) {
158 if (toscreen
== true) {
160 System
.out
.print(message
);
162 if (tofile
== true) {
163 logfile
.append(message
);
167 public void println(String message
) {
168 print(message
+ "\n");
171 public void println(Set
<String
> hash
) {
172 if (toscreen
== true) {
173 log
.append(hash
+ "\n");
174 System
.out
.println(hash
);
176 if (tofile
== true) {
177 logfile
.append(hash
+ "\n");
181 public String
choose(String message
, Object
[] choicelist
) {
182 return (String
) JOptionPane
.showInputDialog(this, message
, "Choose",
183 JOptionPane
.PLAIN_MESSAGE
, null, choicelist
, choicelist
[0]);
186 public String
getInput(String message
) {
187 return (String
) JOptionPane
.showInputDialog(message
);
190 // ---------------------------------------------------------------------------------------//
192 public String
getFilepath(String title
, int mode
) {
193 fc
.setDialogTitle(title
);
194 fc
.setFileSelectionMode(mode
);
195 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
196 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
197 return fc
.getSelectedFile().getAbsolutePath();
202 // ---------------------------------------------------------------------------------------//
204 public void actionPerformed(ActionEvent e
) {
205 if (e
.getSource() == moduleButton
) {
206 startpath
= getFilepath("Please choose a starting path",
207 JFileChooser
.DIRECTORIES_ONLY
);
208 moduletext
.setText(startpath
);
210 if (e
.getSource() == goButton
) {
212 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(
213 startpath
.replaceAll(Common
.STRSEPARATER
, "$1")
214 + File
.separator
+ "migration.log")));
215 MigrationTool
.startMigrateAll(startpath
);
218 } catch (Exception en
) {
219 println(en
.getMessage());
222 if (e
.getSource() == msaEditorButton
) {
224 MsaTreeEditor
.init();
225 } catch (Exception en
) {
226 println(en
.getMessage());
229 if (e
.getSource() == criticButton
) {
231 Critic
.fireAt(startpath
);
232 } catch (Exception en
) {
233 println(en
.getMessage());
236 if (e
.getSource() == specifyCommentButton
) {
237 try { // input examine is not imposed but should be added
238 MigrationTool
.MIGRATIONCOMMENT
= getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
239 // MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
240 } catch (Exception en
) {
241 println(en
.getMessage());
246 public void itemStateChanged(ItemEvent e
) {
247 if (e
.getSource() == filebox
) {
248 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
249 System
.out
.println("filebox DESELECTED");
250 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
251 System
.out
.println("filebox SELECTED");
253 } else if (e
.getSource() == screenbox
) {
254 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
255 System
.out
.println("screenbox DESELECTED");
256 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
257 System
.out
.println("screenbox SELECTED");
259 } else if (e
.getSource() == mibox
) {
260 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
261 MigrationTool
.printModuleInfo
= false;
262 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
263 MigrationTool
.printModuleInfo
= true;
265 } else if (e
.getSource() == criticbox
) {
266 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
267 MigrationTool
.doCritic
= false;
268 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
269 MigrationTool
.doCritic
= true;
271 } else if (e
.getSource() == defaultpathbox
) {
272 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
273 MigrationTool
.defaultoutput
= false;
274 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
275 MigrationTool
.defaultoutput
= true;
280 // ---------------------------------------------------------------------------------------//
282 private static final FirstPanel
init() {
284 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
285 } catch (Exception e
) {
286 System
.out
.println(e
.getMessage());
289 JFrame frame
= new JFrame("MigrationTools");
290 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
292 FirstPanel fp
= new FirstPanel();
294 frame
.setContentPane(fp
);
297 frame
.setVisible(true);
302 public static final FirstPanel
getInstance() {