Add License Head to all files
[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 class FirstPanel extends JPanel implements ActionListener, UI {
22 /**
23 * Define class Serial Version UID
24 */
25 private static final long serialVersionUID = 207759413522910399L;
26
27 private String modulepath;
28
29 private JButton moduleButton , goButton;
30 private JTextField moduletext;
31 private JTextArea log;
32 private JFileChooser fc;
33 private JCheckBox filebox, screenbox;
34
35 private boolean tofile = true, toscreen = true;
36 private PrintWriter logfile;
37
38 FirstPanel() throws Exception {
39 goButton = new JButton("Go");
40 goButton.addActionListener(this);
41 goButton.setActionCommand("go");
42
43 moduleButton = new JButton("Choose ModulePath");
44 moduleButton.addActionListener(this);
45
46 moduletext = new JTextField(30);
47
48 filebox = new JCheckBox("Output to logfile", true);
49 screenbox = new JCheckBox("Specify logfile", false);
50
51 JPanel modulePanel = new JPanel();
52 modulePanel.add(moduleButton);
53 modulePanel.add(moduletext);
54 modulePanel.add(filebox);
55 modulePanel.add(screenbox);
56 modulePanel.add(goButton);
57 add(modulePanel);
58
59 log = new JTextArea(50,25);
60 log.setMargin(new Insets(5,5,5,5));
61 log.setEditable(false);
62 JScrollPane logScrollPane = new JScrollPane(log);
63 add(logScrollPane);
64
65 fc = new JFileChooser();
66 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
67 }
68
69 //---------------------------------------------------------------------------------------//
70
71 public boolean yesOrNo(String question) {
72 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
73 }
74
75 public void print(String message) {
76 if (toscreen == true) {
77 log.append(message);
78 System.out.print(message);
79 }
80 if (tofile == true) {
81 logfile.append(message);
82 }
83 }
84
85 public void println(String message) {
86 print(message + "\n");
87 }
88
89 public void println(Set<String> hash) {
90 if (toscreen == true) {
91 log.append(hash + "\n");
92 System.out.println(hash);
93 }
94 if (tofile == true) {
95 logfile.append(hash + "\n");
96 }
97 }
98
99 //---------------------------------------------------------------------------------------//
100
101 /*
102 public boolean getOption(String item) {
103 if (item.matches("file")) {
104 }
105 }
106 */
107
108 public void actionPerformed(ActionEvent e) {
109 if ( e.getSource() == moduleButton ) {
110 int ret = fc.showOpenDialog(this);
111 if (ret == JFileChooser.APPROVE_OPTION) {
112 modulepath = fc.getSelectedFile().getAbsolutePath();
113 moduletext.setText(modulepath);
114 log.append("ModulePath: " + modulepath + "\n");
115 }
116 }
117 if ( e.getSource() == goButton ) {
118 try {
119 logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
120 println("Project MsaGen");
121 println("Copyright (c) 2006, Intel Corporation");
122 new ModuleInfo(modulepath, this, new Database());
123 logfile.flush();
124 } catch (Exception en) {
125 println(en.getMessage());
126 }
127 }
128 }
129
130 public void itemStateChanged(ItemEvent e) {
131 if (e.getStateChange() == ItemEvent.DESELECTED) {
132 System.out.println("changed");
133 }
134 }
135
136 //---------------------------------------------------------------------------------------//
137
138 public static void init() throws Exception {
139
140 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
141 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
142 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
143 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
144 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
145 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
146
147 JFrame frame = new JFrame("MigrationTools");
148 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
149
150 FirstPanel fp = new FirstPanel();
151 fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
152 fp.setOpaque(true);
153 frame.setContentPane(fp);
154
155 frame.setSize(800,600);
156 frame.setVisible(true);
157 }
158 }