]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
change boolean PCD value to capital "TRUE" "FALSE".
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / FirstPanel.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.awt.*;\r
16import java.awt.event.*;\r
17import java.io.*;\r
18import java.util.*;\r
19import javax.swing.*;\r
20\r
778d35c9 21public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {\r
0dc8c589 22 /**\r
23 * Define class Serial Version UID\r
24 */\r
25 private static final long serialVersionUID = 207759413522910399L;\r
26 \r
4f60c26f 27 private static final FirstPanel INSTANCE = FirstPanel.init();\r
28 \r
99f70980 29 private String startpath;\r
90503bad 30 private ModuleInfo mi;\r
0dc8c589 31 \r
e3e8956d 32 private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;\r
0dc8c589 33 private JTextField moduletext;\r
34 private JTextArea log;\r
35 private JFileChooser fc;\r
778d35c9 36 private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
0dc8c589 37 \r
38 private boolean tofile = true, toscreen = true;\r
39 private PrintWriter logfile;\r
40\r
4f60c26f 41 FirstPanel() {\r
778d35c9 42 GridBagLayout gridbag = new GridBagLayout();\r
43 setLayout(gridbag);\r
44 \r
45 GridBagConstraints cst = new GridBagConstraints();\r
46 \r
0dc8c589 47 goButton = new JButton("Go");\r
48 goButton.addActionListener(this);\r
49 goButton.setActionCommand("go");\r
50 \r
51 moduleButton = new JButton("Choose ModulePath");\r
52 moduleButton.addActionListener(this);\r
53\r
90503bad 54 msaEditorButton = new JButton("MsaEditor");\r
55 msaEditorButton.addActionListener(this);\r
56 \r
fed802b1 57 criticButton = new JButton("Critic");\r
58 criticButton.addActionListener(this);\r
59 \r
e3e8956d 60 specifyCommentButton = new JButton("Comment Style");\r
61 specifyCommentButton.addActionListener(this);\r
62 \r
0dc8c589 63 moduletext = new JTextField(30);\r
64 \r
65 filebox = new JCheckBox("Output to logfile", true);\r
778d35c9 66 filebox.addItemListener(this);\r
446e26ee 67 \r
0dc8c589 68 screenbox = new JCheckBox("Specify logfile", false);\r
778d35c9 69 screenbox.addItemListener(this);\r
446e26ee 70 \r
71 mibox = new JCheckBox("Print ModuleInfo", false);\r
778d35c9 72 mibox.addItemListener(this);\r
482407d3 73 MigrationTool.printModuleInfo = false;\r
446e26ee 74 \r
778d35c9 75 criticbox = new JCheckBox("Run Critic", true);\r
76 criticbox.addItemListener(this);\r
482407d3 77 MigrationTool.doCritic = true;\r
446e26ee 78 \r
778d35c9 79 defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
80 defaultpathbox.addItemListener(this);\r
482407d3 81 MigrationTool.defaultoutput = true;\r
0dc8c589 82 \r
83 JPanel modulePanel = new JPanel();\r
84 modulePanel.add(moduleButton);\r
85 modulePanel.add(moduletext);\r
0dc8c589 86 modulePanel.add(goButton);\r
5ea254f6 87 //modulePanel.add(msaEditorButton);\r
778d35c9 88 cst.gridx = 0;\r
89 cst.gridy = 0;\r
90 //cst.gridwidth = GridBagConstraints.REMAINDER;\r
91 gridbag.setConstraints(modulePanel, cst);\r
0dc8c589 92 add(modulePanel);\r
93\r
778d35c9 94 cst.gridx = 1;\r
95 cst.gridy = 0;\r
e3e8956d 96 gridbag.setConstraints(specifyCommentButton, cst);\r
97 add(specifyCommentButton);\r
98 //gridbag.setConstraints(criticButton, cst);\r
437ffb07 99 //add(criticButton);\r
778d35c9 100 \r
101 JPanel checkboxPanel = new JPanel();\r
102 checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
103 checkboxPanel.add(filebox);\r
104 checkboxPanel.add(screenbox);\r
105 checkboxPanel.add(mibox);\r
106 checkboxPanel.add(criticbox);\r
107 checkboxPanel.add(defaultpathbox);\r
108 cst.gridx = 1;\r
109 cst.gridy = 1;\r
110 //cst.gridheight = 2;\r
111 gridbag.setConstraints(checkboxPanel, cst);\r
112 add(checkboxPanel);\r
113 \r
114 log = new JTextArea(10,20);\r
0dc8c589 115 log.setMargin(new Insets(5,5,5,5));\r
116 log.setEditable(false);\r
117 JScrollPane logScrollPane = new JScrollPane(log);\r
778d35c9 118 cst.gridx = 0;\r
119 cst.gridy = 1;\r
120 cst.fill = GridBagConstraints.BOTH;\r
121 gridbag.setConstraints(logScrollPane, cst);\r
0dc8c589 122 add(logScrollPane);\r
123 \r
124 fc = new JFileChooser();\r
35d5d932 125 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);\r
126 }\r
0dc8c589 127 \r
128 //---------------------------------------------------------------------------------------//\r
129 \r
130 public boolean yesOrNo(String question) {\r
131 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
132 }\r
133 \r
134 public void print(String message) {\r
135 if (toscreen == true) {\r
136 log.append(message);\r
137 System.out.print(message);\r
138 }\r
139 if (tofile == true) {\r
140 logfile.append(message);\r
141 }\r
142 }\r
143 \r
144 public void println(String message) {\r
145 print(message + "\n");\r
146 }\r
147\r
148 public void println(Set<String> hash) {\r
149 if (toscreen == true) {\r
150 log.append(hash + "\n");\r
151 System.out.println(hash);\r
152 }\r
153 if (tofile == true) {\r
154 logfile.append(hash + "\n");\r
155 }\r
156 }\r
157\r
e6a5df3b 158 public String choose(String message, Object[] choicelist) {\r
159 return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r
160 }\r
0dc8c589 161 \r
90503bad 162 public String getInput(String message) {\r
163 return (String)JOptionPane.showInputDialog(message);\r
0dc8c589 164 }\r
90503bad 165\r
166 //---------------------------------------------------------------------------------------//\r
167\r
821709bd 168 public String getFilepath(String title) {\r
169 fc.setDialogTitle(title);\r
5ea254f6 170 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
171 log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
172 return fc.getSelectedFile().getAbsolutePath();\r
173 }\r
174 return null;\r
175 }\r
176\r
177 //---------------------------------------------------------------------------------------//\r
178\r
0dc8c589 179 public void actionPerformed(ActionEvent e) {\r
180 if ( e.getSource() == moduleButton ) {\r
99f70980 181 startpath = getFilepath("Please choose a starting path");\r
182 moduletext.setText(startpath);\r
0dc8c589 183 }\r
184 if ( e.getSource() == goButton ) {\r
185 try {\r
99f70980 186 logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.strseparate, "$1") + File.separator + "migration.log")));\r
482407d3 187 MigrationTool.triger(startpath);\r
0dc8c589 188 logfile.flush();\r
189 } catch (Exception en) {\r
190 println(en.getMessage());\r
191 }\r
192 }\r
90503bad 193 if ( e.getSource() == msaEditorButton) {\r
194 try {\r
195 MsaTreeEditor.init(mi, this);\r
196 } catch (Exception en) {\r
197 println(en.getMessage());\r
198 }\r
199 }\r
fed802b1 200 if ( e.getSource() == criticButton) {\r
201 try {\r
99f70980 202 Critic.fireAt(startpath);\r
fed802b1 203 } catch (Exception en) {\r
204 println(en.getMessage());\r
205 }\r
206 }\r
e3e8956d 207 if ( e.getSource() == specifyCommentButton) {\r
208 try { // input examine is not imposed but should be added\r
209 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");\r
210 } catch (Exception en) {\r
211 println(en.getMessage());\r
212 }\r
213 }\r
0dc8c589 214 }\r
215 \r
216 public void itemStateChanged(ItemEvent e) {\r
778d35c9 217 if (e.getSource() == filebox) {\r
218 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
219 System.out.println("filebox DESELECTED");\r
220 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
221 System.out.println("filebox SELECTED");\r
222 }\r
223 } else if (e.getSource() == screenbox) {\r
224 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
225 System.out.println("screenbox DESELECTED");\r
226 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
227 System.out.println("screenbox SELECTED");\r
228 }\r
229 } else if (e.getSource() == mibox) {\r
230 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
482407d3 231 MigrationTool.printModuleInfo = false;\r
778d35c9 232 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
482407d3 233 MigrationTool.printModuleInfo = true;\r
778d35c9 234 }\r
235 } else if (e.getSource() == criticbox) {\r
236 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
482407d3 237 MigrationTool.doCritic = false;\r
778d35c9 238 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
482407d3 239 MigrationTool.doCritic = true;\r
778d35c9 240 }\r
241 } else if (e.getSource() == defaultpathbox) {\r
242 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
482407d3 243 MigrationTool.defaultoutput = false;\r
778d35c9 244 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
482407d3 245 MigrationTool.defaultoutput = true;\r
778d35c9 246 }\r
0dc8c589 247 }\r
248 }\r
249\r
250 //---------------------------------------------------------------------------------------//\r
251 \r
4f60c26f 252 private static final FirstPanel init() {\r
253 try {\r
254 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
255 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r
256 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");\r
257 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");\r
258 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");\r
259 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");\r
260 } catch (Exception e) {\r
261 System.out.println(e.getMessage());\r
262 }\r
b48e3710 263 \r
264 JFrame frame = new JFrame("MigrationTools");\r
0dc8c589 265 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
266\r
267 FirstPanel fp = new FirstPanel();\r
778d35c9 268 //fp.setLayout(new GridBagLayout());\r
269 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r
0dc8c589 270 fp.setOpaque(true);\r
271 frame.setContentPane(fp);\r
272\r
90503bad 273 frame.pack();\r
0dc8c589 274 frame.setVisible(true);\r
5ea254f6 275 \r
276 return fp;\r
0dc8c589 277 }\r
4f60c26f 278 \r
279 public static final FirstPanel getInstance() {\r
280 return INSTANCE;\r
281 }\r
0dc8c589 282}