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
;
31 private JButton moduleButton
, goButton
, msaEditorButton
, criticButton
, specifyCommentButton
;
32 private JTextField moduletext
;
33 private JTextArea log
;
34 private JFileChooser fc
= new JFileChooser();
35 private JCheckBox filebox
, screenbox
, mibox
, criticbox
, defaultpathbox
;
37 private boolean tofile
= true, toscreen
= true;
38 private PrintWriter logfile
;
41 GridBagLayout gridbag
= new GridBagLayout();
44 GridBagConstraints cst
= new GridBagConstraints();
46 goButton
= new JButton("Go");
47 goButton
.addActionListener(this);
48 goButton
.setActionCommand("go");
50 moduleButton
= new JButton("Choose ModulePath");
51 moduleButton
.addActionListener(this);
53 msaEditorButton
= new JButton("MsaEditor");
54 msaEditorButton
.addActionListener(this);
56 criticButton
= new JButton("Critic");
57 criticButton
.addActionListener(this);
59 specifyCommentButton
= new JButton("Comment Style");
60 specifyCommentButton
.addActionListener(this);
62 moduletext
= new JTextField(30);
64 filebox
= new JCheckBox("Output to logfile", true);
65 filebox
.addItemListener(this);
67 screenbox
= new JCheckBox("Specify logfile", false);
68 screenbox
.addItemListener(this);
70 mibox
= new JCheckBox("Print ModuleInfo", false);
71 mibox
.addItemListener(this);
72 MigrationTool
.printModuleInfo
= false;
74 criticbox
= new JCheckBox("Run Critic", true);
75 criticbox
.addItemListener(this);
76 MigrationTool
.doCritic
= true;
78 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
79 defaultpathbox
.addItemListener(this);
80 MigrationTool
.defaultoutput
= true;
82 JPanel modulePanel
= new JPanel();
83 modulePanel
.add(moduleButton
);
84 modulePanel
.add(moduletext
);
85 modulePanel
.add(goButton
);
86 //modulePanel.add(msaEditorButton);
89 //cst.gridwidth = GridBagConstraints.REMAINDER;
90 gridbag
.setConstraints(modulePanel
, cst
);
95 gridbag
.setConstraints(specifyCommentButton
, cst
);
96 add(specifyCommentButton
);
97 //gridbag.setConstraints(criticButton, cst);
100 JPanel checkboxPanel
= new JPanel();
101 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
102 checkboxPanel
.add(filebox
);
103 checkboxPanel
.add(screenbox
);
104 checkboxPanel
.add(mibox
);
105 checkboxPanel
.add(criticbox
);
106 checkboxPanel
.add(defaultpathbox
);
109 //cst.gridheight = 2;
110 gridbag
.setConstraints(checkboxPanel
, cst
);
113 log
= new JTextArea(10,20);
114 log
.setMargin(new Insets(5,5,5,5));
115 log
.setEditable(false);
116 JScrollPane logScrollPane
= new JScrollPane(log
);
119 cst
.fill
= GridBagConstraints
.BOTH
;
120 gridbag
.setConstraints(logScrollPane
, cst
);
124 //---------------------------------------------------------------------------------------//
126 public boolean yesOrNo(String question
) {
127 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
130 public void print(String message
) {
131 if (toscreen
== true) {
133 System
.out
.print(message
);
135 if (tofile
== true) {
136 logfile
.append(message
);
140 public void println(String message
) {
141 print(message
+ "\n");
144 public void println(Set
<String
> hash
) {
145 if (toscreen
== true) {
146 log
.append(hash
+ "\n");
147 System
.out
.println(hash
);
149 if (tofile
== true) {
150 logfile
.append(hash
+ "\n");
154 public String
choose(String message
, Object
[] choicelist
) {
155 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
158 public String
getInput(String message
) {
159 return (String
)JOptionPane
.showInputDialog(message
);
162 //---------------------------------------------------------------------------------------//
164 public String
getFilepath(String title
, int mode
) {
165 fc
.setDialogTitle(title
);
166 fc
.setFileSelectionMode(mode
);
167 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
168 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
169 return fc
.getSelectedFile().getAbsolutePath();
174 //---------------------------------------------------------------------------------------//
176 public void actionPerformed(ActionEvent e
) {
177 if ( e
.getSource() == moduleButton
) {
178 startpath
= getFilepath("Please choose a starting path", JFileChooser
.DIRECTORIES_ONLY
);
179 moduletext
.setText(startpath
);
181 if ( e
.getSource() == goButton
) {
183 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(startpath
.replaceAll(Common
.strseparate
, "$1") + File
.separator
+ "migration.log")));
184 MigrationTool
.startMigrateAll(startpath
);
186 } catch (Exception en
) {
187 println(en
.getMessage());
190 if ( e
.getSource() == msaEditorButton
) {
192 MsaTreeEditor
.init();
193 } catch (Exception en
) {
194 println(en
.getMessage());
197 if ( e
.getSource() == criticButton
) {
199 Critic
.fireAt(startpath
);
200 } catch (Exception en
) {
201 println(en
.getMessage());
204 if ( e
.getSource() == specifyCommentButton
) {
205 try { // input examine is not imposed but should be added
206 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");
207 //MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
208 } catch (Exception en
) {
209 println(en
.getMessage());
214 public void itemStateChanged(ItemEvent e
) {
215 if (e
.getSource() == filebox
) {
216 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
217 System
.out
.println("filebox DESELECTED");
218 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
219 System
.out
.println("filebox SELECTED");
221 } else if (e
.getSource() == screenbox
) {
222 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
223 System
.out
.println("screenbox DESELECTED");
224 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
225 System
.out
.println("screenbox SELECTED");
227 } else if (e
.getSource() == mibox
) {
228 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
229 MigrationTool
.printModuleInfo
= false;
230 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
231 MigrationTool
.printModuleInfo
= true;
233 } else if (e
.getSource() == criticbox
) {
234 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
235 MigrationTool
.doCritic
= false;
236 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
237 MigrationTool
.doCritic
= true;
239 } else if (e
.getSource() == defaultpathbox
) {
240 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
241 MigrationTool
.defaultoutput
= false;
242 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
243 MigrationTool
.defaultoutput
= true;
248 //---------------------------------------------------------------------------------------//
250 private static final FirstPanel
init() {
252 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
253 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
254 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
255 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
256 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
257 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
258 } catch (Exception e
) {
259 System
.out
.println(e
.getMessage());
262 JFrame frame
= new JFrame("MigrationTools");
263 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
265 FirstPanel fp
= new FirstPanel();
266 //fp.setLayout(new GridBagLayout());
267 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
269 frame
.setContentPane(fp
);
272 frame
.setVisible(true);
277 public static final FirstPanel
getInstance() {