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
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.
13 package org
.tianocore
.migration
;
16 import java
.awt
.event
.*;
21 public final class FirstPanel
extends JPanel
implements ActionListener
, ItemListener
, UI
{
23 * Define class Serial Version UID
25 private static final long serialVersionUID
= 207759413522910399L;
27 private static final FirstPanel INSTANCE
= FirstPanel
.init();
29 private String startpath
;
30 private ModuleInfo mi
;
32 private JButton moduleButton
, goButton
, msaEditorButton
, criticButton
, specifyCommentButton
;
33 private JTextField moduletext
;
34 private JTextArea log
;
35 private JFileChooser fc
;
36 private JCheckBox filebox
, screenbox
, mibox
, criticbox
, defaultpathbox
;
38 private boolean tofile
= true, toscreen
= true;
39 private PrintWriter logfile
;
42 GridBagLayout gridbag
= new GridBagLayout();
45 GridBagConstraints cst
= new GridBagConstraints();
47 goButton
= new JButton("Go");
48 goButton
.addActionListener(this);
49 goButton
.setActionCommand("go");
51 moduleButton
= new JButton("Choose ModulePath");
52 moduleButton
.addActionListener(this);
54 msaEditorButton
= new JButton("MsaEditor");
55 msaEditorButton
.addActionListener(this);
57 criticButton
= new JButton("Critic");
58 criticButton
.addActionListener(this);
60 specifyCommentButton
= new JButton("Comment Style");
61 specifyCommentButton
.addActionListener(this);
63 moduletext
= new JTextField(30);
65 filebox
= new JCheckBox("Output to logfile", true);
66 filebox
.addItemListener(this);
68 screenbox
= new JCheckBox("Specify logfile", false);
69 screenbox
.addItemListener(this);
71 mibox
= new JCheckBox("Print ModuleInfo", false);
72 mibox
.addItemListener(this);
73 MigrationTool
.printModuleInfo
= false;
75 criticbox
= new JCheckBox("Run Critic", true);
76 criticbox
.addItemListener(this);
77 MigrationTool
.doCritic
= true;
79 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
80 defaultpathbox
.addItemListener(this);
81 MigrationTool
.defaultoutput
= true;
83 JPanel modulePanel
= new JPanel();
84 modulePanel
.add(moduleButton
);
85 modulePanel
.add(moduletext
);
86 modulePanel
.add(goButton
);
87 //modulePanel.add(msaEditorButton);
90 //cst.gridwidth = GridBagConstraints.REMAINDER;
91 gridbag
.setConstraints(modulePanel
, cst
);
96 gridbag
.setConstraints(specifyCommentButton
, cst
);
97 add(specifyCommentButton
);
98 //gridbag.setConstraints(criticButton, cst);
101 JPanel checkboxPanel
= new JPanel();
102 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
103 checkboxPanel
.add(filebox
);
104 checkboxPanel
.add(screenbox
);
105 checkboxPanel
.add(mibox
);
106 checkboxPanel
.add(criticbox
);
107 checkboxPanel
.add(defaultpathbox
);
110 //cst.gridheight = 2;
111 gridbag
.setConstraints(checkboxPanel
, cst
);
114 log
= new JTextArea(10,20);
115 log
.setMargin(new Insets(5,5,5,5));
116 log
.setEditable(false);
117 JScrollPane logScrollPane
= new JScrollPane(log
);
120 cst
.fill
= GridBagConstraints
.BOTH
;
121 gridbag
.setConstraints(logScrollPane
, cst
);
124 fc
= new JFileChooser();
125 fc
.setFileSelectionMode(JFileChooser
.DIRECTORIES_ONLY
);
128 //---------------------------------------------------------------------------------------//
130 public boolean yesOrNo(String question
) {
131 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
134 public void print(String message
) {
135 if (toscreen
== true) {
137 System
.out
.print(message
);
139 if (tofile
== true) {
140 logfile
.append(message
);
144 public void println(String message
) {
145 print(message
+ "\n");
148 public void println(Set
<String
> hash
) {
149 if (toscreen
== true) {
150 log
.append(hash
+ "\n");
151 System
.out
.println(hash
);
153 if (tofile
== true) {
154 logfile
.append(hash
+ "\n");
158 public String
choose(String message
, Object
[] choicelist
) {
159 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
162 public String
getInput(String message
) {
163 return (String
)JOptionPane
.showInputDialog(message
);
166 //---------------------------------------------------------------------------------------//
168 public String
getFilepath(String title
) {
169 fc
.setDialogTitle(title
);
170 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
171 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
172 return fc
.getSelectedFile().getAbsolutePath();
177 //---------------------------------------------------------------------------------------//
179 public void actionPerformed(ActionEvent e
) {
180 if ( e
.getSource() == moduleButton
) {
181 startpath
= getFilepath("Please choose a starting path");
182 moduletext
.setText(startpath
);
184 if ( e
.getSource() == goButton
) {
186 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(startpath
.replaceAll(Common
.strseparate
, "$1") + File
.separator
+ "migration.log")));
187 MigrationTool
.startMigrateAll(startpath
);
189 } catch (Exception en
) {
190 println(en
.getMessage());
193 if ( e
.getSource() == msaEditorButton
) {
195 MsaTreeEditor
.init(mi
, this);
196 } catch (Exception en
) {
197 println(en
.getMessage());
200 if ( e
.getSource() == criticButton
) {
202 Critic
.fireAt(startpath
);
203 } catch (Exception en
) {
204 println(en
.getMessage());
207 if ( e
.getSource() == specifyCommentButton
) {
208 try { // input examine is not imposed but should be added
209 MigrationTool
.MIGRATIONCOMMENT
= getInput("Please type in wanted comment style used by the tool\nbe sure to start with '//', or you won't enjoy the result");
210 } catch (Exception en
) {
211 println(en
.getMessage());
216 public void itemStateChanged(ItemEvent e
) {
217 if (e
.getSource() == filebox
) {
218 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
219 System
.out
.println("filebox DESELECTED");
220 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
221 System
.out
.println("filebox SELECTED");
223 } else if (e
.getSource() == screenbox
) {
224 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
225 System
.out
.println("screenbox DESELECTED");
226 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
227 System
.out
.println("screenbox SELECTED");
229 } else if (e
.getSource() == mibox
) {
230 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
231 MigrationTool
.printModuleInfo
= false;
232 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
233 MigrationTool
.printModuleInfo
= true;
235 } else if (e
.getSource() == criticbox
) {
236 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
237 MigrationTool
.doCritic
= false;
238 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
239 MigrationTool
.doCritic
= true;
241 } else if (e
.getSource() == defaultpathbox
) {
242 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
243 MigrationTool
.defaultoutput
= false;
244 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
245 MigrationTool
.defaultoutput
= true;
250 //---------------------------------------------------------------------------------------//
252 private static final FirstPanel
init() {
254 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
255 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
256 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
257 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
258 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
259 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
260 } catch (Exception e
) {
261 System
.out
.println(e
.getMessage());
264 JFrame frame
= new JFrame("MigrationTools");
265 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
267 FirstPanel fp
= new FirstPanel();
268 //fp.setLayout(new GridBagLayout());
269 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
271 frame
.setContentPane(fp
);
274 frame
.setVisible(true);
279 public static final FirstPanel
getInstance() {