2 Java class PackagePkgHeader is GUI for create Package header 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
;
20 import java
.util
.Vector
;
22 import javax
.swing
.DefaultListModel
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JRadioButton
;
25 import javax
.swing
.JTextField
;
26 import javax
.swing
.JComboBox
;
27 import javax
.swing
.JLabel
;
28 import javax
.swing
.JList
;
29 import javax
.swing
.JScrollPane
;
30 import javax
.swing
.JButton
;
31 import javax
.swing
.JFrame
;
33 import org
.tianocore
.packaging
.common
.ui
.StarLabel
;
36 GUI for create Package header elements of spd file
38 @since PackageEditor 1.0
40 public class PackagePkgHeader
extends JFrame
implements ActionListener
{
41 private static String Separator
= "::";
43 private DefaultListModel listItem
= new DefaultListModel();
45 private SpdFileContents sfc
= null;
47 private JPanel jContentPane
= null;
49 private JRadioButton jRadioButtonAdd
= null;
51 private JRadioButton jRadioButtonSelect
= null;
53 private JTextField jTextFieldAdd
= null;
55 private JComboBox jComboBoxSelect
= null;
57 private JScrollPane jScrollPane
= null;
59 private JList jListLibraryClassDefinitions
= null;
61 private JButton jButtonAdd
= null;
63 private JButton jButtonRemove
= null;
65 private JButton jButtonClearAll
= null;
67 private JButton jButtonCancel
= null;
69 private JButton jButtonOk
= null;
71 private JLabel jLabel
= null;
73 private JTextField jTextField
= null;
75 private StarLabel starLabel
= null;
78 This method initializes this
81 private void initialize() {
82 this.setTitle("Package Headers");
83 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
88 This method initializes jRadioButtonAdd
90 @return javax.swing.JRadioButton
92 private JRadioButton
getJRadioButtonAdd() {
93 if (jRadioButtonAdd
== null) {
94 jRadioButtonAdd
= new JRadioButton();
95 jRadioButtonAdd
.setBounds(new java
.awt
.Rectangle(10, 35, 205, 20));
96 jRadioButtonAdd
.setText("Add a new Module Type");
97 jRadioButtonAdd
.setEnabled(false);
98 jRadioButtonAdd
.addActionListener(this);
99 jRadioButtonAdd
.setSelected(false);
101 return jRadioButtonAdd
;
105 This method initializes jRadioButtonSelect
107 @return javax.swing.JRadioButton
109 private JRadioButton
getJRadioButtonSelect() {
110 if (jRadioButtonSelect
== null) {
111 jRadioButtonSelect
= new JRadioButton();
112 jRadioButtonSelect
.setBounds(new java
.awt
.Rectangle(10, 10, 205, 20));
113 jRadioButtonSelect
.setText("Select an existed Module Type");
114 jRadioButtonSelect
.setActionCommand("Select an existed Module Type");
115 jRadioButtonSelect
.addActionListener(this);
116 jRadioButtonSelect
.setSelected(true);
118 return jRadioButtonSelect
;
122 This method initializes jTextFieldAdd
124 @return javax.swing.JTextField
126 private JTextField
getJTextFieldAdd() {
127 if (jTextFieldAdd
== null) {
128 jTextFieldAdd
= new JTextField();
129 jTextFieldAdd
.setBounds(new java
.awt
.Rectangle(220, 35, 260, 20));
130 jTextFieldAdd
.setEditable(false);
131 jTextFieldAdd
.setEnabled(false);
133 return jTextFieldAdd
;
137 This method initializes jComboBoxSelect
139 @return javax.swing.JComboBox
141 private JComboBox
getJComboBoxSelect() {
142 if (jComboBoxSelect
== null) {
143 jComboBoxSelect
= new JComboBox();
144 jComboBoxSelect
.setBounds(new java
.awt
.Rectangle(220, 10, 260, 20));
145 jComboBoxSelect
.setEnabled(true);
147 return jComboBoxSelect
;
151 This method initializes jScrollPane
153 @return javax.swing.JScrollPane
155 private JScrollPane
getJScrollPane() {
156 if (jScrollPane
== null) {
157 jScrollPane
= new JScrollPane();
158 jScrollPane
.setBounds(new java
.awt
.Rectangle(10, 121, 350, 174));
159 jScrollPane
.setViewportView(getJListLibraryClassDefinitions());
165 This method initializes jListLibraryClassDefinitions
167 @return javax.swing.JList
169 private JList
getJListLibraryClassDefinitions() {
170 if (jListLibraryClassDefinitions
== null) {
171 jListLibraryClassDefinitions
= new JList(listItem
);
173 return jListLibraryClassDefinitions
;
177 This method initializes jButtonAdd
179 @return javax.swing.JButton
181 private JButton
getJButtonAdd() {
182 if (jButtonAdd
== null) {
183 jButtonAdd
= new JButton();
184 jButtonAdd
.setBounds(new java
.awt
.Rectangle(375, 132, 90, 20));
185 jButtonAdd
.setText("Add");
186 jButtonAdd
.addActionListener(this);
192 This method initializes jButtonRemove
194 @return javax.swing.JButton
196 private JButton
getJButtonRemove() {
197 if (jButtonRemove
== null) {
198 jButtonRemove
= new JButton();
199 jButtonRemove
.setBounds(new java
.awt
.Rectangle(375, 230, 90, 20));
200 jButtonRemove
.setText("Remove");
201 jButtonRemove
.addActionListener(this);
203 return jButtonRemove
;
207 This method initializes jButtonRemoveAll
209 @return javax.swing.JButton
211 private JButton
getJButtonClearAll() {
212 if (jButtonClearAll
== null) {
213 jButtonClearAll
= new JButton();
214 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(375, 260, 90, 20));
215 jButtonClearAll
.setText("Clear All");
216 jButtonClearAll
.addActionListener(this);
218 return jButtonClearAll
;
222 This method initializes jButtonCancel
224 @return javax.swing.JButton
226 private JButton
getJButtonCancel() {
227 if (jButtonCancel
== null) {
228 jButtonCancel
= new JButton();
229 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
230 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
231 jButtonCancel
.setText("Cancel");
232 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
233 jButtonCancel
.addActionListener(this);
235 return jButtonCancel
;
239 This method initializes jButton
241 @return javax.swing.JButton
243 private JButton
getJButtonOk() {
244 if (jButtonOk
== null) {
245 jButtonOk
= new JButton();
246 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
247 jButtonOk
.setText("OK");
248 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
249 jButtonOk
.addActionListener(this);
255 This is the default constructor
257 public PackagePkgHeader(SpdFileContents sfc
) {
265 Start the window at the center of screen
268 protected void centerWindow(int intWidth
, int intHeight
) {
269 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
270 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
274 Start the window at the center of screen
277 protected void centerWindow() {
278 centerWindow(this.getSize().width
, this.getSize().height
);
281 // private void init(LibraryClassDefinitionsDocument.LibraryClassDefinitions inLibraryClassDefinitions) {
283 // this.setLibraryClassDefinitions(inLibraryClassDefinitions);
284 // int intLibraryCount = this.libraryClassDefinitions.getLibraryClassArray().length;
285 // if (intLibraryCount > 0) {
286 // for (int index = 0; index < intLibraryCount; index++) {
287 // listItem.addElement(this.libraryClassDefinitions.getLibraryClassArray(index).getUsage().toString() +
289 // this.libraryClassDefinitions.getLibraryClassArray(index).getStringValue());
290 // this.libraryClassDefinitions.getLibraryClassArray();
296 This method initializes this
300 private void init() {
301 this.setContentPane(getJContentPane());
302 this.setTitle("Library Class Declarations");
303 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
309 This method initializes jContentPane
311 @return javax.swing.JPanel
313 private JPanel
getJContentPane() {
314 if (jContentPane
== null) {
315 starLabel
= new StarLabel();
316 starLabel
.setBounds(new java
.awt
.Rectangle(5, 85, 10, 20));
317 jLabel
= new JLabel();
318 jLabel
.setBounds(new java
.awt
.Rectangle(14, 85, 201, 22));
319 jLabel
.setText("Include Header for Selected Type");
320 jContentPane
= new JPanel();
321 jContentPane
.setLayout(null);
322 jContentPane
.add(getJRadioButtonAdd(), null);
323 jContentPane
.add(getJRadioButtonSelect(), null);
324 jContentPane
.add(getJTextFieldAdd(), null);
325 jContentPane
.add(getJComboBoxSelect(), null);
326 jContentPane
.add(getJScrollPane(), null);
327 jContentPane
.add(getJButtonAdd(), null);
328 jContentPane
.add(getJButtonRemove(), null);
329 jContentPane
.add(getJButtonClearAll(), null);
330 jContentPane
.add(getJButtonCancel(), null);
331 jContentPane
.add(getJButtonOk(), null);
332 jContentPane
.add(jLabel
, null);
333 jContentPane
.add(getJTextField(), null);
334 jContentPane
.add(starLabel
, null);
339 private void initFrame() {
340 jComboBoxSelect
.addItem("BASE");
341 jComboBoxSelect
.addItem("SEC");
342 jComboBoxSelect
.addItem("PEI_CORE");
343 jComboBoxSelect
.addItem("PEIM");
344 jComboBoxSelect
.addItem("DXE_CORE");
345 jComboBoxSelect
.addItem("DXE_DRIVER");
346 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
347 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
348 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
349 jComboBoxSelect
.addItem("TOOLS");
350 jComboBoxSelect
.addItem("UEFI_DRIVER");
351 jComboBoxSelect
.addItem("UEFI_APPLICATION");
352 jComboBoxSelect
.addItem("USER_DEFINED");
356 public void actionPerformed(ActionEvent arg0
) {
357 if (arg0
.getSource() == jButtonOk
) {
362 if (arg0
.getSource() == jButtonCancel
) {
366 if (arg0
.getSource() == jButtonAdd
) {
367 String strLibClass
= "";
369 if (jRadioButtonAdd
.isSelected()) {
370 strLibClass
= jTextFieldAdd
.getText();
372 if (jRadioButtonSelect
.isSelected()) {
373 strLibClass
= jComboBoxSelect
.getSelectedItem().toString();
376 listItem
.addElement(jTextField
.getText().replace('\\', '/') + Separator
+ strLibClass
);
379 if (arg0
.getSource() == jButtonRemove
) {
380 int intSelected
[] = jListLibraryClassDefinitions
.getSelectedIndices();
381 if (intSelected
.length
> 0) {
382 for (int index
= intSelected
.length
- 1; index
> -1; index
--) {
383 listItem
.removeElementAt(intSelected
[index
]);
386 jListLibraryClassDefinitions
.getSelectionModel().clearSelection();
389 if (arg0
.getSource() == jButtonClearAll
) {
390 listItem
.removeAllElements();
393 if (arg0
.getSource() == jRadioButtonAdd
) {
394 if (jRadioButtonAdd
.isSelected()) {
395 jRadioButtonSelect
.setSelected(false);
396 jTextFieldAdd
.setEnabled(true);
397 jComboBoxSelect
.setEnabled(false);
399 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
400 jRadioButtonAdd
.setSelected(true);
401 jTextFieldAdd
.setEnabled(true);
402 jComboBoxSelect
.setEnabled(false);
406 if (arg0
.getSource() == jRadioButtonSelect
) {
407 if (jRadioButtonSelect
.isSelected()) {
408 jRadioButtonAdd
.setSelected(false);
409 jTextFieldAdd
.setEnabled(false);
410 jComboBoxSelect
.setEnabled(true);
412 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
413 jRadioButtonSelect
.setSelected(true);
414 jTextFieldAdd
.setEnabled(false);
415 jComboBoxSelect
.setEnabled(true);
420 private void save() {
422 int intLibraryCount
= listItem
.getSize();
424 if (intLibraryCount
> 0) {
426 for (int index
= 0; index
< intLibraryCount
; index
++) {
427 String strAll
= listItem
.get(index
).toString();
428 String strInclude
= strAll
.substring(0, strAll
.indexOf(Separator
));
429 String strType
= strAll
.substring(strAll
.indexOf(Separator
) + Separator
.length());
430 sfc
.genSpdModuleHeaders(strType
, strInclude
, null, null, null, null, null, null);
436 } catch (Exception e
) {
437 System
.out
.println(e
.toString());
442 This method initializes jTextField
444 @return javax.swing.JTextField
446 private JTextField
getJTextField() {
447 if (jTextField
== null) {
448 jTextField
= new JTextField();
449 jTextField
.setBounds(new java
.awt
.Rectangle(221, 86, 257, 21));