]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java
Many Many Modifies
[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 final 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 private ModuleInfo mi;
29
30 private JButton moduleButton, goButton, msaEditorButton, criticButton;
31 private JTextField moduletext;
32 private JTextArea log;
33 private JFileChooser fc;
34 private JCheckBox filebox, screenbox;
35
36 private boolean tofile = true, toscreen = true;
37 private PrintWriter logfile;
38
39 FirstPanel() throws Exception {
40 goButton = new JButton("Go");
41 goButton.addActionListener(this);
42 goButton.setActionCommand("go");
43
44 moduleButton = new JButton("Choose ModulePath");
45 moduleButton.addActionListener(this);
46
47 msaEditorButton = new JButton("MsaEditor");
48 msaEditorButton.addActionListener(this);
49
50 criticButton = new JButton("Critic");
51 criticButton.addActionListener(this);
52
53 moduletext = new JTextField(30);
54
55 filebox = new JCheckBox("Output to logfile", true);
56 screenbox = new JCheckBox("Specify logfile", false);
57
58 JPanel modulePanel = new JPanel();
59 modulePanel.add(moduleButton);
60 modulePanel.add(moduletext);
61 modulePanel.add(filebox);
62 modulePanel.add(screenbox);
63 modulePanel.add(goButton);
64 //modulePanel.add(msaEditorButton);
65 modulePanel.add(criticButton);
66 add(modulePanel);
67
68 log = new JTextArea(20,25);
69 log.setMargin(new Insets(5,5,5,5));
70 log.setEditable(false);
71 JScrollPane logScrollPane = new JScrollPane(log);
72 add(logScrollPane);
73
74 fc = new JFileChooser();
75 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
76 }
77
78 //---------------------------------------------------------------------------------------//
79
80 public boolean yesOrNo(String question) {
81 return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
82 }
83
84 public void print(String message) {
85 if (toscreen == true) {
86 log.append(message);
87 System.out.print(message);
88 }
89 if (tofile == true) {
90 logfile.append(message);
91 }
92 }
93
94 public void println(String message) {
95 print(message + "\n");
96 }
97
98 public void println(Set<String> hash) {
99 if (toscreen == true) {
100 log.append(hash + "\n");
101 System.out.println(hash);
102 }
103 if (tofile == true) {
104 logfile.append(hash + "\n");
105 }
106 }
107
108 public String choose(String message, Object[] choicelist) {
109 return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);
110 }
111
112 public String getInput(String message) {
113 return (String)JOptionPane.showInputDialog(message);
114 }
115
116 //---------------------------------------------------------------------------------------//
117
118 public String getFilepath() {
119 if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
120 log.append(fc.getSelectedFile().getAbsolutePath() + "\n");
121 return fc.getSelectedFile().getAbsolutePath();
122 }
123 return null;
124 }
125
126 //---------------------------------------------------------------------------------------//
127
128 public void actionPerformed(ActionEvent e) {
129 if ( e.getSource() == moduleButton ) {
130 modulepath = getFilepath();
131 /*
132 int ret = fc.showOpenDialog(this);
133 if (ret == JFileChooser.APPROVE_OPTION) {
134 modulepath = fc.getSelectedFile().getAbsolutePath();
135 moduletext.setText(modulepath);
136 log.append("ModulePath: " + modulepath + "\n");
137 }
138 */
139 }
140 if ( e.getSource() == goButton ) {
141 try {
142 logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));
143 println("Project MsaGen");
144 println("Copyright (c) 2006, Intel Corporation");
145 Common.toDoAll(modulepath, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR);
146 logfile.flush();
147 } catch (Exception en) {
148 println(en.getMessage());
149 }
150 }
151 if ( e.getSource() == msaEditorButton) {
152 try {
153 MsaTreeEditor.init(mi, this);
154 } catch (Exception en) {
155 println(en.getMessage());
156 }
157 }
158 if ( e.getSource() == criticButton) {
159 try {
160 Critic.fireAt(modulepath);
161 } catch (Exception en) {
162 println(en.getMessage());
163 }
164 }
165 }
166
167 public void itemStateChanged(ItemEvent e) {
168 if (e.getStateChange() == ItemEvent.DESELECTED) {
169 System.out.println("changed");
170 }
171 }
172
173 //---------------------------------------------------------------------------------------//
174
175 public static FirstPanel init() throws Exception {
176
177 //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
178 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
179 //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
180 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
181 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
182 //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
183
184 JFrame frame = new JFrame("MigrationTools");
185 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
186
187 FirstPanel fp = new FirstPanel();
188 fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));
189 fp.setOpaque(true);
190 frame.setContentPane(fp);
191
192 frame.pack();
193 frame.setVisible(true);
194
195 return fp;
196 }
197 }