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