1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/** @file
Copyright (c) 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
package org.tianocore.migration;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public final class FirstPanel extends JPanel implements ActionListener, ItemListener, UI {
/**
* Define class Serial Version UID
*/
private static final long serialVersionUID = 207759413522910399L;
private String startpath;
private ModuleInfo mi;
private JButton moduleButton, goButton, msaEditorButton, criticButton;
private JTextField moduletext;
private JTextArea log;
private JFileChooser fc;
private JCheckBox filebox, screenbox, mibox, criticbox, defaultpathbox;
private boolean tofile = true, toscreen = true;
private PrintWriter logfile;
FirstPanel() throws Exception {
GridBagLayout gridbag = new GridBagLayout();
setLayout(gridbag);
GridBagConstraints cst = new GridBagConstraints();
goButton = new JButton("Go");
goButton.addActionListener(this);
goButton.setActionCommand("go");
moduleButton = new JButton("Choose ModulePath");
moduleButton.addActionListener(this);
msaEditorButton = new JButton("MsaEditor");
msaEditorButton.addActionListener(this);
criticButton = new JButton("Critic");
criticButton.addActionListener(this);
moduletext = new JTextField(30);
filebox = new JCheckBox("Output to logfile", true);
filebox.addItemListener(this);
screenbox = new JCheckBox("Specify logfile", false);
screenbox.addItemListener(this);
mibox = new JCheckBox("Print ModuleInfo", false);
mibox.addItemListener(this);
MigrationTool.printModuleInfo = false;
criticbox = new JCheckBox("Run Critic", true);
criticbox.addItemListener(this);
MigrationTool.doCritic = true;
defaultpathbox = new JCheckBox("Use Default Output Path", true);
defaultpathbox.addItemListener(this);
MigrationTool.defaultoutput = true;
JPanel modulePanel = new JPanel();
modulePanel.add(moduleButton);
modulePanel.add(moduletext);
modulePanel.add(goButton);
//modulePanel.add(msaEditorButton);
cst.gridx = 0;
cst.gridy = 0;
//cst.gridwidth = GridBagConstraints.REMAINDER;
gridbag.setConstraints(modulePanel, cst);
add(modulePanel);
cst.gridx = 1;
cst.gridy = 0;
gridbag.setConstraints(criticButton, cst);
//add(criticButton);
JPanel checkboxPanel = new JPanel();
checkboxPanel.setLayout(new BoxLayout(checkboxPanel, BoxLayout.Y_AXIS));
checkboxPanel.add(filebox);
checkboxPanel.add(screenbox);
checkboxPanel.add(mibox);
checkboxPanel.add(criticbox);
checkboxPanel.add(defaultpathbox);
cst.gridx = 1;
cst.gridy = 1;
//cst.gridheight = 2;
gridbag.setConstraints(checkboxPanel, cst);
add(checkboxPanel);
log = new JTextArea(10,20);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(log);
cst.gridx = 0;
cst.gridy = 1;
cst.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(logScrollPane, cst);
add(logScrollPane);
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
//---------------------------------------------------------------------------------------//
public boolean yesOrNo(String question) {
return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}
public void print(String message) {
if (toscreen == true) {
log.append(message);
System.out.print(message);
}
if (tofile == true) {
logfile.append(message);
}
}
public void println(String message) {
print(message + "\n");
}
public void println(Set<String> hash) {
if (toscreen == true) {
log.append(hash + "\n");
System.out.println(hash);
}
if (tofile == true) {
logfile.append(hash + "\n");
}
}
public String choose(String message, Object[] choicelist) {
return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
}
public String getInput(String message) {
return (String)JOptionPane.showInputDialog(message);
}
//---------------------------------------------------------------------------------------//
public String getFilepath(String title) {
fc.setDialogTitle(title);
if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
return fc.getSelectedFile().getAbsolutePath();
}
return null;
}
//---------------------------------------------------------------------------------------//
public void actionPerformed(ActionEvent e) {
if ( e.getSource() == moduleButton ) {
startpath = getFilepath("Please choose a starting path");
moduletext.setText(startpath);
}
if ( e.getSource() == goButton ) {
try {
logfile = new PrintWriter(new BufferedWriter(new FileWriter(startpath.replaceAll(Common.strseparate, "$1") + File.separator + "migration.log")));
MigrationTool.triger(startpath);
logfile.flush();
} catch (Exception en) {
println(en.getMessage());
}
}
if ( e.getSource() == msaEditorButton) {
try {
MsaTreeEditor.init(mi, this);
} catch (Exception en) {
println(en.getMessage());
}
}
if ( e.getSource() == criticButton) {
try {
Critic.fireAt(startpath);
} catch (Exception en) {
println(en.getMessage());
}
}
}
public void itemStateChanged(ItemEvent e) {
if (e.getSource() == filebox) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
System.out.println("filebox DESELECTED");
} else if (e.getStateChange() == ItemEvent.SELECTED) {
System.out.println("filebox SELECTED");
}
} else if (e.getSource() == screenbox) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
System.out.println("screenbox DESELECTED");
} else if (e.getStateChange() == ItemEvent.SELECTED) {
System.out.println("screenbox SELECTED");
}
} else if (e.getSource() == mibox) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
MigrationTool.printModuleInfo = false;
} else if (e.getStateChange() == ItemEvent.SELECTED) {
MigrationTool.printModuleInfo = true;
}
} else if (e.getSource() == criticbox) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
MigrationTool.doCritic = false;
} else if (e.getStateChange() == ItemEvent.SELECTED) {
MigrationTool.doCritic = true;
}
} else if (e.getSource() == defaultpathbox) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
MigrationTool.defaultoutput = false;
} else if (e.getStateChange() == ItemEvent.SELECTED) {
MigrationTool.defaultoutput = true;
}
}
}
//---------------------------------------------------------------------------------------//
public static FirstPanel init() throws Exception {
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
JFrame frame = new JFrame("MigrationTools");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FirstPanel fp = new FirstPanel();
//fp.setLayout(new GridBagLayout());
//fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
fp.setOpaque(true);
frame.setContentPane(fp);
frame.pack();
frame.setVisible(true);
return fp;
}
}
|