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