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