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