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