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
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.
14 package org
.tianocore
.frameworkwizard
.far
.updateui
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
18 import java
.awt
.event
.MouseEvent
;
19 import java
.awt
.event
.MouseListener
;
21 import java
.util
.Vector
;
22 import java
.util
.jar
.JarFile
;
24 import javax
.swing
.JFileChooser
;
25 import javax
.swing
.JPanel
;
26 import javax
.swing
.JTextArea
;
27 import javax
.swing
.JButton
;
28 import javax
.swing
.JLabel
;
29 import javax
.swing
.JTextField
;
31 import org
.tianocore
.frameworkwizard
.common
.DataType
;
32 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
33 import org
.tianocore
.frameworkwizard
.common
.Log
;
34 import org
.tianocore
.frameworkwizard
.common
.Tools
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
37 import org
.tianocore
.frameworkwizard
.far
.Far
;
38 import org
.tianocore
.frameworkwizard
.far
.FarIdentification
;
39 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
40 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
42 import javax
.swing
.JScrollPane
;
43 import javax
.swing
.JList
;
45 public class UpdateStepOne
extends IDialog
implements MouseListener
{
50 private static final long serialVersionUID
= 735554907464539931L;
52 private JPanel jContentPane
= null;
54 private JTextArea jTextArea
= null;
56 private JButton jButtonCancel
= null;
58 private JButton jButtonNext
= null;
60 private JLabel jLabel
= null;
62 private JTextField jTextFieldFarFile
= null;
64 private JButton jButtonBrowser
= null;
66 private UpdateStepTwo stepTwo
= null;
68 private Far far
= null;
70 private Vector
<FarIdentification
> farVector
= null;
72 private JLabel jLabel1
= null;
74 private JScrollPane jScrollPane
= null;
76 private JList jListFarFromDb
= null;
78 private File farFile
= null;
80 public File
getFarFile() {
85 * This method initializes jTextArea
87 * @return javax.swing.JTextArea
89 private JTextArea
getJTextArea() {
90 if (jTextArea
== null) {
91 jTextArea
= new JTextArea();
92 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
93 jTextArea
.setText("Step 1: Choose framework archive (FAR) file. \n");
94 jTextArea
.setEditable(false);
100 * This method initializes jButtonCancel
102 * @return javax.swing.JButton
104 private JButton
getJButtonCancel() {
105 if (jButtonCancel
== null) {
106 jButtonCancel
= new JButton();
107 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
108 jButtonCancel
.setText("Cancel");
109 jButtonCancel
.addMouseListener(this);
111 return jButtonCancel
;
115 * This method initializes jButtonNext
117 * @return javax.swing.JButton
119 private JButton
getJButtonNext() {
120 if (jButtonNext
== null) {
121 jButtonNext
= new JButton();
122 jButtonNext
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
123 jButtonNext
.setText("Next");
124 jButtonNext
.addMouseListener(this);
130 * This method initializes jTextField
132 * @return javax.swing.JTextField
134 private JTextField
getJTextFieldFarFile() {
135 if (jTextFieldFarFile
== null) {
136 jTextFieldFarFile
= new JTextField();
137 jTextFieldFarFile
.setBounds(new java
.awt
.Rectangle(130, 80, 436, 20));
139 return jTextFieldFarFile
;
143 * This method initializes jButton
145 * @return javax.swing.JButton
147 private JButton
getJButtonBrowser() {
148 if (jButtonBrowser
== null) {
149 jButtonBrowser
= new JButton();
150 jButtonBrowser
.setBounds(new java
.awt
.Rectangle(570, 80, 100, 20));
151 jButtonBrowser
.setText("Browser...");
152 jButtonBrowser
.addMouseListener(this);
154 return jButtonBrowser
;
158 * This method initializes jScrollPane
160 * @return javax.swing.JScrollPane
162 private JScrollPane
getJScrollPane() {
163 if (jScrollPane
== null) {
164 jScrollPane
= new JScrollPane();
165 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 135, 642, 160));
166 jScrollPane
.setViewportView(getJListFarFromDb());
172 * This method initializes jListFarFromDb
174 * @return javax.swing.JList
176 private JList
getJListFarFromDb() {
177 if (jListFarFromDb
== null) {
178 jListFarFromDb
= new JList();
179 WorkspaceTools wt
= new WorkspaceTools();
180 farVector
= wt
.getAllFars();
181 jListFarFromDb
.setListData(farVector
);
182 jListFarFromDb
.setSelectionMode(0);
184 return jListFarFromDb
;
188 * This is the default constructor
190 public UpdateStepOne(IFrame iFrame
, boolean modal
) {
191 super(iFrame
, modal
);
196 * This method initializes this
200 private void initialize() {
201 this.setSize(700, 400);
202 this.setContentPane(getJContentPane());
203 this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");
204 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
205 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
209 * This method initializes jContentPane
211 * @return javax.swing.JPanel
213 private JPanel
getJContentPane() {
214 if (jContentPane
== null) {
215 jLabel1
= new JLabel();
216 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 110, 355, 18));
217 jLabel1
.setText("Choose FAR from current framework database");
218 jLabel
= new JLabel();
219 jLabel
.setBounds(new java
.awt
.Rectangle(30, 80, 97, 20));
220 jLabel
.setText("Choose FAR file: ");
221 jContentPane
= new JPanel();
222 jContentPane
.setLayout(null);
223 jContentPane
.add(getJTextArea(), null);
224 jContentPane
.add(getJButtonCancel(), null);
225 jContentPane
.add(getJButtonNext(), null);
226 jContentPane
.add(jLabel
, null);
227 jContentPane
.add(getJTextFieldFarFile(), null);
228 jContentPane
.add(getJButtonBrowser(), null);
229 jContentPane
.add(jLabel1
, null);
230 jContentPane
.add(getJScrollPane(), null);
235 public void mouseClicked(MouseEvent e
) {
236 if (e
.getSource() == jButtonCancel
) {
237 this.setVisible(false);
238 } else if (e
.getSource() == jButtonNext
) {
240 // Judge if FAR file is existed
242 farFile
= new File(jTextFieldFarFile
.getText());
243 if (!farFile
.exists() || !farFile
.isFile()) {
244 Log
.wrn("Update far", "Please choose a FAR file already exists. ");
249 // Judge FAR is valid
252 JarFile file
= new JarFile(farFile
);
253 this.far
= new Far(file
);
254 } catch (Exception ex
) {
255 Log
.wrn("Update far", ex
.getMessage());
256 Log
.err("Update far", ex
.getMessage());
260 // Add more logic process here
262 if (jListFarFromDb
.getSelectedValue() == null) {
263 Log
.wrn("Update far", "Please choose a FAR from framework database. ");
267 if (stepTwo
== null) {
268 stepTwo
= new UpdateStepTwo(this, true, this);
270 this.setVisible(false);
271 stepTwo
.prepareTable();
272 stepTwo
.setVisible(true);
273 } else if (e
.getSource() == jButtonBrowser
) {
274 JFileChooser fc
= new JFileChooser();
275 fc
.setAcceptAllFileFilterUsed(false);
276 fc
.addChoosableFileFilter(new IFileFilter(DataType
.FAR_SURFACE_AREA_EXT
));
277 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
279 int result
= fc
.showSaveDialog(new JPanel());
280 if (result
== JFileChooser
.APPROVE_OPTION
) {
281 this.jTextFieldFarFile
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(),
282 DataType
.RETURN_TYPE_FAR_SURFACE_AREA
));
287 public void mousePressed(MouseEvent e
) {
288 // TODO Auto-generated method stub
292 public void mouseReleased(MouseEvent e
) {
293 // TODO Auto-generated method stub
297 public void mouseEntered(MouseEvent e
) {
298 // TODO Auto-generated method stub
302 public void mouseExited(MouseEvent e
) {
303 // TODO Auto-generated method stub
307 public FarIdentification
getSelecedDbFar() {
308 return (FarIdentification
) jListFarFromDb
.getSelectedValue();
311 public Far
getFar() {