]>
Commit | Line | Data |
---|---|---|
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 | 13 | package org.tianocore.migration;\r |
14 | \r | |
71f30e51 | 15 | import java.awt.GridBagConstraints;\r |
16 | import java.awt.GridBagLayout;\r | |
17 | import java.awt.Insets;\r | |
18 | import java.awt.event.ActionEvent;\r | |
19 | import java.awt.event.ActionListener;\r | |
20 | import java.awt.event.ItemEvent;\r | |
21 | import java.awt.event.ItemListener;\r | |
22 | import java.io.BufferedWriter;\r | |
23 | import java.io.File;\r | |
24 | import java.io.FileWriter;\r | |
25 | import java.io.PrintWriter;\r | |
26 | import java.util.Set;\r | |
27 | \r | |
28 | import javax.swing.BoxLayout;\r | |
29 | import javax.swing.JButton;\r | |
30 | import javax.swing.JCheckBox;\r | |
31 | import javax.swing.JFileChooser;\r | |
32 | import javax.swing.JFrame;\r | |
33 | import javax.swing.JOptionPane;\r | |
34 | import javax.swing.JPanel;\r | |
35 | import javax.swing.JScrollPane;\r | |
36 | import javax.swing.JTextArea;\r | |
37 | import javax.swing.JTextField;\r | |
38 | import javax.swing.UIManager;\r | |
39 | \r | |
40 | public final class FirstPanel extends JPanel implements ActionListener,\r | |
41 | ItemListener, UI {\r | |
42 | /**\r | |
43 | * Define class Serial Version UID\r | |
44 | */\r | |
45 | private static final long serialVersionUID = 207759413522910399L;\r | |
46 | \r | |
47 | private static final FirstPanel INSTANCE = FirstPanel.init();\r | |
48 | \r | |
49 | private String startpath = null;\r | |
50 | \r | |
51 | private JButton moduleButton, goButton, msaEditorButton, criticButton,\r | |
52 | specifyCommentButton;\r | |
53 | \r | |
54 | private JTextField moduletext;\r | |
55 | \r | |
56 | private JTextArea log;\r | |
57 | \r | |
58 | private JFileChooser fc = new JFileChooser();\r | |
59 | \r | |
60 | private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r | |
61 | \r | |
62 | private boolean tofile = true, toscreen = true;\r | |
63 | \r | |
64 | private PrintWriter logfile;\r | |
65 | \r | |
66 | FirstPanel() {\r | |
67 | GridBagLayout gridbag = new GridBagLayout();\r | |
68 | setLayout(gridbag);\r | |
69 | \r | |
70 | GridBagConstraints cst = new GridBagConstraints();\r | |
71 | \r | |
72 | goButton = new JButton("Go");\r | |
73 | goButton.addActionListener(this);\r | |
74 | goButton.setActionCommand("go");\r | |
75 | \r | |
76 | moduleButton = new JButton("Choose ModulePath");\r | |
77 | moduleButton.addActionListener(this);\r | |
78 | \r | |
79 | msaEditorButton = new JButton("MsaEditor");\r | |
80 | msaEditorButton.addActionListener(this);\r | |
81 | \r | |
82 | criticButton = new JButton("Critic");\r | |
83 | criticButton.addActionListener(this);\r | |
84 | \r | |
85 | specifyCommentButton = new JButton("Comment Style");\r | |
86 | specifyCommentButton.addActionListener(this);\r | |
87 | \r | |
88 | moduletext = new JTextField(30);\r | |
89 | \r | |
90 | filebox = new JCheckBox("Output to logfile", true);\r | |
91 | filebox.addItemListener(this);\r | |
92 | \r | |
93 | screenbox = new JCheckBox("Specify logfile", false);\r | |
94 | screenbox.addItemListener(this);\r | |
95 | \r | |
96 | mibox = new JCheckBox("Print ModuleInfo", false);\r | |
97 | mibox.addItemListener(this);\r | |
98 | MigrationTool.printModuleInfo = false;\r | |
99 | \r | |
100 | criticbox = new JCheckBox("Run Critic", true);\r | |
101 | criticbox.addItemListener(this);\r | |
102 | MigrationTool.doCritic = true;\r | |
103 | \r | |
104 | defaultpathbox = new JCheckBox("Use Default Output Path", true);\r | |
105 | defaultpathbox.addItemListener(this);\r | |
106 | MigrationTool.defaultoutput = true;\r | |
107 | \r | |
108 | JPanel modulePanel = new JPanel();\r | |
109 | modulePanel.add(moduleButton);\r | |
110 | modulePanel.add(moduletext);\r | |
111 | modulePanel.add(goButton);\r | |
112 | // modulePanel.add(msaEditorButton);\r | |
113 | cst.gridx = 0;\r | |
114 | cst.gridy = 0;\r | |
115 | // cst.gridwidth = GridBagConstraints.REMAINDER;\r | |
116 | gridbag.setConstraints(modulePanel, cst);\r | |
117 | add(modulePanel);\r | |
118 | \r | |
119 | cst.gridx = 1;\r | |
120 | cst.gridy = 0;\r | |
121 | gridbag.setConstraints(specifyCommentButton, cst);\r | |
122 | add(specifyCommentButton);\r | |
123 | // gridbag.setConstraints(criticButton, cst);\r | |
124 | // add(criticButton);\r | |
125 | \r | |
126 | JPanel checkboxPanel = new JPanel();\r | |
127 | checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));\r | |
128 | checkboxPanel.add(filebox);\r | |
129 | checkboxPanel.add(screenbox);\r | |
130 | checkboxPanel.add(mibox);\r | |
131 | checkboxPanel.add(criticbox);\r | |
132 | checkboxPanel.add(defaultpathbox);\r | |
133 | cst.gridx = 1;\r | |
134 | cst.gridy = 1;\r | |
135 | // cst.gridheight = 2;\r | |
136 | gridbag.setConstraints(checkboxPanel, cst);\r | |
137 | add(checkboxPanel);\r | |
138 | \r | |
139 | log = new JTextArea(10, 20);\r | |
140 | log.setMargin(new Insets(5, 5, 5, 5));\r | |
141 | log.setEditable(false);\r | |
142 | JScrollPane logScrollPane = new JScrollPane(log);\r | |
143 | cst.gridx = 0;\r | |
144 | cst.gridy = 1;\r | |
145 | cst.fill = GridBagConstraints.BOTH;\r | |
146 | gridbag.setConstraints(logScrollPane, cst);\r | |
147 | add(logScrollPane);\r | |
148 | }\r | |
149 | \r | |
150 | // ---------------------------------------------------------------------------------------//\r | |
151 | \r | |
152 | public boolean yesOrNo(String question) {\r | |
153 | return JOptionPane.showConfirmDialog(this, question, "Yes or No",\r | |
154 | JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r | |
155 | }\r | |
156 | \r | |
157 | public void print(String message) {\r | |
158 | if (toscreen == true) {\r | |
159 | log.append(message);\r | |
160 | System.out.print(message);\r | |
161 | }\r | |
162 | if (tofile == true) {\r | |
163 | logfile.append(message);\r | |
164 | }\r | |
165 | }\r | |
166 | \r | |
167 | public void println(String message) {\r | |
168 | print(message + "\n");\r | |
169 | }\r | |
170 | \r | |
171 | public void println(Set<String> hash) {\r | |
172 | if (toscreen == true) {\r | |
173 | log.append(hash + "\n");\r | |
174 | System.out.println(hash);\r | |
175 | }\r | |
176 | if (tofile == true) {\r | |
177 | logfile.append(hash + "\n");\r | |
178 | }\r | |
179 | }\r | |
180 | \r | |
181 | public String choose(String message, Object[] choicelist) {\r | |
182 | return (String) JOptionPane.showInputDialog(this, message, "Choose",\r | |
183 | JOptionPane.PLAIN_MESSAGE, null, choicelist, choicelist[0]);\r | |
184 | }\r | |
185 | \r | |
186 | public String getInput(String message) {\r | |
187 | return (String) JOptionPane.showInputDialog(message);\r | |
188 | }\r | |
189 | \r | |
190 | // ---------------------------------------------------------------------------------------//\r | |
191 | \r | |
192 | public String getFilepath(String title, int mode) {\r | |
193 | fc.setDialogTitle(title);\r | |
194 | fc.setFileSelectionMode(mode);\r | |
195 | if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r | |
196 | log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r | |
197 | return fc.getSelectedFile().getAbsolutePath();\r | |
198 | }\r | |
199 | return null;\r | |
200 | }\r | |
201 | \r | |
202 | // ---------------------------------------------------------------------------------------//\r | |
203 | \r | |
204 | public void actionPerformed(ActionEvent e) {\r | |
205 | if (e.getSource() == moduleButton) {\r | |
206 | startpath = getFilepath("Please choose a starting path",\r | |
207 | JFileChooser.DIRECTORIES_ONLY);\r | |
208 | moduletext.setText(startpath);\r | |
209 | }\r | |
210 | if (e.getSource() == goButton) {\r | |
211 | try {\r | |
212 | logfile = new PrintWriter(new BufferedWriter(new FileWriter(\r | |
213 | startpath.replaceAll(Common.STRSEPARATER, "$1")\r | |
214 | + File.separator + "migration.log")));\r | |
215 | MigrationTool.startMigrateAll(startpath);\r | |
216 | logfile.flush();\r | |
217 | logfile.close();\r | |
218 | } catch (Exception en) {\r | |
219 | println(en.getMessage());\r | |
220 | }\r | |
221 | }\r | |
222 | if (e.getSource() == msaEditorButton) {\r | |
223 | try {\r | |
224 | MsaTreeEditor.init();\r | |
225 | } catch (Exception en) {\r | |
226 | println(en.getMessage());\r | |
227 | }\r | |
228 | }\r | |
229 | if (e.getSource() == criticButton) {\r | |
230 | try {\r | |
231 | Critic.fireAt(startpath);\r | |
232 | } catch (Exception en) {\r | |
233 | println(en.getMessage());\r | |
234 | }\r | |
235 | }\r | |
236 | if (e.getSource() == specifyCommentButton) {\r | |
237 | try { // input examine is not imposed but should be added\r | |
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");\r | |
239 | // MsaWriter.parse("C:\\tianocore\\edk2\\MdePkg\\Library\\BaseLib\\BaseLib.msa");\r | |
240 | } catch (Exception en) {\r | |
241 | println(en.getMessage());\r | |
242 | }\r | |
243 | }\r | |
244 | }\r | |
245 | \r | |
246 | public void itemStateChanged(ItemEvent e) {\r | |
247 | if (e.getSource() == filebox) {\r | |
248 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
249 | System.out.println("filebox DESELECTED");\r | |
250 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
251 | System.out.println("filebox SELECTED");\r | |
252 | }\r | |
253 | } else if (e.getSource() == screenbox) {\r | |
254 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
255 | System.out.println("screenbox DESELECTED");\r | |
256 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
257 | System.out.println("screenbox SELECTED");\r | |
258 | }\r | |
259 | } else if (e.getSource() == mibox) {\r | |
260 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
261 | MigrationTool.printModuleInfo = false;\r | |
262 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
263 | MigrationTool.printModuleInfo = true;\r | |
264 | }\r | |
265 | } else if (e.getSource() == criticbox) {\r | |
266 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
267 | MigrationTool.doCritic = false;\r | |
268 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
269 | MigrationTool.doCritic = true;\r | |
270 | }\r | |
271 | } else if (e.getSource() == defaultpathbox) {\r | |
272 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
273 | MigrationTool.defaultoutput = false;\r | |
274 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
275 | MigrationTool.defaultoutput = true;\r | |
276 | }\r | |
277 | }\r | |
278 | }\r | |
279 | \r | |
280 | // ---------------------------------------------------------------------------------------//\r | |
281 | \r | |
282 | private static final FirstPanel init() {\r | |
283 | try {\r | |
284 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r | |
285 | } catch (Exception e) {\r | |
286 | System.out.println(e.getMessage());\r | |
287 | }\r | |
288 | \r | |
289 | JFrame frame = new JFrame("MigrationTools");\r | |
290 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r | |
291 | \r | |
292 | FirstPanel fp = new FirstPanel();\r | |
293 | fp.setOpaque(true);\r | |
294 | frame.setContentPane(fp);\r | |
295 | \r | |
296 | frame.pack();\r | |
297 | frame.setVisible(true);\r | |
298 | \r | |
299 | return fp;\r | |
300 | }\r | |
301 | \r | |
302 | public static final FirstPanel getInstance() {\r | |
303 | return INSTANCE;\r | |
304 | }\r | |
0dc8c589 | 305 | } |