]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
21 | public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {\r | |
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 | |
28 | private ModuleInfo mi;\r | |
29 | \r | |
30 | private JButton moduleButton, goButton, msaEditorButton, criticButton;\r | |
31 | private JTextField moduletext;\r | |
32 | private JTextArea log;\r | |
33 | private JFileChooser fc;\r | |
34 | private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;\r | |
35 | \r | |
36 | private boolean tofile = true, toscreen = true;\r | |
37 | private PrintWriter logfile;\r | |
38 | \r | |
39 | FirstPanel() throws Exception {\r | |
40 | GridBagLayout gridbag = new GridBagLayout();\r | |
41 | setLayout(gridbag);\r | |
42 | \r | |
43 | GridBagConstraints cst = new GridBagConstraints();\r | |
44 | \r | |
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 | |
52 | msaEditorButton = new JButton("MsaEditor");\r | |
53 | msaEditorButton.addActionListener(this);\r | |
54 | \r | |
55 | criticButton = new JButton("Critic");\r | |
56 | criticButton.addActionListener(this);\r | |
57 | \r | |
58 | moduletext = new JTextField(30);\r | |
59 | \r | |
60 | filebox = new JCheckBox("Output to logfile", true);\r | |
61 | filebox.addItemListener(this);\r | |
62 | \r | |
63 | screenbox = new JCheckBox("Specify logfile", false);\r | |
64 | screenbox.addItemListener(this);\r | |
65 | \r | |
66 | mibox = new JCheckBox("Print ModuleInfo", false);\r | |
67 | mibox.addItemListener(this);\r | |
68 | ModuleInfo.printModuleInfo = false;\r | |
69 | \r | |
70 | criticbox = new JCheckBox("Run Critic", true);\r | |
71 | criticbox.addItemListener(this);\r | |
72 | ModuleInfo.doCritic = true;\r | |
73 | \r | |
74 | defaultpathbox = new JCheckBox("Use Default Output Path", true);\r | |
75 | defaultpathbox.addItemListener(this);\r | |
76 | \r | |
77 | JPanel modulePanel = new JPanel();\r | |
78 | modulePanel.add(moduleButton);\r | |
79 | modulePanel.add(moduletext);\r | |
80 | modulePanel.add(goButton);\r | |
81 | //modulePanel.add(msaEditorButton);\r | |
82 | cst.gridx = 0;\r | |
83 | cst.gridy = 0;\r | |
84 | //cst.gridwidth = GridBagConstraints.REMAINDER;\r | |
85 | gridbag.setConstraints(modulePanel, cst);\r | |
86 | add(modulePanel);\r | |
87 | \r | |
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 | |
107 | log.setMargin(new Insets(5,5,5,5));\r | |
108 | log.setEditable(false);\r | |
109 | JScrollPane logScrollPane = new JScrollPane(log);\r | |
110 | cst.gridx = 0;\r | |
111 | cst.gridy = 1;\r | |
112 | cst.fill = GridBagConstraints.BOTH;\r | |
113 | gridbag.setConstraints(logScrollPane, cst);\r | |
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 | |
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 | |
153 | \r | |
154 | public String getInput(String message) {\r | |
155 | return (String)JOptionPane.showInputDialog(message);\r | |
156 | }\r | |
157 | \r | |
158 | //---------------------------------------------------------------------------------------//\r | |
159 | \r | |
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 | |
170 | public void actionPerformed(ActionEvent e) {\r | |
171 | if ( e.getSource() == moduleButton ) {\r | |
172 | modulepath = getFilepath();\r | |
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 | |
177 | ModuleInfo.triger(modulepath);\r | |
178 | logfile.flush();\r | |
179 | } catch (Exception en) {\r | |
180 | println(en.getMessage());\r | |
181 | }\r | |
182 | }\r | |
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 | |
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 | |
197 | }\r | |
198 | \r | |
199 | public void itemStateChanged(ItemEvent e) {\r | |
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 | |
214 | ModuleInfo.printModuleInfo = false;\r | |
215 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
216 | ModuleInfo.printModuleInfo = true;\r | |
217 | }\r | |
218 | } else if (e.getSource() == criticbox) {\r | |
219 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
220 | ModuleInfo.doCritic = false;\r | |
221 | System.out.println("criticbox DESELECTED");\r | |
222 | } else if (e.getStateChange() == ItemEvent.SELECTED) {\r | |
223 | ModuleInfo.doCritic = true;\r | |
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 | |
232 | }\r | |
233 | }\r | |
234 | \r | |
235 | //---------------------------------------------------------------------------------------//\r | |
236 | \r | |
237 | public static FirstPanel init() throws Exception {\r | |
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 | |
247 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r | |
248 | \r | |
249 | FirstPanel fp = new FirstPanel();\r | |
250 | //fp.setLayout(new GridBagLayout());\r | |
251 | //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r | |
252 | fp.setOpaque(true);\r | |
253 | frame.setContentPane(fp);\r | |
254 | \r | |
255 | frame.pack();\r | |
256 | frame.setVisible(true);\r | |
257 | \r | |
258 | return fp;\r | |
259 | }\r | |
260 | } |