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
;
23 import javax
.swing
.JFileChooser
;
24 import javax
.swing
.JPanel
;
25 import javax
.swing
.JTextArea
;
26 import javax
.swing
.JButton
;
27 import javax
.swing
.JLabel
;
28 import javax
.swing
.JTextField
;
30 import org
.tianocore
.frameworkwizard
.common
.DataType
;
31 import org
.tianocore
.frameworkwizard
.common
.IFileFilter
;
32 import org
.tianocore
.frameworkwizard
.common
.Log
;
33 import org
.tianocore
.frameworkwizard
.common
.Tools
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IDialog
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.IFrame
;
36 import org
.tianocore
.frameworkwizard
.far
.Far
;
37 import org
.tianocore
.frameworkwizard
.far
.FarIdentification
;
38 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
39 import org
.tianocore
.frameworkwizard
.workspace
.WorkspaceTools
;
41 import javax
.swing
.JScrollPane
;
42 import javax
.swing
.JList
;
44 public class UpdateStepOne
extends IDialog
implements MouseListener
{
49 private static final long serialVersionUID
= 735554907464539931L;
51 private JPanel jContentPane
= null;
53 private JTextArea jTextArea
= null;
55 private JButton jButtonCancel
= null;
57 private JButton jButtonNext
= null;
59 private JLabel jLabel
= null;
61 private JTextField jTextFieldFarFile
= null;
63 private JButton jButtonBrowser
= null;
65 private UpdateStepTwo stepTwo
= null;
67 private Far far
= null;
69 private Vector
<FarIdentification
> farVector
= null;
71 private JLabel jLabel1
= null;
73 private JScrollPane jScrollPane
= null;
75 private JList jListFarFromDb
= null;
77 private File farFile
= null;
79 public File
getFarFile() {
84 * This method initializes jTextArea
86 * @return javax.swing.JTextArea
88 private JTextArea
getJTextArea() {
89 if (jTextArea
== null) {
90 jTextArea
= new JTextArea();
91 jTextArea
.setBounds(new java
.awt
.Rectangle(30, 7, 642, 50));
92 jTextArea
.setText("Step 1: Choose framework archive (FAR) file. \n");
93 jTextArea
.setEditable(false);
99 * This method initializes jButtonCancel
101 * @return javax.swing.JButton
103 private JButton
getJButtonCancel() {
104 if (jButtonCancel
== null) {
105 jButtonCancel
= new JButton();
106 jButtonCancel
.setBounds(new java
.awt
.Rectangle(570, 330, 90, 20));
107 jButtonCancel
.setText("Cancel");
108 jButtonCancel
.addMouseListener(this);
110 return jButtonCancel
;
114 * This method initializes jButtonNext
116 * @return javax.swing.JButton
118 private JButton
getJButtonNext() {
119 if (jButtonNext
== null) {
120 jButtonNext
= new JButton();
121 jButtonNext
.setBounds(new java
.awt
.Rectangle(470, 330, 90, 20));
122 jButtonNext
.setText("Next");
123 jButtonNext
.addMouseListener(this);
129 * This method initializes jTextField
131 * @return javax.swing.JTextField
133 private JTextField
getJTextFieldFarFile() {
134 if (jTextFieldFarFile
== null) {
135 jTextFieldFarFile
= new JTextField();
136 jTextFieldFarFile
.setBounds(new java
.awt
.Rectangle(130, 100, 400, 20));
138 return jTextFieldFarFile
;
142 * This method initializes jButton
144 * @return javax.swing.JButton
146 private JButton
getJButtonBrowser() {
147 if (jButtonBrowser
== null) {
148 jButtonBrowser
= new JButton();
149 jButtonBrowser
.setBounds(new java
.awt
.Rectangle(542, 100, 97, 20));
150 jButtonBrowser
.setText("Browser...");
151 jButtonBrowser
.addMouseListener(this);
153 return jButtonBrowser
;
157 * This method initializes jScrollPane
159 * @return javax.swing.JScrollPane
161 private JScrollPane
getJScrollPane() {
162 if (jScrollPane
== null) {
163 jScrollPane
= new JScrollPane();
164 jScrollPane
.setBounds(new java
.awt
.Rectangle(130, 164, 500, 160));
165 jScrollPane
.setViewportView(getJListFarFromDb());
171 * This method initializes jListFarFromDb
173 * @return javax.swing.JList
175 private JList
getJListFarFromDb() {
176 if (jListFarFromDb
== null) {
177 jListFarFromDb
= new JList();
178 WorkspaceTools wt
= new WorkspaceTools();
179 farVector
= wt
.getAllFars();
180 jListFarFromDb
.setListData(farVector
);
182 return jListFarFromDb
;
186 * This is the default constructor
188 public UpdateStepOne(IFrame iFrame
, boolean modal
) {
189 super(iFrame
, modal
);
194 * This method initializes this
198 private void initialize() {
199 this.setSize(700, 400);
200 this.setContentPane(getJContentPane());
201 this.setTitle("Update Framework Archive(FAR) - Step 1: Choose FAR File");
202 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
203 this.setLocation((d
.width
- this.getSize().width
) / 2, (d
.height
- this.getSize().height
) / 2);
207 * This method initializes jContentPane
209 * @return javax.swing.JPanel
211 private JPanel
getJContentPane() {
212 if (jContentPane
== null) {
213 jLabel1
= new JLabel();
214 jLabel1
.setBounds(new java
.awt
.Rectangle(30, 138, 355, 18));
215 jLabel1
.setText("Choose FAR from current framework database");
216 jLabel
= new JLabel();
217 jLabel
.setBounds(new java
.awt
.Rectangle(30, 80, 220, 20));
218 jLabel
.setText("Choose FAR file: ");
219 jContentPane
= new JPanel();
220 jContentPane
.setLayout(null);
221 jContentPane
.add(getJTextArea(), null);
222 jContentPane
.add(getJButtonCancel(), null);
223 jContentPane
.add(getJButtonNext(), null);
224 jContentPane
.add(jLabel
, null);
225 jContentPane
.add(getJTextFieldFarFile(), null);
226 jContentPane
.add(getJButtonBrowser(), null);
227 jContentPane
.add(jLabel1
, null);
228 jContentPane
.add(getJScrollPane(), null);
233 public void mouseClicked(MouseEvent e
) {
234 if (e
.getSource() == jButtonCancel
) {
235 this.setVisible(false);
236 } else if (e
.getSource() == jButtonNext
) {
238 // Judge if FAR file is existed
240 farFile
= new File(jTextFieldFarFile
.getText());
241 if (!farFile
.exists() || !farFile
.isFile()) {
242 Log
.err("Please choose a FAR file already exists. ");
247 // Judge FAR is valid
251 // Add more logic process here
253 if (jListFarFromDb
.getSelectedValue() == null) {
254 Log
.err("Please choose a FAR from framework database. ");
258 if (stepTwo
== null) {
259 stepTwo
= new UpdateStepTwo(this, true, this);
261 this.setVisible(false);
262 stepTwo
.prepareTable();
263 stepTwo
.setVisible(true);
264 } else if (e
.getSource() == jButtonBrowser
) {
265 JFileChooser fc
= new JFileChooser();
266 fc
.setAcceptAllFileFilterUsed(false);
267 fc
.addChoosableFileFilter(new IFileFilter(DataType
.FAR_SURFACE_AREA_EXT
));
268 fc
.setCurrentDirectory(new File(Workspace
.getCurrentWorkspace()));
270 int result
= fc
.showSaveDialog(new JPanel());
271 if (result
== JFileChooser
.APPROVE_OPTION
) {
272 this.jTextFieldFarFile
.setText(Tools
.addPathExt(fc
.getSelectedFile().getPath(),
273 DataType
.RETURN_TYPE_FAR_SURFACE_AREA
));
278 public void mousePressed(MouseEvent e
) {
279 // TODO Auto-generated method stub
283 public void mouseReleased(MouseEvent e
) {
284 // TODO Auto-generated method stub
288 public void mouseEntered(MouseEvent e
) {
289 // TODO Auto-generated method stub
293 public void mouseExited(MouseEvent e
) {
294 // TODO Auto-generated method stub
298 public FarIdentification
getSelecedDbFar() {
299 return (FarIdentification
) jListFarFromDb
.getSelectedValue();
302 public Far
getFar() {