2 Java class PackageMsaFile is GUI for create MsaFile elements of spd file.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.packaging
;
15 import java
.awt
.BorderLayout
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
18 import java
.awt
.event
.ActionEvent
;
19 import java
.awt
.event
.ActionListener
;
21 import java
.util
.Vector
;
23 import javax
.swing
.DefaultListModel
;
24 import javax
.swing
.JFileChooser
;
25 import javax
.swing
.JOptionPane
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JRadioButton
;
28 import javax
.swing
.JTextField
;
29 import javax
.swing
.JComboBox
;
30 import javax
.swing
.JLabel
;
31 import javax
.swing
.JList
;
32 import javax
.swing
.JScrollPane
;
33 import javax
.swing
.JButton
;
34 import javax
.swing
.JFrame
;
37 GUI for create MsaFile elements of spd file
39 @since PackageEditor 1.0
41 public class PackageMsaFile
extends JFrame
implements ActionListener
{
44 private DefaultListModel listItem
= new DefaultListModel();
46 private SpdFileContents sfc
= null;
48 private JPanel jContentPane
= null;
50 private JScrollPane jScrollPane
= null;
52 private JList jListLibraryClassDefinitions
= null;
54 private JButton jButtonAdd
= null;
56 private JButton jButtonRemove
= null;
58 private JButton jButtonClearAll
= null;
60 private JButton jButtonCancel
= null;
62 private JButton jButtonOk
= null;
64 private JLabel jLabel
= null;
66 private JTextField jTextField
= null;
68 private JButton jButton
= null;
71 This method initializes this
74 private void initialize() {
75 this.setTitle("MSA Files");
76 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
81 This method initializes jScrollPane
83 @return javax.swing.JScrollPane
85 private JScrollPane
getJScrollPane() {
86 if (jScrollPane
== null) {
87 jScrollPane
= new JScrollPane();
88 jScrollPane
.setBounds(new java
.awt
.Rectangle(10, 85, 350, 210));
89 jScrollPane
.setViewportView(getJListLibraryClassDefinitions());
95 This method initializes jListLibraryClassDefinitions
97 @return javax.swing.JList
99 private JList
getJListLibraryClassDefinitions() {
100 if (jListLibraryClassDefinitions
== null) {
101 jListLibraryClassDefinitions
= new JList(listItem
);
103 return jListLibraryClassDefinitions
;
107 This method initializes jButtonAdd
109 @return javax.swing.JButton
111 private JButton
getJButtonAdd() {
112 if (jButtonAdd
== null) {
113 jButtonAdd
= new JButton();
114 jButtonAdd
.setBounds(new java
.awt
.Rectangle(375, 132, 90, 20));
115 jButtonAdd
.setText("Add");
116 jButtonAdd
.addActionListener(this);
122 This method initializes jButtonRemove
124 @return javax.swing.JButton
126 private JButton
getJButtonRemove() {
127 if (jButtonRemove
== null) {
128 jButtonRemove
= new JButton();
129 jButtonRemove
.setBounds(new java
.awt
.Rectangle(375, 230, 90, 20));
130 jButtonRemove
.setText("Remove");
131 jButtonRemove
.addActionListener(this);
133 return jButtonRemove
;
137 This method initializes jButtonRemoveAll
139 @return javax.swing.JButton
141 private JButton
getJButtonClearAll() {
142 if (jButtonClearAll
== null) {
143 jButtonClearAll
= new JButton();
144 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(375, 260, 90, 20));
145 jButtonClearAll
.setText("Clear All");
146 jButtonClearAll
.addActionListener(this);
148 return jButtonClearAll
;
152 This method initializes jButtonCancel
154 @return javax.swing.JButton
156 private JButton
getJButtonCancel() {
157 if (jButtonCancel
== null) {
158 jButtonCancel
= new JButton();
159 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
160 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
161 jButtonCancel
.setText("Cancel");
162 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
163 jButtonCancel
.addActionListener(this);
165 return jButtonCancel
;
169 This method initializes jButton
171 @return javax.swing.JButton
173 private JButton
getJButtonOk() {
174 if (jButtonOk
== null) {
175 jButtonOk
= new JButton();
176 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
177 jButtonOk
.setText("OK");
178 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
179 jButtonOk
.addActionListener(this);
185 This is the default constructor
187 public PackageMsaFile(SpdFileContents sfc
) {
195 Start the window at the center of screen
198 protected void centerWindow(int intWidth
, int intHeight
) {
199 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
200 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
204 Start the window at the center of screen
207 protected void centerWindow() {
208 centerWindow(this.getSize().width
, this.getSize().height
);
212 This method initializes this
216 private void init() {
217 this.setContentPane(getJContentPane());
218 this.setTitle("Library Class Declarations");
219 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
225 This method initializes jContentPane
227 @return javax.swing.JPanel
229 private JPanel
getJContentPane() {
230 if (jContentPane
== null) {
231 jLabel
= new JLabel();
232 jLabel
.setBounds(new java
.awt
.Rectangle(11,20,143,22));
233 jLabel
.setText("Msa File Path and Name");
234 jContentPane
= new JPanel();
235 jContentPane
.setLayout(null);
236 jContentPane
.add(getJScrollPane(), null);
237 jContentPane
.add(getJButtonAdd(), null);
238 jContentPane
.add(getJButtonRemove(), null);
239 jContentPane
.add(getJButtonClearAll(), null);
240 jContentPane
.add(getJButtonCancel(), null);
241 jContentPane
.add(getJButtonOk(), null);
242 jContentPane
.add(jLabel
, null);
243 jContentPane
.add(getJTextField(), null);
244 jContentPane
.add(getJButton(), null);
249 private void initFrame() {
253 public void actionPerformed(ActionEvent arg0
) {
254 if (arg0
.getSource() == jButtonOk
) {
258 if (arg0
.getSource() == jButtonCancel
) {
262 if (arg0
.getSource() == jButtonAdd
) {
264 listItem
.addElement(jTextField
.getText());
267 if (arg0
.getSource() == jButtonRemove
) {
268 int intSelected
[] = jListLibraryClassDefinitions
.getSelectedIndices();
269 if (intSelected
.length
> 0) {
270 for (int index
= intSelected
.length
- 1; index
> -1; index
--) {
271 listItem
.removeElementAt(intSelected
[index
]);
274 jListLibraryClassDefinitions
.getSelectionModel().clearSelection();
277 if (arg0
.getSource() == jButtonClearAll
) {
278 listItem
.removeAllElements();
283 protected void save() {
285 int intLibraryCount
= listItem
.getSize();
287 if (intLibraryCount
> 0) {
289 for (int index
= 0; index
< intLibraryCount
; index
++) {
290 String strAll
= listItem
.get(index
).toString();
291 sfc
.genSpdMsaFiles(strAll
, null);
297 } catch (Exception e
) {
298 System
.out
.println(e
.toString());
303 This method initializes jTextField
305 @return javax.swing.JTextField
307 private JTextField
getJTextField() {
308 if (jTextField
== null) {
309 jTextField
= new JTextField();
310 jTextField
.setBounds(new java
.awt
.Rectangle(11,44,349,21));
316 This method initializes jButton
318 @return javax.swing.JButton
320 private JButton
getJButton() {
321 if (jButton
== null) {
322 jButton
= new JButton();
323 jButton
.setBounds(new java
.awt
.Rectangle(377,46,89,20));
324 jButton
.setText("Browse");
325 jButton
.setPreferredSize(new java
.awt
.Dimension(34,20));
326 jButton
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
327 public void mouseClicked(java
.awt
.event
.MouseEvent e
) {
328 JFileChooser chooser
= new JFileChooser(System
.getenv("WORKSPACE"));
330 chooser
.setMultiSelectionEnabled(false);
331 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
332 chooser
.setFileFilter(new PkgFileFilter("msa"));
333 int retval
= chooser
.showOpenDialog(frame
);
334 if (retval
== JFileChooser
.APPROVE_OPTION
) {
336 File theFile
= chooser
.getSelectedFile();
337 String file
= theFile
.getPath();
338 if (!file
.startsWith(System
.getenv("WORKSPACE"))) {
339 JOptionPane
.showMessageDialog(frame
, "You can only select files in current workspace!");
342 int fileIndex
= file
.indexOf(System
.getProperty("file.separator"), System
.getenv("WORKSPACE").length() + 1);
343 jTextField
.setText(file
.substring(fileIndex
+ 1));