]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
enhance ModuleReader
[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
27 private String modulepath;\r
90503bad 28 private ModuleInfo mi;\r
0dc8c589 29 \r
fed802b1 30 private JButton moduleButton, goButton, msaEditorButton, criticButton;\r
0dc8c589 31 private JTextField moduletext;\r
32 private JTextArea log;\r
33 private JFileChooser fc;\r
778d35c9 34 private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r
0dc8c589 35 \r
36 private boolean tofile = true, toscreen = true;\r
37 private PrintWriter logfile;\r
38\r
39 FirstPanel() throws Exception {\r
778d35c9 40 GridBagLayout gridbag = new GridBagLayout();\r
41 setLayout(gridbag);\r
42 \r
43 GridBagConstraints cst = new GridBagConstraints();\r
44 \r
0dc8c589 45 goButton = new JButton("Go");\r
46 goButton.addActionListener(this);\r
47 goButton.setActionCommand("go");\r
48 \r
49 moduleButton = new JButton("Choose ModulePath");\r
50 moduleButton.addActionListener(this);\r
51\r
90503bad 52 msaEditorButton = new JButton("MsaEditor");\r
53 msaEditorButton.addActionListener(this);\r
54 \r
fed802b1 55 criticButton = new JButton("Critic");\r
56 criticButton.addActionListener(this);\r
57 \r
0dc8c589 58 moduletext = new JTextField(30);\r
59 \r
60 filebox = new JCheckBox("Output to logfile", true);\r
778d35c9 61 filebox.addItemListener(this);\r
446e26ee 62 \r
0dc8c589 63 screenbox = new JCheckBox("Specify logfile", false);\r
778d35c9 64 screenbox.addItemListener(this);\r
446e26ee 65 \r
66 mibox = new JCheckBox("Print ModuleInfo", false);\r
778d35c9 67 mibox.addItemListener(this);\r
446e26ee 68 MigrationTool.printModuleInfo = false;\r
69 \r
778d35c9 70 criticbox = new JCheckBox("Run Critic", true);\r
71 criticbox.addItemListener(this);\r
446e26ee 72 MigrationTool.doCritic = true;\r
73 \r
778d35c9 74 defaultpathbox = new JCheckBox("Use Default Output Path", true);\r
75 defaultpathbox.addItemListener(this);\r
0dc8c589 76 \r
77 JPanel modulePanel = new JPanel();\r
78 modulePanel.add(moduleButton);\r
79 modulePanel.add(moduletext);\r
0dc8c589 80 modulePanel.add(goButton);\r
5ea254f6 81 //modulePanel.add(msaEditorButton);\r
778d35c9 82 cst.gridx = 0;\r
83 cst.gridy = 0;\r
84 //cst.gridwidth = GridBagConstraints.REMAINDER;\r
85 gridbag.setConstraints(modulePanel, cst);\r
0dc8c589 86 add(modulePanel);\r
87\r
778d35c9 88 cst.gridx = 1;\r
89 cst.gridy = 0;\r
90 gridbag.setConstraints(criticButton, cst);\r
91 add(criticButton);\r
92 \r
93 JPanel checkboxPanel = new JPanel();\r
94 checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r
95 checkboxPanel.add(filebox);\r
96 checkboxPanel.add(screenbox);\r
97 checkboxPanel.add(mibox);\r
98 checkboxPanel.add(criticbox);\r
99 checkboxPanel.add(defaultpathbox);\r
100 cst.gridx = 1;\r
101 cst.gridy = 1;\r
102 //cst.gridheight = 2;\r
103 gridbag.setConstraints(checkboxPanel, cst);\r
104 add(checkboxPanel);\r
105 \r
106 log = new JTextArea(10,20);\r
0dc8c589 107 log.setMargin(new Insets(5,5,5,5));\r
108 log.setEditable(false);\r
109 JScrollPane logScrollPane = new JScrollPane(log);\r
778d35c9 110 cst.gridx = 0;\r
111 cst.gridy = 1;\r
112 cst.fill = GridBagConstraints.BOTH;\r
113 gridbag.setConstraints(logScrollPane, cst);\r
0dc8c589 114 add(logScrollPane);\r
115 \r
116 fc = new JFileChooser();\r
117 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r
118 }\r
119 \r
120 //---------------------------------------------------------------------------------------//\r
121 \r
122 public boolean yesOrNo(String question) {\r
123 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
124 }\r
125 \r
126 public void print(String message) {\r
127 if (toscreen == true) {\r
128 log.append(message);\r
129 System.out.print(message);\r
130 }\r
131 if (tofile == true) {\r
132 logfile.append(message);\r
133 }\r
134 }\r
135 \r
136 public void println(String message) {\r
137 print(message + "\n");\r
138 }\r
139\r
140 public void println(Set<String> hash) {\r
141 if (toscreen == true) {\r
142 log.append(hash + "\n");\r
143 System.out.println(hash);\r
144 }\r
145 if (tofile == true) {\r
146 logfile.append(hash + "\n");\r
147 }\r
148 }\r
149\r
e6a5df3b 150 public String choose(String message, Object[] choicelist) {\r
151 return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r
152 }\r
0dc8c589 153 \r
90503bad 154 public String getInput(String message) {\r
155 return (String)JOptionPane.showInputDialog(message);\r
0dc8c589 156 }\r
90503bad 157\r
158 //---------------------------------------------------------------------------------------//\r
159\r
5ea254f6 160 public String getFilepath() {\r
161 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r
162 log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r
163 return fc.getSelectedFile().getAbsolutePath();\r
164 }\r
165 return null;\r
166 }\r
167\r
168 //---------------------------------------------------------------------------------------//\r
169\r
0dc8c589 170 public void actionPerformed(ActionEvent e) {\r
171 if ( e.getSource() == moduleButton ) {\r
5ea254f6 172 modulepath = getFilepath();\r
0dc8c589 173 }\r
174 if ( e.getSource() == goButton ) {\r
175 try {\r
176 logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
7bcb8d17 177 ModuleInfo.triger(modulepath);\r
0dc8c589 178 logfile.flush();\r
179 } catch (Exception en) {\r
180 println(en.getMessage());\r
181 }\r
182 }\r
90503bad 183 if ( e.getSource() == msaEditorButton) {\r
184 try {\r
185 MsaTreeEditor.init(mi, this);\r
186 } catch (Exception en) {\r
187 println(en.getMessage());\r
188 }\r
189 }\r
fed802b1 190 if ( e.getSource() == criticButton) {\r
191 try {\r
192 Critic.fireAt(modulepath);\r
193 } catch (Exception en) {\r
194 println(en.getMessage());\r
195 }\r
196 }\r
0dc8c589 197 }\r
198 \r
199 public void itemStateChanged(ItemEvent e) {\r
778d35c9 200 if (e.getSource() == filebox) {\r
201 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
202 System.out.println("filebox DESELECTED");\r
203 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
204 System.out.println("filebox SELECTED");\r
205 }\r
206 } else if (e.getSource() == screenbox) {\r
207 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
208 System.out.println("screenbox DESELECTED");\r
209 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
210 System.out.println("screenbox SELECTED");\r
211 }\r
212 } else if (e.getSource() == mibox) {\r
213 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
446e26ee 214 MigrationTool.printModuleInfo = false;\r
778d35c9 215 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
446e26ee 216 MigrationTool.printModuleInfo = true;\r
778d35c9 217 }\r
218 } else if (e.getSource() == criticbox) {\r
219 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
446e26ee 220 MigrationTool.doCritic = false;\r
778d35c9 221 System.out.println("criticbox DESELECTED");\r
222 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
446e26ee 223 MigrationTool.doCritic = true;\r
778d35c9 224 System.out.println("criticbox SELECTED");\r
225 }\r
226 } else if (e.getSource() == defaultpathbox) {\r
227 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
228 System.out.println("defaultpathbox DESELECTED");\r
229 } else if (e.getStateChange() == ItemEvent.SELECTED) {\r
230 System.out.println("defaultpathbox SELECTED");\r
231 }\r
0dc8c589 232 }\r
233 }\r
234\r
235 //---------------------------------------------------------------------------------------//\r
236 \r
5ea254f6 237 public static FirstPanel init() throws Exception {\r
b48e3710 238 \r
239 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r
240 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
241 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");\r
242 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");\r
243 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");\r
244 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");\r
245 \r
246 JFrame frame = new JFrame("MigrationTools");\r
0dc8c589 247 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
248\r
249 FirstPanel fp = new FirstPanel();\r
778d35c9 250 //fp.setLayout(new GridBagLayout());\r
251 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r
0dc8c589 252 fp.setOpaque(true);\r
253 frame.setContentPane(fp);\r
254\r
90503bad 255 frame.pack();\r
0dc8c589 256 frame.setVisible(true);\r
5ea254f6 257 \r
258 return fp;\r
0dc8c589 259 }\r
260}