add MigrationTool
[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 startpath;
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 MigrationTool.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(String title) {
162 fc.setDialogTitle(title);
163 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
164 log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
165 return fc.getSelectedFile().getAbsolutePath();
166 }
167 return null;
168 }
169
170 //---------------------------------------------------------------------------------------//
171
172 public void actionPerformed(ActionEvent e) {
173 if ( e.getSource() == moduleButton ) {
174 startpath = getFilepath("Please choose a starting path");
175 moduletext.setText(startpath);
176 }
177 if ( e.getSource() == goButton ) {
178 try {
179 logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.strseparate, "$1") + File.separator + "migration.log")));
180 MigrationTool.triger(startpath);
181 logfile.flush();
182 } catch (Exception en) {
183 println(en.getMessage());
184 }
185 }
186 if ( e.getSource() == msaEditorButton) {
187 try {
188 MsaTreeEditor.init(mi, this);
189 } catch (Exception en) {
190 println(en.getMessage());
191 }
192 }
193 if ( e.getSource() == criticButton) {
194 try {
195 Critic.fireAt(startpath);
196 } catch (Exception en) {
197 println(en.getMessage());
198 }
199 }
200 }
201
202 public void itemStateChanged(ItemEvent e) {
203 if (e.getSource() == filebox) {
204 if (e.getStateChange() == ItemEvent.DESELECTED) {
205 System.out.println("filebox DESELECTED");
206 } else if (e.getStateChange() == ItemEvent.SELECTED) {
207 System.out.println("filebox SELECTED");
208 }
209 } else if (e.getSource() == screenbox) {
210 if (e.getStateChange() == ItemEvent.DESELECTED) {
211 System.out.println("screenbox DESELECTED");
212 } else if (e.getStateChange() == ItemEvent.SELECTED) {
213 System.out.println("screenbox SELECTED");
214 }
215 } else if (e.getSource() == mibox) {
216 if (e.getStateChange() == ItemEvent.DESELECTED) {
217 MigrationTool.printModuleInfo = false;
218 } else if (e.getStateChange() == ItemEvent.SELECTED) {
219 MigrationTool.printModuleInfo = true;
220 }
221 } else if (e.getSource() == criticbox) {
222 if (e.getStateChange() == ItemEvent.DESELECTED) {
223 MigrationTool.doCritic = false;
224 } else if (e.getStateChange() == ItemEvent.SELECTED) {
225 MigrationTool.doCritic = true;
226 }
227 } else if (e.getSource() == defaultpathbox) {
228 if (e.getStateChange() == ItemEvent.DESELECTED) {
229 MigrationTool.defaultoutput = false;
230 } else if (e.getStateChange() == ItemEvent.SELECTED) {
231 MigrationTool.defaultoutput = true;
232 }
233 }
234 }
235
236 //---------------------------------------------------------------------------------------//
237
238 public static FirstPanel init() throws Exception {
239
240 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
241 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
242 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
243 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
244 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
245 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
246
247 JFrame frame = new JFrame("MigrationTools");
248 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
249
250 FirstPanel fp = new FirstPanel();
251 //fp.setLayout(new GridBagLayout());
252 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
253 fp.setOpaque(true);
254 frame.setContentPane(fp);
255
256 frame.pack();
257 frame.setVisible(true);
258
259 return fp;
260 }
261 }