]>
Commit | Line | Data |
---|---|---|
5a24e806 | 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 | |
13 | \r | |
14 | package org.tianocore.frameworkwizard.far.updateui;\r | |
15 | \r | |
16 | import java.awt.Dimension;\r | |
17 | import java.awt.Toolkit;\r | |
18 | import java.awt.event.MouseEvent;\r | |
19 | import java.awt.event.MouseListener;\r | |
20 | import java.io.File;\r | |
21 | import java.util.Vector;\r | |
1898a0c3 | 22 | import java.util.jar.JarFile;\r |
5a24e806 | 23 | \r |
24 | import javax.swing.JFileChooser;\r | |
25 | import javax.swing.JPanel;\r | |
26 | import javax.swing.JTextArea;\r | |
27 | import javax.swing.JButton;\r | |
28 | import javax.swing.JLabel;\r | |
29 | import javax.swing.JTextField;\r | |
30 | \r | |
31 | import org.tianocore.frameworkwizard.common.DataType;\r | |
32 | import org.tianocore.frameworkwizard.common.IFileFilter;\r | |
33 | import org.tianocore.frameworkwizard.common.Log;\r | |
34 | import org.tianocore.frameworkwizard.common.Tools;\r | |
35 | import org.tianocore.frameworkwizard.common.ui.IDialog;\r | |
36 | import org.tianocore.frameworkwizard.common.ui.IFrame;\r | |
37 | import org.tianocore.frameworkwizard.far.Far;\r | |
38 | import org.tianocore.frameworkwizard.far.FarIdentification;\r | |
39 | import org.tianocore.frameworkwizard.workspace.Workspace;\r | |
40 | import org.tianocore.frameworkwizard.workspace.WorkspaceTools;\r | |
41 | \r | |
42 | import javax.swing.JScrollPane;\r | |
43 | import javax.swing.JList;\r | |
44 | \r | |
45 | public class UpdateStepOne extends IDialog implements MouseListener {\r | |
46 | \r | |
47 | /**\r | |
48 | * \r | |
49 | */\r | |
50 | private static final long serialVersionUID = 735554907464539931L;\r | |
51 | \r | |
52 | private JPanel jContentPane = null;\r | |
53 | \r | |
54 | private JTextArea jTextArea = null;\r | |
55 | \r | |
56 | private JButton jButtonCancel = null;\r | |
57 | \r | |
58 | private JButton jButtonNext = null;\r | |
59 | \r | |
60 | private JLabel jLabel = null;\r | |
61 | \r | |
62 | private JTextField jTextFieldFarFile = null;\r | |
63 | \r | |
64 | private JButton jButtonBrowser = null;\r | |
65 | \r | |
66 | private UpdateStepTwo stepTwo = null;\r | |
67 | \r | |
68 | private Far far = null;\r | |
69 | \r | |
70 | private Vector<FarIdentification> farVector = null;\r | |
71 | \r | |
72 | private JLabel jLabel1 = null;\r | |
73 | \r | |
74 | private JScrollPane jScrollPane = null;\r | |
75 | \r | |
76 | private JList jListFarFromDb = null;\r | |
77 | \r | |
78 | private File farFile = null;\r | |
79 | \r | |
80 | public File getFarFile() {\r | |
81 | return farFile;\r | |
82 | }\r | |
83 | \r | |
84 | /**\r | |
85 | * This method initializes jTextArea \r | |
86 | * \r | |
87 | * @return javax.swing.JTextArea \r | |
88 | */\r | |
89 | private JTextArea getJTextArea() {\r | |
90 | if (jTextArea == null) {\r | |
91 | jTextArea = new JTextArea();\r | |
92 | jTextArea.setBounds(new java.awt.Rectangle(30, 7, 642, 50));\r | |
93 | jTextArea.setText("Step 1: Choose framework archive (FAR) file. \n");\r | |
94 | jTextArea.setEditable(false);\r | |
95 | }\r | |
96 | return jTextArea;\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | * This method initializes jButtonCancel \r | |
101 | * \r | |
102 | * @return javax.swing.JButton \r | |
103 | */\r | |
104 | private JButton getJButtonCancel() {\r | |
105 | if (jButtonCancel == null) {\r | |
106 | jButtonCancel = new JButton();\r | |
107 | jButtonCancel.setBounds(new java.awt.Rectangle(570, 330, 90, 20));\r | |
108 | jButtonCancel.setText("Cancel");\r | |
109 | jButtonCancel.addMouseListener(this);\r | |
110 | }\r | |
111 | return jButtonCancel;\r | |
112 | }\r | |
113 | \r | |
114 | /**\r | |
115 | * This method initializes jButtonNext \r | |
116 | * \r | |
117 | * @return javax.swing.JButton \r | |
118 | */\r | |
119 | private JButton getJButtonNext() {\r | |
120 | if (jButtonNext == null) {\r | |
121 | jButtonNext = new JButton();\r | |
122 | jButtonNext.setBounds(new java.awt.Rectangle(470, 330, 90, 20));\r | |
123 | jButtonNext.setText("Next");\r | |
124 | jButtonNext.addMouseListener(this);\r | |
125 | }\r | |
126 | return jButtonNext;\r | |
127 | }\r | |
128 | \r | |
129 | /**\r | |
130 | * This method initializes jTextField \r | |
131 | * \r | |
132 | * @return javax.swing.JTextField \r | |
133 | */\r | |
134 | private JTextField getJTextFieldFarFile() {\r | |
135 | if (jTextFieldFarFile == null) {\r | |
136 | jTextFieldFarFile = new JTextField();\r | |
a45e9a40 | 137 | jTextFieldFarFile.setBounds(new java.awt.Rectangle(130,80,436,20));\r |
5a24e806 | 138 | }\r |
139 | return jTextFieldFarFile;\r | |
140 | }\r | |
141 | \r | |
142 | /**\r | |
143 | * This method initializes jButton \r | |
144 | * \r | |
145 | * @return javax.swing.JButton \r | |
146 | */\r | |
147 | private JButton getJButtonBrowser() {\r | |
148 | if (jButtonBrowser == null) {\r | |
149 | jButtonBrowser = new JButton();\r | |
a45e9a40 | 150 | jButtonBrowser.setBounds(new java.awt.Rectangle(570, 80, 100, 20));\r |
5a24e806 | 151 | jButtonBrowser.setText("Browser...");\r |
152 | jButtonBrowser.addMouseListener(this);\r | |
153 | }\r | |
154 | return jButtonBrowser;\r | |
155 | }\r | |
156 | \r | |
157 | /**\r | |
158 | * This method initializes jScrollPane \r | |
159 | * \r | |
160 | * @return javax.swing.JScrollPane \r | |
161 | */\r | |
162 | private JScrollPane getJScrollPane() {\r | |
163 | if (jScrollPane == null) {\r | |
164 | jScrollPane = new JScrollPane();\r | |
a45e9a40 | 165 | jScrollPane.setBounds(new java.awt.Rectangle(30, 135, 642, 160));\r |
5a24e806 | 166 | jScrollPane.setViewportView(getJListFarFromDb());\r |
167 | }\r | |
168 | return jScrollPane;\r | |
169 | }\r | |
170 | \r | |
171 | /**\r | |
172 | * This method initializes jListFarFromDb \r | |
173 | * \r | |
174 | * @return javax.swing.JList \r | |
175 | */\r | |
176 | private JList getJListFarFromDb() {\r | |
177 | if (jListFarFromDb == null) {\r | |
178 | jListFarFromDb = new JList();\r | |
179 | WorkspaceTools wt = new WorkspaceTools();\r | |
180 | farVector = wt.getAllFars();\r | |
181 | jListFarFromDb.setListData(farVector);\r | |
182 | }\r | |
183 | return jListFarFromDb;\r | |
184 | }\r | |
185 | \r | |
186 | /**\r | |
187 | * This is the default constructor\r | |
188 | */\r | |
189 | public UpdateStepOne(IFrame iFrame, boolean modal) {\r | |
190 | super(iFrame, modal);\r | |
191 | initialize();\r | |
192 | }\r | |
193 | \r | |
194 | /**\r | |
195 | * This method initializes this\r | |
196 | * \r | |
197 | * @return void\r | |
198 | */\r | |
199 | private void initialize() {\r | |
200 | this.setSize(700, 400);\r | |
201 | this.setContentPane(getJContentPane());\r | |
202 | this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");\r | |
203 | Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r | |
204 | this.setLocation((d.width - this.getSize().width) / 2, (d.height - this.getSize().height) / 2);\r | |
205 | }\r | |
206 | \r | |
207 | /**\r | |
208 | * This method initializes jContentPane\r | |
209 | * \r | |
210 | * @return javax.swing.JPanel\r | |
211 | */\r | |
212 | private JPanel getJContentPane() {\r | |
213 | if (jContentPane == null) {\r | |
214 | jLabel1 = new JLabel();\r | |
a45e9a40 | 215 | jLabel1.setBounds(new java.awt.Rectangle(30, 110, 355, 18));\r |
5a24e806 | 216 | jLabel1.setText("Choose FAR from current framework database");\r |
217 | jLabel = new JLabel();\r | |
a45e9a40 | 218 | jLabel.setBounds(new java.awt.Rectangle(30,80,97,20));\r |
5a24e806 | 219 | jLabel.setText("Choose FAR file: ");\r |
220 | jContentPane = new JPanel();\r | |
221 | jContentPane.setLayout(null);\r | |
222 | jContentPane.add(getJTextArea(), null);\r | |
223 | jContentPane.add(getJButtonCancel(), null);\r | |
224 | jContentPane.add(getJButtonNext(), null);\r | |
225 | jContentPane.add(jLabel, null);\r | |
226 | jContentPane.add(getJTextFieldFarFile(), null);\r | |
227 | jContentPane.add(getJButtonBrowser(), null);\r | |
228 | jContentPane.add(jLabel1, null);\r | |
229 | jContentPane.add(getJScrollPane(), null);\r | |
230 | }\r | |
231 | return jContentPane;\r | |
232 | }\r | |
233 | \r | |
1898a0c3 | 234 | public void mouseClicked(MouseEvent e) {\r |
235 | if (e.getSource() == jButtonCancel) {\r | |
236 | this.setVisible(false);\r | |
237 | }\r | |
238 | else if (e.getSource() == jButtonNext) {\r | |
239 | //\r | |
240 | // Judge if FAR file is existed\r | |
241 | //\r | |
242 | farFile = new File(jTextFieldFarFile.getText());\r | |
243 | if ( ! farFile.exists() || ! farFile.isFile()) {\r | |
244 | Log.err("Please choose a FAR file already exists. ");\r | |
245 | return ;\r | |
246 | } \r | |
247 | \r | |
248 | //\r | |
249 | // Judge FAR is valid\r | |
250 | //\r | |
251 | try{\r | |
252 | JarFile file = new JarFile(farFile);\r | |
253 | this.far = new Far(file);\r | |
254 | } catch (Exception ex){\r | |
255 | Log.err(ex.getMessage());\r | |
256 | }\r | |
257 | \r | |
258 | \r | |
259 | //\r | |
260 | // Add more logic process here\r | |
261 | //\r | |
262 | if (jListFarFromDb.getSelectedValue() == null) {\r | |
263 | Log.err("Please choose a FAR from framework database. ");\r | |
264 | return ;\r | |
265 | }\r | |
266 | \r | |
267 | if (stepTwo == null) {\r | |
5a24e806 | 268 | stepTwo = new UpdateStepTwo(this, true, this);\r |
1898a0c3 | 269 | }\r |
270 | this.setVisible(false);\r | |
271 | stepTwo.prepareTable();\r | |
272 | stepTwo.setVisible(true);\r | |
273 | }\r | |
274 | else if (e.getSource() == jButtonBrowser) {\r | |
275 | JFileChooser fc = new JFileChooser();\r | |
276 | fc.setAcceptAllFileFilterUsed(false);\r | |
277 | fc.addChoosableFileFilter(new IFileFilter(DataType.FAR_SURFACE_AREA_EXT));\r | |
278 | fc.setCurrentDirectory(new File(Workspace.getCurrentWorkspace()));\r | |
5a24e806 | 279 | \r |
280 | int result = fc.showSaveDialog(new JPanel());\r | |
281 | if (result == JFileChooser.APPROVE_OPTION) {\r | |
282 | this.jTextFieldFarFile.setText(Tools.addPathExt(fc.getSelectedFile().getPath(),\r | |
283 | DataType.RETURN_TYPE_FAR_SURFACE_AREA));\r | |
284 | }\r | |
285 | }\r | |
286 | }\r | |
287 | \r | |
288 | public void mousePressed(MouseEvent e) {\r | |
289 | // TODO Auto-generated method stub\r | |
290 | \r | |
291 | }\r | |
292 | \r | |
293 | public void mouseReleased(MouseEvent e) {\r | |
294 | // TODO Auto-generated method stub\r | |
295 | \r | |
296 | }\r | |
297 | \r | |
298 | public void mouseEntered(MouseEvent e) {\r | |
299 | // TODO Auto-generated method stub\r | |
300 | \r | |
301 | }\r | |
302 | \r | |
303 | public void mouseExited(MouseEvent e) {\r | |
304 | // TODO Auto-generated method stub\r | |
305 | \r | |
306 | }\r | |
307 | \r | |
308 | public FarIdentification getSelecedDbFar() {\r | |
309 | return (FarIdentification) jListFarFromDb.getSelectedValue();\r | |
310 | }\r | |
311 | \r | |
312 | public Far getFar() {\r | |
313 | return far;\r | |
314 | }\r | |
315 | }\r |