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