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