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