]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
func name changed & modify common.todoall
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / FirstPanel.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13 package org.tianocore.migration;
14
15 import java.awt.*;
16 import java.awt.event.*;
17 import java.io.*;
18 import java.util.*;
19 import javax.swing.*;
20
21 public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {
22 /**
23 * Define class Serial Version UID
24 */
25 private static final long serialVersionUID = 207759413522910399L;
26
27 private static final FirstPanel INSTANCE = FirstPanel.init();
28
29 private String startpath;
30 private ModuleInfo mi;
31
32 private JButton moduleButton, goButton, msaEditorButton, criticButton, specifyCommentButton;
33 private JTextField moduletext;
34 private JTextArea log;
35 private JFileChooser fc;
36 private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
37
38 private boolean tofile = true, toscreen = true;
39 private PrintWriter logfile;
40
41 FirstPanel() {
42 GridBagLayout gridbag = new GridBagLayout();
43 setLayout(gridbag);
44
45 GridBagConstraints cst = new GridBagConstraints();
46
47 goButton = new JButton("Go");
48 goButton.addActionListener(this);
49 goButton.setActionCommand("go");
50
51 moduleButton = new JButton("Choose ModulePath");
52 moduleButton.addActionListener(this);
53
54 msaEditorButton = new JButton("MsaEditor");
55 msaEditorButton.addActionListener(this);
56
57 criticButton = new JButton("Critic");
58 criticButton.addActionListener(this);
59
60 specifyCommentButton = new JButton("Comment Style");
61 specifyCommentButton.addActionListener(this);
62
63 moduletext = new JTextField(30);
64
65 filebox = new JCheckBox("Output to logfile", true);
66 filebox.addItemListener(this);
67
68 screenbox = new JCheckBox("Specify logfile", false);
69 screenbox.addItemListener(this);
70
71 mibox = new JCheckBox("Print ModuleInfo", false);
72 mibox.addItemListener(this);
73 MigrationTool.printModuleInfo = false;
74
75 criticbox = new JCheckBox("Run Critic", true);
76 criticbox.addItemListener(this);
77 MigrationTool.doCritic = true;
78
79 defaultpathbox = new JCheckBox("Use Default Output Path", true);
80 defaultpathbox.addItemListener(this);
81 MigrationTool.defaultoutput = true;
82
83 JPanel modulePanel = new JPanel();
84 modulePanel.add(moduleButton);
85 modulePanel.add(moduletext);
86 modulePanel.add(goButton);
87 //modulePanel.add(msaEditorButton);
88 cst.gridx = 0;
89 cst.gridy = 0;
90 //cst.gridwidth = GridBagConstraints.REMAINDER;
91 gridbag.setConstraints(modulePanel, cst);
92 add(modulePanel);
93
94 cst.gridx = 1;
95 cst.gridy = 0;
96 gridbag.setConstraints(specifyCommentButton, cst);
97 add(specifyCommentButton);
98 //gridbag.setConstraints(criticButton, cst);
99 //add(criticButton);
100
101 JPanel checkboxPanel = new JPanel();
102 checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
103 checkboxPanel.add(filebox);
104 checkboxPanel.add(screenbox);
105 checkboxPanel.add(mibox);
106 checkboxPanel.add(criticbox);
107 checkboxPanel.add(defaultpathbox);
108 cst.gridx = 1;
109 cst.gridy = 1;
110 //cst.gridheight = 2;
111 gridbag.setConstraints(checkboxPanel, cst);
112 add(checkboxPanel);
113
114 log = new JTextArea(10,20);
115 log.setMargin(new Insets(5,5,5,5));
116 log.setEditable(false);
117 JScrollPane logScrollPane = new JScrollPane(log);
118 cst.gridx = 0;
119 cst.gridy = 1;
120 cst.fill = GridBagConstraints.BOTH;
121 gridbag.setConstraints(logScrollPane, cst);
122 add(logScrollPane);
123
124 fc = new JFileChooser();
125 fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
126 }
127
128 //---------------------------------------------------------------------------------------//
129
130 public boolean yesOrNo(String question) {
131 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
132 }
133
134 public void print(String message) {
135 if (toscreen == true) {
136 log.append(message);
137 System.out.print(message);
138 }
139 if (tofile == true) {
140 logfile.append(message);
141 }
142 }
143
144 public void println(String message) {
145 print(message + "\n");
146 }
147
148 public void println(Set<String> hash) {
149 if (toscreen == true) {
150 log.append(hash + "\n");
151 System.out.println(hash);
152 }
153 if (tofile == true) {
154 logfile.append(hash + "\n");
155 }
156 }
157
158 public String choose(String message, Object[] choicelist) {
159 return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
160 }
161
162 public String getInput(String message) {
163 return (String)JOptionPane.showInputDialog(message);
164 }
165
166 //---------------------------------------------------------------------------------------//
167
168 public String getFilepath(String title) {
169 fc.setDialogTitle(title);
170 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
171 log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
172 return fc.getSelectedFile().getAbsolutePath();
173 }
174 return null;
175 }
176
177 //---------------------------------------------------------------------------------------//
178
179 public void actionPerformed(ActionEvent e) {
180 if ( e.getSource() == moduleButton ) {
181 startpath = getFilepath("Please choose a starting path");
182 moduletext.setText(startpath);
183 }
184 if ( e.getSource() == goButton ) {
185 try {
186 logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.strseparate, "$1") + File.separator + "migration.log")));
187 MigrationTool.startMigrateAll(startpath);
188 logfile.flush();
189 } catch (Exception en) {
190 println(en.getMessage());
191 }
192 }
193 if ( e.getSource() == msaEditorButton) {
194 try {
195 MsaTreeEditor.init(mi, this);
196 } catch (Exception en) {
197 println(en.getMessage());
198 }
199 }
200 if ( e.getSource() == criticButton) {
201 try {
202 Critic.fireAt(startpath);
203 } catch (Exception en) {
204 println(en.getMessage());
205 }
206 }
207 if ( e.getSource() == specifyCommentButton) {
208 try { // input examine is not imposed but should be added
209 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");
210 } catch (Exception en) {
211 println(en.getMessage());
212 }
213 }
214 }
215
216 public void itemStateChanged(ItemEvent e) {
217 if (e.getSource() == filebox) {
218 if (e.getStateChange() == ItemEvent.DESELECTED) {
219 System.out.println("filebox DESELECTED");
220 } else if (e.getStateChange() == ItemEvent.SELECTED) {
221 System.out.println("filebox SELECTED");
222 }
223 } else if (e.getSource() == screenbox) {
224 if (e.getStateChange() == ItemEvent.DESELECTED) {
225 System.out.println("screenbox DESELECTED");
226 } else if (e.getStateChange() == ItemEvent.SELECTED) {
227 System.out.println("screenbox SELECTED");
228 }
229 } else if (e.getSource() == mibox) {
230 if (e.getStateChange() == ItemEvent.DESELECTED) {
231 MigrationTool.printModuleInfo = false;
232 } else if (e.getStateChange() == ItemEvent.SELECTED) {
233 MigrationTool.printModuleInfo = true;
234 }
235 } else if (e.getSource() == criticbox) {
236 if (e.getStateChange() == ItemEvent.DESELECTED) {
237 MigrationTool.doCritic = false;
238 } else if (e.getStateChange() == ItemEvent.SELECTED) {
239 MigrationTool.doCritic = true;
240 }
241 } else if (e.getSource() == defaultpathbox) {
242 if (e.getStateChange() == ItemEvent.DESELECTED) {
243 MigrationTool.defaultoutput = false;
244 } else if (e.getStateChange() == ItemEvent.SELECTED) {
245 MigrationTool.defaultoutput = true;
246 }
247 }
248 }
249
250 //---------------------------------------------------------------------------------------//
251
252 private static final FirstPanel init() {
253 try {
254 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
255 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
256 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
257 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
258 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
259 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
260 } catch (Exception e) {
261 System.out.println(e.getMessage());
262 }
263
264 JFrame frame = new JFrame("MigrationTools");
265 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
266
267 FirstPanel fp = new FirstPanel();
268 //fp.setLayout(new GridBagLayout());
269 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
270 fp.setOpaque(true);
271 frame.setContentPane(fp);
272
273 frame.pack();
274 frame.setVisible(true);
275
276 return fp;
277 }
278
279 public static final FirstPanel getInstance() {
280 return INSTANCE;
281 }
282 }