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