]>
Commit | Line | Data |
---|---|---|
b0282412 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | **/\r | |
0dc8c589 | 13 | package org.tianocore.migration;\r |
14 | \r | |
15 | import java.awt.*;\r | |
16 | import java.awt.event.*;\r | |
17 | import java.io.*;\r | |
18 | import java.util.*;\r | |
19 | import javax.swing.*;\r | |
20 | \r | |
5ea254f6 | 21 | public final class FirstPanel extends JPanel implements ActionListener, UI {\r |
0dc8c589 | 22 | /**\r |
23 | * Define class Serial Version UID\r | |
24 | */\r | |
25 | private static final long serialVersionUID = 207759413522910399L;\r | |
26 | \r | |
27 | private String modulepath;\r | |
90503bad | 28 | private ModuleInfo mi;\r |
0dc8c589 | 29 | \r |
fed802b1 | 30 | private JButton moduleButton, goButton, msaEditorButton, criticButton;\r |
0dc8c589 | 31 | private JTextField moduletext;\r |
32 | private JTextArea log;\r | |
33 | private JFileChooser fc;\r | |
34 | private JCheckBox filebox, screenbox;\r | |
35 | \r | |
36 | private boolean tofile = true, toscreen = true;\r | |
37 | private PrintWriter logfile;\r | |
38 | \r | |
39 | FirstPanel() throws Exception {\r | |
40 | goButton = new JButton("Go");\r | |
41 | goButton.addActionListener(this);\r | |
42 | goButton.setActionCommand("go");\r | |
43 | \r | |
44 | moduleButton = new JButton("Choose ModulePath");\r | |
45 | moduleButton.addActionListener(this);\r | |
46 | \r | |
90503bad | 47 | msaEditorButton = new JButton("MsaEditor");\r |
48 | msaEditorButton.addActionListener(this);\r | |
49 | \r | |
fed802b1 | 50 | criticButton = new JButton("Critic");\r |
51 | criticButton.addActionListener(this);\r | |
52 | \r | |
0dc8c589 | 53 | moduletext = new JTextField(30);\r |
54 | \r | |
55 | filebox = new JCheckBox("Output to logfile", true);\r | |
56 | screenbox = new JCheckBox("Specify logfile", false);\r | |
57 | \r | |
58 | JPanel modulePanel = new JPanel();\r | |
59 | modulePanel.add(moduleButton);\r | |
60 | modulePanel.add(moduletext);\r | |
61 | modulePanel.add(filebox);\r | |
62 | modulePanel.add(screenbox);\r | |
63 | modulePanel.add(goButton);\r | |
5ea254f6 | 64 | //modulePanel.add(msaEditorButton);\r |
fed802b1 | 65 | modulePanel.add(criticButton);\r |
0dc8c589 | 66 | add(modulePanel);\r |
67 | \r | |
90503bad | 68 | log = new JTextArea(20,25);\r |
0dc8c589 | 69 | log.setMargin(new Insets(5,5,5,5));\r |
70 | log.setEditable(false);\r | |
71 | JScrollPane logScrollPane = new JScrollPane(log);\r | |
72 | add(logScrollPane);\r | |
73 | \r | |
74 | fc = new JFileChooser();\r | |
75 | fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r | |
76 | }\r | |
77 | \r | |
78 | //---------------------------------------------------------------------------------------//\r | |
79 | \r | |
80 | public boolean yesOrNo(String question) {\r | |
81 | return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r | |
82 | }\r | |
83 | \r | |
84 | public void print(String message) {\r | |
85 | if (toscreen == true) {\r | |
86 | log.append(message);\r | |
87 | System.out.print(message);\r | |
88 | }\r | |
89 | if (tofile == true) {\r | |
90 | logfile.append(message);\r | |
91 | }\r | |
92 | }\r | |
93 | \r | |
94 | public void println(String message) {\r | |
95 | print(message + "\n");\r | |
96 | }\r | |
97 | \r | |
98 | public void println(Set<String> hash) {\r | |
99 | if (toscreen == true) {\r | |
100 | log.append(hash + "\n");\r | |
101 | System.out.println(hash);\r | |
102 | }\r | |
103 | if (tofile == true) {\r | |
104 | logfile.append(hash + "\n");\r | |
105 | }\r | |
106 | }\r | |
107 | \r | |
e6a5df3b | 108 | public String choose(String message, Object[] choicelist) {\r |
109 | return (String)JOptionPane.showInputDialog(this, message,"Choose",JOptionPane.PLAIN_MESSAGE,null,choicelist,choicelist[0]);\r | |
110 | }\r | |
0dc8c589 | 111 | \r |
90503bad | 112 | public String getInput(String message) {\r |
113 | return (String)JOptionPane.showInputDialog(message);\r | |
0dc8c589 | 114 | }\r |
90503bad | 115 | \r |
116 | //---------------------------------------------------------------------------------------//\r | |
117 | \r | |
5ea254f6 | 118 | public String getFilepath() {\r |
119 | if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {\r | |
120 | log.append(fc.getSelectedFile().getAbsolutePath() + "\n");\r | |
121 | return fc.getSelectedFile().getAbsolutePath();\r | |
122 | }\r | |
123 | return null;\r | |
124 | }\r | |
125 | \r | |
126 | //---------------------------------------------------------------------------------------//\r | |
127 | \r | |
0dc8c589 | 128 | public void actionPerformed(ActionEvent e) {\r |
129 | if ( e.getSource() == moduleButton ) {\r | |
5ea254f6 | 130 | modulepath = getFilepath();\r |
0dc8c589 | 131 | }\r |
132 | if ( e.getSource() == goButton ) {\r | |
133 | try {\r | |
134 | logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r | |
7bcb8d17 | 135 | ModuleInfo.triger(modulepath);\r |
0dc8c589 | 136 | logfile.flush();\r |
137 | } catch (Exception en) {\r | |
138 | println(en.getMessage());\r | |
139 | }\r | |
140 | }\r | |
90503bad | 141 | if ( e.getSource() == msaEditorButton) {\r |
142 | try {\r | |
143 | MsaTreeEditor.init(mi, this);\r | |
144 | } catch (Exception en) {\r | |
145 | println(en.getMessage());\r | |
146 | }\r | |
147 | }\r | |
fed802b1 | 148 | if ( e.getSource() == criticButton) {\r |
149 | try {\r | |
150 | Critic.fireAt(modulepath);\r | |
151 | } catch (Exception en) {\r | |
152 | println(en.getMessage());\r | |
153 | }\r | |
154 | }\r | |
0dc8c589 | 155 | }\r |
156 | \r | |
157 | public void itemStateChanged(ItemEvent e) {\r | |
158 | if (e.getStateChange() == ItemEvent.DESELECTED) {\r | |
159 | System.out.println("changed");\r | |
160 | }\r | |
161 | }\r | |
162 | \r | |
163 | //---------------------------------------------------------------------------------------//\r | |
164 | \r | |
5ea254f6 | 165 | public static FirstPanel init() throws Exception {\r |
b48e3710 | 166 | \r |
167 | //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());\r | |
168 | UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r | |
169 | //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");\r | |
170 | //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");\r | |
171 | //UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");\r | |
172 | //UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");\r | |
173 | \r | |
174 | JFrame frame = new JFrame("MigrationTools");\r | |
0dc8c589 | 175 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r |
176 | \r | |
177 | FirstPanel fp = new FirstPanel();\r | |
178 | fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r | |
179 | fp.setOpaque(true);\r | |
180 | frame.setContentPane(fp);\r | |
181 | \r | |
90503bad | 182 | frame.pack();\r |
0dc8c589 | 183 | frame.setVisible(true);\r |
5ea254f6 | 184 | \r |
185 | return fp;\r | |
0dc8c589 | 186 | }\r |
187 | } |