30085d449edd0770bc1fd7c5ab4712334da39fa5
[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 public String choose(String message, Object[] choicelist) {
100 return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
101 }
102
103 //---------------------------------------------------------------------------------------//
104
105 /*
106 public boolean getOption(String item) {
107 if (item.matches("file")) {
108 }
109 }
110 */
111
112 public void actionPerformed(ActionEvent e) {
113 if ( e.getSource() == moduleButton ) {
114 int ret = fc.showOpenDialog(this);
115 if (ret == JFileChooser.APPROVE_OPTION) {
116 modulepath = fc.getSelectedFile().getAbsolutePath();
117 moduletext.setText(modulepath);
118 log.append("ModulePath: " + modulepath + "\n");
119 }
120 }
121 if ( e.getSource() == goButton ) {
122 try {
123 logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
124 println("Project MsaGen");
125 println("Copyright (c) 2006, Intel Corporation");
126 new ModuleInfo(modulepath, this, new Database());
127 logfile.flush();
128 } catch (Exception en) {
129 println(en.getMessage());
130 }
131 }
132 }
133
134 public void itemStateChanged(ItemEvent e) {
135 if (e.getStateChange() == ItemEvent.DESELECTED) {
136 System.out.println("changed");
137 }
138 }
139
140 //---------------------------------------------------------------------------------------//
141
142 public static void init() throws Exception {
143
144 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
145 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
146 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
147 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
148 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
149 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
150
151 JFrame frame = new JFrame("MigrationTools");
152 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
153
154 FirstPanel fp = new FirstPanel();
155 fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
156 fp.setOpaque(true);
157 frame.setContentPane(fp);
158
159 frame.setSize(800,600);
160 frame.setVisible(true);
161 }
162 }