2 Java class UpdatePkgHeader is GUI for update Package Header in 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 javax
.swing
.DefaultCellEditor
;
16 import javax
.swing
.JComboBox
;
17 import javax
.swing
.JPanel
;
18 import javax
.swing
.JFrame
;
19 import javax
.swing
.JLabel
;
20 import javax
.swing
.JTextField
;
21 import javax
.swing
.JButton
;
23 import javax
.swing
.JScrollPane
;
24 import javax
.swing
.JTable
;
25 import javax
.swing
.table
.*;
27 import org
.tianocore
.common
.Tools
;
29 import java
.awt
.Dimension
;
30 import java
.awt
.Toolkit
;
31 import java
.awt
.event
.ActionEvent
;
32 import java
.awt
.event
.ActionListener
;
36 GUI for update Package Header in spd file
38 @since PackageEditor 1.0
40 public class UpdatePkgHeader
extends JFrame
implements ActionListener
{
42 private JPanel jContentPane
= null;
44 private JScrollPane jScrollPane
= null;
46 private JTable jTable
= null;
48 private SpdFileContents sfc
= null;
50 private JButton jButtonOk
= null;
52 private JButton jButtonCancel
= null;
54 private DefaultTableModel model
= null;
56 private JButton jButton
= null;
59 This is the default constructor
61 public UpdatePkgHeader(SpdFileContents sfc
) {
68 public void actionPerformed(ActionEvent arg0
) {
69 if (arg0
.getSource() == jButtonOk
) {
74 if (arg0
.getSource() == jButtonCancel
) {
79 if (arg0
.getSource() == jButton
) {
80 String
[] o
= { "BASE", "" };
86 This method initializes this
90 private void initialize() {
91 this.setSize(604, 553);
92 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
93 this.setTitle("Update Package Headers");
94 this.setContentPane(getJContentPane());
98 Start the window at the center of screen
101 protected void centerWindow(int intWidth
, int intHeight
) {
102 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
103 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
107 Start the window at the center of screen
110 protected void centerWindow() {
111 centerWindow(this.getSize().width
, this.getSize().height
);
114 This method initializes jContentPane
116 @return javax.swing.JPanel
118 private JPanel
getJContentPane() {
119 if (jContentPane
== null) {
120 jContentPane
= new JPanel();
121 jContentPane
.setLayout(null);
122 jContentPane
.add(getJScrollPane(), null);
123 jContentPane
.add(getJButtonOk(), null);
124 jContentPane
.add(getJButtonCancel(), null);
125 jContentPane
.add(getJButton(), null);
131 This method initializes jScrollPane
133 @return javax.swing.JScrollPane
135 private JScrollPane
getJScrollPane() {
136 if (jScrollPane
== null) {
137 jScrollPane
= new JScrollPane();
138 jScrollPane
.setBounds(new java
.awt
.Rectangle(38, 45, 453, 419));
139 jScrollPane
.setViewportView(getJTable());
145 This method initializes jTable
147 @return javax.swing.JTable
149 private JTable
getJTable() {
150 if (jTable
== null) {
151 model
= new DefaultTableModel();
152 jTable
= new JTable(model
);
153 jTable
.setRowHeight(20);
154 model
.addColumn("ModuleType");
155 model
.addColumn("IncludeHeader");
157 // Using combobox to display ModuleType in table
159 TableColumn typeColumn
= jTable
.getColumnModel().getColumn(0);
160 JComboBox jComboBoxSelect
= new JComboBox();
161 jComboBoxSelect
.addItem("BASE");
162 jComboBoxSelect
.addItem("SEC");
163 jComboBoxSelect
.addItem("PEI_CORE");
164 jComboBoxSelect
.addItem("PEIM");
165 jComboBoxSelect
.addItem("DXE_CORE");
166 jComboBoxSelect
.addItem("DXE_DRIVER");
167 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
168 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
169 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
170 jComboBoxSelect
.addItem("TOOLS");
171 jComboBoxSelect
.addItem("UEFI_DRIVER");
172 jComboBoxSelect
.addItem("UEFI_APPLICATION");
173 jComboBoxSelect
.addItem("USER_DEFINED");
174 typeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxSelect
));
176 if (sfc
.getSpdPackageHeaderCount() == 0) {
179 String
[][] saa
= new String
[sfc
.getSpdPackageHeaderCount()][2];
180 sfc
.getSpdPackageHeaders(saa
);
182 while (i
< saa
.length
) {
183 model
.addRow(saa
[i
]);
192 Remove original package headers before saving updated ones
194 protected void save() {
195 if (jTable
.isEditing()) {
196 jTable
.getCellEditor().stopCellEditing();
198 sfc
.removeSpdPkgHeader();
199 int rowCount
= model
.getRowCount();
201 while (i
< rowCount
) {
202 String headFile
= null;
203 if (model
.getValueAt(i
, 1) != null) {
204 headFile
= model
.getValueAt(i
, 1).toString();
206 sfc
.genSpdModuleHeaders(model
.getValueAt(i
, 0).toString(), headFile
, null, null, null, null, null, null);
212 This method initializes jButtonOk
214 @return javax.swing.JButton
216 private JButton
getJButtonOk() {
217 if (jButtonOk
== null) {
218 jButtonOk
= new JButton();
219 jButtonOk
.setText("Ok");
220 jButtonOk
.setSize(new java
.awt
.Dimension(84, 20));
221 jButtonOk
.setLocation(new java
.awt
.Point(316, 486));
222 jButtonOk
.addActionListener(this);
228 This method initializes jButtonCancel
230 @return javax.swing.JButton
232 private JButton
getJButtonCancel() {
233 if (jButtonCancel
== null) {
234 jButtonCancel
= new JButton();
235 jButtonCancel
.setText("Cancel");
236 jButtonCancel
.setSize(new java
.awt
.Dimension(82, 20));
237 jButtonCancel
.setLocation(new java
.awt
.Point(411, 486));
238 jButtonCancel
.addActionListener(this);
240 return jButtonCancel
;
244 This method initializes jButton
246 @return javax.swing.JButton
248 private JButton
getJButton() {
249 if (jButton
== null) {
250 jButton
= new JButton();
251 jButton
.setBounds(new java
.awt
.Rectangle(220, 486, 85, 20));
252 jButton
.setText("Insert");
253 jButton
.addActionListener(this);
257 } // @jve:decl-index=0:visual-constraint="11,7"