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
);
187 } catch (Exception en
) {
188 println(en
.getMessage());
191 if ( e
.getSource() == msaEditorButton
) {
193 MsaTreeEditor
.init();
194 } catch (Exception en
) {
195 println(en
.getMessage());
198 if ( e
.getSource() == criticButton
) {
200 Critic
.fireAt(startpath
);
201 } catch (Exception en
) {
202 println(en
.getMessage());
205 if ( e
.getSource() == specifyCommentButton
) {
206 try { // input examine is not imposed but should be added
207 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");
208 //MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");
209 } catch (Exception en
) {
210 println(en
.getMessage());
215 public void itemStateChanged(ItemEvent e
) {
216 if (e
.getSource() == filebox
) {
217 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
218 System
.out
.println("filebox DESELECTED");
219 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
220 System
.out
.println("filebox SELECTED");
222 } else if (e
.getSource() == screenbox
) {
223 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
224 System
.out
.println("screenbox DESELECTED");
225 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
226 System
.out
.println("screenbox SELECTED");
228 } else if (e
.getSource() == mibox
) {
229 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
230 MigrationTool
.printModuleInfo
= false;
231 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
232 MigrationTool
.printModuleInfo
= true;
234 } else if (e
.getSource() == criticbox
) {
235 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
236 MigrationTool
.doCritic
= false;
237 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
238 MigrationTool
.doCritic
= true;
240 } else if (e
.getSource() == defaultpathbox
) {
241 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
242 MigrationTool
.defaultoutput
= false;
243 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
244 MigrationTool
.defaultoutput
= true;
249 //---------------------------------------------------------------------------------------//
251 private static final FirstPanel
init() {
253 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
254 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
255 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
256 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
257 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
258 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
259 } catch (Exception e
) {
260 System
.out
.println(e
.getMessage());
263 JFrame frame
= new JFrame("MigrationTools");
264 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
266 FirstPanel fp
= new FirstPanel();
267 //fp.setLayout(new GridBagLayout());
268 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
270 frame
.setContentPane(fp
);
273 frame
.setVisible(true);
278 public static final FirstPanel
getInstance() {