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
.far
.FarStringDefinition
;
40 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
41 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
43 import javax
.swing
.JScrollPane
;
44 import javax
.swing
.JList
;
46 public class UpdateStepOne
extends IDialog
implements MouseListener
{
51 private static final long serialVersionUID
= 735554907464539931L;
53 private JPanel jContentPane
= null;
55 private JTextArea jTextArea
= null;
57 private JButton jButtonCancel
= null;
59 private JButton jButtonNext
= null;
61 private JLabel jLabel
= null;
63 private JTextField jTextFieldFarFile
= null;
65 private JButton jButtonBrowser
= null;
67 private UpdateStepTwo stepTwo
= null;
69 private Far far
= null;
71 private Vector
<FarIdentification
> farVector
= null;
73 private JLabel jLabel1
= null;
75 private JScrollPane jScrollPane
= null;
77 private JList jListFarFromDb
= null;
79 private File farFile
= null;
81 public File
getFarFile() {
86 * This method initializes jTextArea
88 * @return javax.swing.JTextArea
90 private JTextArea
getJTextArea() {
91 if (jTextArea
== null) {
92 jTextArea
= new JTextArea();
93 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
94 jTextArea
.setText("Step 1: Choose framework archive (FAR) file. \n");
95 jTextArea
.setEditable(false);
101 * This method initializes jButtonCancel
103 * @return javax.swing.JButton
105 private JButton
getJButtonCancel() {
106 if (jButtonCancel
== null) {
107 jButtonCancel
= new JButton();
108 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
109 jButtonCancel
.setText("Cancel");
110 jButtonCancel
.addMouseListener(this);
112 return jButtonCancel
;
116 * This method initializes jButtonNext
118 * @return javax.swing.JButton
120 private JButton
getJButtonNext() {
121 if (jButtonNext
== null) {
122 jButtonNext
= new JButton();
123 jButtonNext
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
124 jButtonNext
.setText("Next");
125 jButtonNext
.addMouseListener(this);
131 * This method initializes jTextField
133 * @return javax.swing.JTextField
135 private JTextField
getJTextFieldFarFile() {
136 if (jTextFieldFarFile
== null) {
137 jTextFieldFarFile
= new JTextField();
138 jTextFieldFarFile
.setBounds(new java
.awt
.Rectangle(130, 80, 436, 20));
140 return jTextFieldFarFile
;
144 * This method initializes jButton
146 * @return javax.swing.JButton
148 private JButton
getJButtonBrowser() {
149 if (jButtonBrowser
== null) {
150 jButtonBrowser
= new JButton();
151 jButtonBrowser
.setBounds(new java
.awt
.Rectangle(570, 80, 100, 20));
152 jButtonBrowser
.setText("Browser...");
153 jButtonBrowser
.addMouseListener(this);
155 return jButtonBrowser
;
159 * This method initializes jScrollPane
161 * @return javax.swing.JScrollPane
163 private JScrollPane
getJScrollPane() {
164 if (jScrollPane
== null) {
165 jScrollPane
= new JScrollPane();
166 jScrollPane
.setBounds(new java
.awt
.Rectangle(30, 135, 642, 160));
167 jScrollPane
.setViewportView(getJListFarFromDb());
173 * This method initializes jListFarFromDb
175 * @return javax.swing.JList
177 private JList
getJListFarFromDb() {
178 if (jListFarFromDb
== null) {
179 jListFarFromDb
= new JList();
180 WorkspaceTools wt
= new WorkspaceTools();
181 farVector
= wt
.getAllFars();
182 jListFarFromDb
.setListData(farVector
);
183 jListFarFromDb
.setSelectionMode(0);
185 return jListFarFromDb
;
189 * This is the default constructor
191 public UpdateStepOne(IFrame iFrame
, boolean modal
) {
192 super(iFrame
, modal
);
197 * This method initializes this
201 private void initialize() {
202 this.setSize(700, 400);
203 this.setContentPane(getJContentPane());
204 this.setTitle(FarStringDefinition
.UPDATE_STEP_ONE_TITLE
);
205 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
206 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
210 * This method initializes jContentPane
212 * @return javax.swing.JPanel
214 private JPanel
getJContentPane() {
215 if (jContentPane
== null) {
216 jLabel1
= new JLabel();
217 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 110, 355, 18));
218 jLabel1
.setText("Choose FAR from current WORKSPACE.");
219 jLabel
= new JLabel();
220 jLabel
.setBounds(new java
.awt
.Rectangle(30, 80, 97, 20));
221 jLabel
.setText("Choose FAR file: ");
222 jContentPane
= new JPanel();
223 jContentPane
.setLayout(null);
224 jContentPane
.add(getJTextArea(), null);
225 jContentPane
.add(getJButtonCancel(), null);
226 jContentPane
.add(getJButtonNext(), null);
227 jContentPane
.add(jLabel
, null);
228 jContentPane
.add(getJTextFieldFarFile(), null);
229 jContentPane
.add(getJButtonBrowser(), null);
230 jContentPane
.add(jLabel1
, null);
231 jContentPane
.add(getJScrollPane(), null);
236 public void mouseClicked(MouseEvent e
) {
237 if (e
.getSource() == jButtonCancel
) {
238 this.setVisible(false);
239 } else if (e
.getSource() == jButtonNext
) {
241 // Judge if FAR file is existed
243 farFile
= new File(jTextFieldFarFile
.getText());
244 if (!farFile
.exists() || !farFile
.isFile()) {
245 Log
.wrn("Update far", "Please choose a FAR file that already exists.");
250 // Judge FAR is valid
253 JarFile file
= new JarFile(farFile
);
254 this.far
= new Far(file
);
255 } catch (Exception ex
) {
256 Log
.wrn("Update far", ex
.getMessage());
257 Log
.err("Update far", ex
.getMessage());
261 // Add more logic process here
263 if (jListFarFromDb
.getSelectedValue() == null) {
264 Log
.wrn("Update far", "Please choose a FAR from current WORKSPACE.");
268 if (stepTwo
== null) {
269 stepTwo
= new UpdateStepTwo(this, true, this);
271 this.setVisible(false);
272 stepTwo
.prepareTable();
273 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
.showOpenDialog(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() {