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, 100, 400, 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(542, 100, 97, 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(130, 164, 500, 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
);
183 return jListFarFromDb
;
187 * This is the default constructor
189 public UpdateStepOne(IFrame iFrame
, boolean modal
) {
190 super(iFrame
, modal
);
195 * This method initializes this
199 private void initialize() {
200 this.setSize(700, 400);
201 this.setContentPane(getJContentPane());
202 this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");
203 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
204 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
208 * This method initializes jContentPane
210 * @return javax.swing.JPanel
212 private JPanel
getJContentPane() {
213 if (jContentPane
== null) {
214 jLabel1
= new JLabel();
215 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 138, 355, 18));
216 jLabel1
.setText("Choose FAR from current framework database");
217 jLabel
= new JLabel();
218 jLabel
.setBounds(new java
.awt
.Rectangle(30, 80, 220, 20));
219 jLabel
.setText("Choose FAR file: ");
220 jContentPane
= new JPanel();
221 jContentPane
.setLayout(null);
222 jContentPane
.add(getJTextArea(), null);
223 jContentPane
.add(getJButtonCancel(), null);
224 jContentPane
.add(getJButtonNext(), null);
225 jContentPane
.add(jLabel
, null);
226 jContentPane
.add(getJTextFieldFarFile(), null);
227 jContentPane
.add(getJButtonBrowser(), null);
228 jContentPane
.add(jLabel1
, null);
229 jContentPane
.add(getJScrollPane(), null);
234 public void mouseClicked(MouseEvent e
) {
235 if (e
.getSource() == jButtonCancel
) {
236 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
.err("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
.err(ex
.getMessage());
260 // Add more logic process here
262 if (jListFarFromDb
.getSelectedValue() == null) {
263 Log
.err("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);
274 else if (e
.getSource() == jButtonBrowser
) {
275 JFileChooser fc
= new JFileChooser();
276 fc
.setAcceptAllFileFilterUsed(false);
277 fc
.addChoosableFileFilter(new IFileFilter(DataType
.FAR_SURFACE_AREA_EXT
));
278 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
280 int result
= fc
.showSaveDialog(new JPanel());
281 if (result
== JFileChooser
.APPROVE_OPTION
) {
282 this.jTextFieldFarFile
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(),
283 DataType
.RETURN_TYPE_FAR_SURFACE_AREA
));
288 public void mousePressed(MouseEvent e
) {
289 // TODO Auto-generated method stub
293 public void mouseReleased(MouseEvent e
) {
294 // TODO Auto-generated method stub
298 public void mouseEntered(MouseEvent e
) {
299 // TODO Auto-generated method stub
303 public void mouseExited(MouseEvent e
) {
304 // TODO Auto-generated method stub
308 public FarIdentification
getSelecedDbFar() {
309 return (FarIdentification
) jListFarFromDb
.getSelectedValue();
312 public Far
getFar() {