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