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 String modulepath
;
28 private ModuleInfo mi
;
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
;
36 private boolean tofile
= true, toscreen
= true;
37 private PrintWriter logfile
;
39 FirstPanel() throws Exception
{
40 GridBagLayout gridbag
= new GridBagLayout();
43 GridBagConstraints cst
= new GridBagConstraints();
45 goButton
= new JButton("Go");
46 goButton
.addActionListener(this);
47 goButton
.setActionCommand("go");
49 moduleButton
= new JButton("Choose ModulePath");
50 moduleButton
.addActionListener(this);
52 msaEditorButton
= new JButton("MsaEditor");
53 msaEditorButton
.addActionListener(this);
55 criticButton
= new JButton("Critic");
56 criticButton
.addActionListener(this);
58 moduletext
= new JTextField(30);
60 filebox
= new JCheckBox("Output to logfile", true);
61 filebox
.addItemListener(this);
63 screenbox
= new JCheckBox("Specify logfile", false);
64 screenbox
.addItemListener(this);
66 mibox
= new JCheckBox("Print ModuleInfo", false);
67 mibox
.addItemListener(this);
68 MigrationTool
.printModuleInfo
= false;
70 criticbox
= new JCheckBox("Run Critic", true);
71 criticbox
.addItemListener(this);
72 MigrationTool
.doCritic
= true;
74 defaultpathbox
= new JCheckBox("Use Default Output Path", true);
75 defaultpathbox
.addItemListener(this);
77 JPanel modulePanel
= new JPanel();
78 modulePanel
.add(moduleButton
);
79 modulePanel
.add(moduletext
);
80 modulePanel
.add(goButton
);
81 //modulePanel.add(msaEditorButton);
84 //cst.gridwidth = GridBagConstraints.REMAINDER;
85 gridbag
.setConstraints(modulePanel
, cst
);
90 gridbag
.setConstraints(criticButton
, cst
);
93 JPanel checkboxPanel
= new JPanel();
94 checkboxPanel
.setLayout(new BoxLayout(checkboxPanel
, BoxLayout
.Y_AXIS
));
95 checkboxPanel
.add(filebox
);
96 checkboxPanel
.add(screenbox
);
97 checkboxPanel
.add(mibox
);
98 checkboxPanel
.add(criticbox
);
99 checkboxPanel
.add(defaultpathbox
);
102 //cst.gridheight = 2;
103 gridbag
.setConstraints(checkboxPanel
, cst
);
106 log
= new JTextArea(10,20);
107 log
.setMargin(new Insets(5,5,5,5));
108 log
.setEditable(false);
109 JScrollPane logScrollPane
= new JScrollPane(log
);
112 cst
.fill
= GridBagConstraints
.BOTH
;
113 gridbag
.setConstraints(logScrollPane
, cst
);
116 fc
= new JFileChooser();
117 fc
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
120 //---------------------------------------------------------------------------------------//
122 public boolean yesOrNo(String question
) {
123 return JOptionPane
.showConfirmDialog(this, question
, "Yes or No", JOptionPane
.YES_NO_OPTION
) == JOptionPane
.YES_OPTION
;
126 public void print(String message
) {
127 if (toscreen
== true) {
129 System
.out
.print(message
);
131 if (tofile
== true) {
132 logfile
.append(message
);
136 public void println(String message
) {
137 print(message
+ "\n");
140 public void println(Set
<String
> hash
) {
141 if (toscreen
== true) {
142 log
.append(hash
+ "\n");
143 System
.out
.println(hash
);
145 if (tofile
== true) {
146 logfile
.append(hash
+ "\n");
150 public String
choose(String message
, Object
[] choicelist
) {
151 return (String
)JOptionPane
.showInputDialog(this, message
,"Choose",JOptionPane
.PLAIN_MESSAGE
,null,choicelist
,choicelist
[0]);
154 public String
getInput(String message
) {
155 return (String
)JOptionPane
.showInputDialog(message
);
158 //---------------------------------------------------------------------------------------//
160 public String
getFilepath() {
161 if (fc
.showOpenDialog(this) == JFileChooser
.APPROVE_OPTION
) {
162 log
.append(fc
.getSelectedFile().getAbsolutePath() + "\n");
163 return fc
.getSelectedFile().getAbsolutePath();
168 //---------------------------------------------------------------------------------------//
170 public void actionPerformed(ActionEvent e
) {
171 if ( e
.getSource() == moduleButton
) {
172 modulepath
= getFilepath();
174 if ( e
.getSource() == goButton
) {
176 logfile
= new PrintWriter(new BufferedWriter(new FileWriter(modulepath
+ File
.separator
+ "migration.log")));
177 ModuleInfo
.triger(modulepath
);
179 } catch (Exception en
) {
180 println(en
.getMessage());
183 if ( e
.getSource() == msaEditorButton
) {
185 MsaTreeEditor
.init(mi
, this);
186 } catch (Exception en
) {
187 println(en
.getMessage());
190 if ( e
.getSource() == criticButton
) {
192 Critic
.fireAt(modulepath
);
193 } catch (Exception en
) {
194 println(en
.getMessage());
199 public void itemStateChanged(ItemEvent e
) {
200 if (e
.getSource() == filebox
) {
201 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
202 System
.out
.println("filebox DESELECTED");
203 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
204 System
.out
.println("filebox SELECTED");
206 } else if (e
.getSource() == screenbox
) {
207 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
208 System
.out
.println("screenbox DESELECTED");
209 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
210 System
.out
.println("screenbox SELECTED");
212 } else if (e
.getSource() == mibox
) {
213 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
214 MigrationTool
.printModuleInfo
= false;
215 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
216 MigrationTool
.printModuleInfo
= true;
218 } else if (e
.getSource() == criticbox
) {
219 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
220 MigrationTool
.doCritic
= false;
221 System
.out
.println("criticbox DESELECTED");
222 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
223 MigrationTool
.doCritic
= true;
224 System
.out
.println("criticbox SELECTED");
226 } else if (e
.getSource() == defaultpathbox
) {
227 if (e
.getStateChange() == ItemEvent
.DESELECTED
) {
228 System
.out
.println("defaultpathbox DESELECTED");
229 } else if (e
.getStateChange() == ItemEvent
.SELECTED
) {
230 System
.out
.println("defaultpathbox SELECTED");
235 //---------------------------------------------------------------------------------------//
237 public static FirstPanel
init() throws Exception
{
239 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
240 UIManager
.setLookAndFeel(UIManager
.getSystemLookAndFeelClassName());
241 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
242 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
243 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
244 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
246 JFrame frame
= new JFrame("MigrationTools");
247 frame
.setDefaultCloseOperation(JFrame
.EXIT_ON_CLOSE
);
249 FirstPanel fp
= new FirstPanel();
250 //fp.setLayout(new GridBagLayout());
251 //fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
253 frame
.setContentPane(fp
);
256 frame
.setVisible(true);