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
;
35 import javax
.swing
.filechooser
.FileFilter
;
38 GUI for create MsaFile elements of spd file
40 @since PackageEditor 1.0
42 public class PackageMsaFile
extends JFrame
implements ActionListener
{
45 private DefaultListModel listItem
= new DefaultListModel();
47 private SpdFileContents sfc
= null;
49 private JPanel jContentPane
= null;
51 private JScrollPane jScrollPane
= null;
53 private JList jListLibraryClassDefinitions
= null;
55 private JButton jButtonAdd
= null;
57 private JButton jButtonRemove
= null;
59 private JButton jButtonClearAll
= null;
61 private JButton jButtonCancel
= null;
63 private JButton jButtonOk
= null;
65 private JLabel jLabel
= null;
67 private JTextField jTextField
= null;
69 private JButton jButton
= null;
72 This method initializes this
75 private void initialize() {
76 this.setTitle("MSA Files");
77 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
82 This method initializes jScrollPane
84 @return javax.swing.JScrollPane
86 private JScrollPane
getJScrollPane() {
87 if (jScrollPane
== null) {
88 jScrollPane
= new JScrollPane();
89 jScrollPane
.setBounds(new java
.awt
.Rectangle(10, 85, 350, 210));
90 jScrollPane
.setViewportView(getJListLibraryClassDefinitions());
96 This method initializes jListLibraryClassDefinitions
98 @return javax.swing.JList
100 private JList
getJListLibraryClassDefinitions() {
101 if (jListLibraryClassDefinitions
== null) {
102 jListLibraryClassDefinitions
= new JList(listItem
);
104 return jListLibraryClassDefinitions
;
108 This method initializes jButtonAdd
110 @return javax.swing.JButton
112 private JButton
getJButtonAdd() {
113 if (jButtonAdd
== null) {
114 jButtonAdd
= new JButton();
115 jButtonAdd
.setBounds(new java
.awt
.Rectangle(375, 132, 90, 20));
116 jButtonAdd
.setText("Add");
117 jButtonAdd
.addActionListener(this);
123 This method initializes jButtonRemove
125 @return javax.swing.JButton
127 private JButton
getJButtonRemove() {
128 if (jButtonRemove
== null) {
129 jButtonRemove
= new JButton();
130 jButtonRemove
.setBounds(new java
.awt
.Rectangle(375, 230, 90, 20));
131 jButtonRemove
.setText("Remove");
132 jButtonRemove
.addActionListener(this);
134 return jButtonRemove
;
138 This method initializes jButtonRemoveAll
140 @return javax.swing.JButton
142 private JButton
getJButtonClearAll() {
143 if (jButtonClearAll
== null) {
144 jButtonClearAll
= new JButton();
145 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(375, 260, 90, 20));
146 jButtonClearAll
.setText("Clear All");
147 jButtonClearAll
.addActionListener(this);
149 return jButtonClearAll
;
153 This method initializes jButtonCancel
155 @return javax.swing.JButton
157 private JButton
getJButtonCancel() {
158 if (jButtonCancel
== null) {
159 jButtonCancel
= new JButton();
160 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
161 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
162 jButtonCancel
.setText("Cancel");
163 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
164 jButtonCancel
.addActionListener(this);
166 return jButtonCancel
;
170 This method initializes jButton
172 @return javax.swing.JButton
174 private JButton
getJButtonOk() {
175 if (jButtonOk
== null) {
176 jButtonOk
= new JButton();
177 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
178 jButtonOk
.setText("OK");
179 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
180 jButtonOk
.addActionListener(this);
186 This is the default constructor
188 public PackageMsaFile(SpdFileContents sfc
) {
196 Start the window at the center of screen
199 protected void centerWindow(int intWidth
, int intHeight
) {
200 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
201 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
205 Start the window at the center of screen
208 protected void centerWindow() {
209 centerWindow(this.getSize().width
, this.getSize().height
);
213 This method initializes this
217 private void init() {
218 this.setContentPane(getJContentPane());
219 this.setTitle("Library Class Declarations");
220 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
226 This method initializes jContentPane
228 @return javax.swing.JPanel
230 private JPanel
getJContentPane() {
231 if (jContentPane
== null) {
232 jLabel
= new JLabel();
233 jLabel
.setBounds(new java
.awt
.Rectangle(11,20,143,22));
234 jLabel
.setText("Msa File Path and Name");
235 jContentPane
= new JPanel();
236 jContentPane
.setLayout(null);
237 jContentPane
.add(getJScrollPane(), null);
238 jContentPane
.add(getJButtonAdd(), null);
239 jContentPane
.add(getJButtonRemove(), null);
240 jContentPane
.add(getJButtonClearAll(), null);
241 jContentPane
.add(getJButtonCancel(), null);
242 jContentPane
.add(getJButtonOk(), null);
243 jContentPane
.add(jLabel
, null);
244 jContentPane
.add(getJTextField(), null);
245 jContentPane
.add(getJButton(), null);
250 private void initFrame() {
254 public void actionPerformed(ActionEvent arg0
) {
255 if (arg0
.getSource() == jButtonOk
) {
259 if (arg0
.getSource() == jButtonCancel
) {
263 if (arg0
.getSource() == jButtonAdd
) {
265 listItem
.addElement(jTextField
.getText());
268 if (arg0
.getSource() == jButtonRemove
) {
269 int intSelected
[] = jListLibraryClassDefinitions
.getSelectedIndices();
270 if (intSelected
.length
> 0) {
271 for (int index
= intSelected
.length
- 1; index
> -1; index
--) {
272 listItem
.removeElementAt(intSelected
[index
]);
275 jListLibraryClassDefinitions
.getSelectionModel().clearSelection();
278 if (arg0
.getSource() == jButtonClearAll
) {
279 listItem
.removeAllElements();
284 protected void save() {
286 int intLibraryCount
= listItem
.getSize();
288 if (intLibraryCount
> 0) {
290 for (int index
= 0; index
< intLibraryCount
; index
++) {
291 String strAll
= listItem
.get(index
).toString();
292 sfc
.genSpdMsaFiles(strAll
, null);
298 } catch (Exception e
) {
299 System
.out
.println(e
.toString());
304 This method initializes jTextField
306 @return javax.swing.JTextField
308 private JTextField
getJTextField() {
309 if (jTextField
== null) {
310 jTextField
= new JTextField();
311 jTextField
.setBounds(new java
.awt
.Rectangle(11,44,349,21));
317 This method initializes jButton
319 @return javax.swing.JButton
321 private JButton
getJButton() {
322 final FileFilter filter
= new PkgFileFilter("msa");
324 if (jButton
== null) {
325 jButton
= new JButton();
326 jButton
.setBounds(new java
.awt
.Rectangle(377,46,89,20));
327 jButton
.setText("Browse");
328 jButton
.setPreferredSize(new java
.awt
.Dimension(34,20));
329 jButton
.addMouseListener(new java
.awt
.event
.MouseAdapter() {
330 public void mouseClicked(java
.awt
.event
.MouseEvent e
) {
331 JFileChooser chooser
= new JFileChooser(System
.getenv("WORKSPACE"));
333 String msaDest
= null;
335 chooser
.setMultiSelectionEnabled(false);
336 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
337 chooser
.setFileFilter(filter
);
338 int retval
= chooser
.showOpenDialog(frame
);
339 if (retval
== JFileChooser
.APPROVE_OPTION
) {
341 theFile
= chooser
.getSelectedFile();
342 String file
= theFile
.getPath();
343 if (!file
.startsWith(System
.getenv("WORKSPACE"))) {
344 JOptionPane
.showMessageDialog(frame
, "You can only select files in current workspace!");
353 if (!theFile
.getPath().startsWith(PackagingMain
.dirForNewSpd
)) {
355 //ToDo: copy elsewhere msa to new pkg dir, prompt user to chooser a location
357 JOptionPane
.showMessageDialog(frame
, "You must copy msa file into current package directory!");
361 msaDest
= theFile
.getPath();
362 int fileIndex
= msaDest
.indexOf(System
.getProperty("file.separator"), PackagingMain
.dirForNewSpd
.length());
364 jTextField
.setText(msaDest
.substring(fileIndex
+ 1).replace('\\', '/'));