Add License Head to all files
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / FirstPanel.java
CommitLineData
b0282412 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8 \r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 \r
12 **/\r
0dc8c589 13package org.tianocore.migration;\r
14\r
15import java.awt.*;\r
16import java.awt.event.*;\r
17import java.io.*;\r
18import java.util.*;\r
19import javax.swing.*;\r
20\r
21public class FirstPanel extends JPanel implements ActionListener, UI {\r
22 /**\r
23 * Define class Serial Version UID\r
24 */\r
25 private static final long serialVersionUID = 207759413522910399L;\r
26 \r
27 private String modulepath;\r
28 \r
29 private JButton moduleButton , goButton;\r
30 private JTextField moduletext;\r
31 private JTextArea log;\r
32 private JFileChooser fc;\r
33 private JCheckBox filebox, screenbox;\r
34 \r
35 private boolean tofile = true, toscreen = true;\r
36 private PrintWriter logfile;\r
37\r
38 FirstPanel() throws Exception {\r
39 goButton = new JButton("Go");\r
40 goButton.addActionListener(this);\r
41 goButton.setActionCommand("go");\r
42 \r
43 moduleButton = new JButton("Choose ModulePath");\r
44 moduleButton.addActionListener(this);\r
45\r
46 moduletext = new JTextField(30);\r
47 \r
48 filebox = new JCheckBox("Output to logfile", true);\r
49 screenbox = new JCheckBox("Specify logfile", false);\r
50 \r
51 JPanel modulePanel = new JPanel();\r
52 modulePanel.add(moduleButton);\r
53 modulePanel.add(moduletext);\r
54 modulePanel.add(filebox);\r
55 modulePanel.add(screenbox);\r
56 modulePanel.add(goButton);\r
57 add(modulePanel);\r
58\r
59 log = new JTextArea(50,25);\r
60 log.setMargin(new Insets(5,5,5,5));\r
61 log.setEditable(false);\r
62 JScrollPane logScrollPane = new JScrollPane(log);\r
63 add(logScrollPane);\r
64 \r
65 fc = new JFileChooser();\r
66 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r
67 }\r
68 \r
69 //---------------------------------------------------------------------------------------//\r
70 \r
71 public boolean yesOrNo(String question) {\r
72 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
73 }\r
74 \r
75 public void print(String message) {\r
76 if (toscreen == true) {\r
77 log.append(message);\r
78 System.out.print(message);\r
79 }\r
80 if (tofile == true) {\r
81 logfile.append(message);\r
82 }\r
83 }\r
84 \r
85 public void println(String message) {\r
86 print(message + "\n");\r
87 }\r
88\r
89 public void println(Set<String> hash) {\r
90 if (toscreen == true) {\r
91 log.append(hash + "\n");\r
92 System.out.println(hash);\r
93 }\r
94 if (tofile == true) {\r
95 logfile.append(hash + "\n");\r
96 }\r
97 }\r
98\r
99 //---------------------------------------------------------------------------------------//\r
100 \r
101 /*\r
102 public boolean getOption(String item) {\r
103 if (item.matches("file")) {\r
104 }\r
105 }\r
106 */\r
107 \r
108 public void actionPerformed(ActionEvent e) {\r
109 if ( e.getSource() == moduleButton ) {\r
110 int ret = fc.showOpenDialog(this);\r
111 if (ret == JFileChooser.APPROVE_OPTION) {\r
112 modulepath = fc.getSelectedFile().getAbsolutePath();\r
113 moduletext.setText(modulepath);\r
114 log.append("ModulePath: " + modulepath + "\n");\r
115 }\r
116 }\r
117 if ( e.getSource() == goButton ) {\r
118 try {\r
119 logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
120 println("Project MsaGen");\r
121 println("Copyright (c) 2006, Intel Corporation");\r
122 new ModuleInfo(modulepath, this, new Database());\r
123 logfile.flush();\r
124 } catch (Exception en) {\r
125 println(en.getMessage());\r
126 }\r
127 }\r
128 }\r
129 \r
130 public void itemStateChanged(ItemEvent e) {\r
131 if (e.getStateChange() == ItemEvent.DESELECTED) {\r
132 System.out.println("changed");\r
133 }\r
134 }\r
135\r
136 //---------------------------------------------------------------------------------------//\r
137 \r
138 public static void init() throws Exception {\r
b48e3710 139 \r
140 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r
141 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
142 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");\r
143 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");\r
144 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");\r
145 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");\r
146 \r
147 JFrame frame = new JFrame("MigrationTools");\r
0dc8c589 148 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
149\r
150 FirstPanel fp = new FirstPanel();\r
151 fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r
152 fp.setOpaque(true);\r
153 frame.setContentPane(fp);\r
154\r
155 frame.setSize(800,600);\r
156 frame.setVisible(true);\r
157 }\r
158}