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