2 Java class UpdatePCD is GUI for update PCD definitions 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
.event
.ActionEvent
;
30 import java
.awt
.event
.ActionListener
;
34 GUI for update PCD definitions in spd file
36 @since PackageEditor 1.0
38 public class UpdatePCD
extends JFrame
implements ActionListener
{
40 private JPanel jContentPane
= null;
42 private SpdFileContents sfc
= null;
44 private JButton jButtonOk
= null;
46 private JButton jButtonCancel
= null;
48 private DefaultTableModel model
= null;
50 private String
[][] saa
= null;
52 private JScrollPane jScrollPane
= null;
54 private JTable jTable
= null;
56 private JButton jButton
= null;
59 This is the default constructor
61 public UpdatePCD(SpdFileContents sfc
) {
68 public void actionPerformed(ActionEvent arg0
) {
69 if (arg0
.getSource() == jButtonOk
) {
74 if (arg0
.getSource() == jButtonCancel
) {
78 if (arg0
.getSource() == jButton
) {
79 String
[] o
= { "FEATURE_FLAG", "", "", "UINT8", "0" };
86 This method initializes this
90 private void initialize() {
91 this.setSize(916, 486);
92 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
93 this.setTitle("Update PCD Definitions");
94 this.setContentPane(getJContentPane());
98 This method initializes jContentPane
100 @return javax.swing.JPanel
102 private JPanel
getJContentPane() {
103 if (jContentPane
== null) {
104 jContentPane
= new JPanel();
105 jContentPane
.setLayout(null);
106 jContentPane
.add(getJButtonOk(), null);
107 jContentPane
.add(getJButtonCancel(), null);
108 jContentPane
.add(getJScrollPane(), null);
109 jContentPane
.add(getJButton(), null);
115 Remove original Pcd definitions before saving updated ones
117 protected void save() {
118 if (jTable
.isEditing()) {
119 jTable
.getCellEditor().stopCellEditing();
121 sfc
.removeSpdPcdDefinition();
122 int rowCount
= model
.getRowCount();
124 while (i
< rowCount
) {
126 if (model
.getValueAt(i
, 1) != null) {
127 cName
= model
.getValueAt(i
, 1).toString();
130 if (model
.getValueAt(i
, 2) != null) {
131 token
= model
.getValueAt(i
, 2).toString();
133 String defaultVal
= null;
134 if (model
.getValueAt(i
, 4) != null) {
135 defaultVal
= model
.getValueAt(i
, 4).toString();
137 sfc
.genSpdPcdDefinitions(model
.getValueAt(i
, 0).toString(), cName
, token
,
138 model
.getValueAt(i
, 3).toString(), null, null, null, null, null, null, defaultVal
);
144 This method initializes jButtonOk
146 @return javax.swing.JButton
148 private JButton
getJButtonOk() {
149 if (jButtonOk
== null) {
150 jButtonOk
= new JButton();
151 jButtonOk
.setText("Ok");
152 jButtonOk
.setSize(new java
.awt
.Dimension(84, 20));
153 jButtonOk
.setLocation(new java
.awt
.Point(605, 404));
154 jButtonOk
.addActionListener(this);
160 This method initializes jButtonCancel
162 @return javax.swing.JButton
164 private JButton
getJButtonCancel() {
165 if (jButtonCancel
== null) {
166 jButtonCancel
= new JButton();
167 jButtonCancel
.setText("Cancel");
168 jButtonCancel
.setSize(new java
.awt
.Dimension(82, 20));
169 jButtonCancel
.setLocation(new java
.awt
.Point(712, 404));
170 jButtonCancel
.addActionListener(this);
172 return jButtonCancel
;
176 This method initializes jScrollPane
178 @return javax.swing.JScrollPane
180 private JScrollPane
getJScrollPane() {
181 if (jScrollPane
== null) {
182 jScrollPane
= new JScrollPane();
183 jScrollPane
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
184 jScrollPane
.setBounds(new java
.awt
.Rectangle(51, 62, 782, 304));
185 jScrollPane
.setViewportView(getJTable2());
191 This method initializes jTable
193 @return javax.swing.JTable
195 private JTable
getJTable2() {
196 if (jTable
== null) {
197 model
= new DefaultTableModel();
198 jTable
= new JTable(model
);
199 jTable
.setRowHeight(20);
200 model
.addColumn("ItemType");
201 model
.addColumn("C_Name");
202 model
.addColumn("Token");
203 model
.addColumn("DataType");
204 model
.addColumn("DefaultValue");
206 // Using combobox to display ItemType in table
208 JComboBox jComboBoxItemType
= new JComboBox();
209 jComboBoxItemType
.addItem("FEATURE_FLAG");
210 jComboBoxItemType
.addItem("FIXED_AT_BUILD");
211 jComboBoxItemType
.addItem("PATCHABLE_IN_MODULE");
212 jComboBoxItemType
.addItem("DYNAMIC");
213 jComboBoxItemType
.addItem("DYNAMIC_EX");
214 TableColumn itemTypeColumn
= jTable
.getColumnModel().getColumn(0);
215 itemTypeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxItemType
));
217 // Using combobox to display data type in table
219 JComboBox jComboBoxDataType
= new JComboBox();
220 jComboBoxDataType
.addItem("UINT8");
221 jComboBoxDataType
.addItem("UINT16");
222 jComboBoxDataType
.addItem("UINT32");
223 jComboBoxDataType
.addItem("UINT64");
224 jComboBoxDataType
.addItem("VOID*");
225 jComboBoxDataType
.addItem("BOOLEAN");
226 TableColumn dataTypeColumn
= jTable
.getColumnModel().getColumn(3);
227 dataTypeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxDataType
));
229 if (sfc
.getSpdPcdDefinitionCount() == 0) {
233 saa
= new String
[sfc
.getSpdPcdDefinitionCount()][5];
234 sfc
.getSpdPcdDefinitions(saa
);
236 while (i
< saa
.length
) {
237 model
.addRow(saa
[i
]);
246 This method initializes jButton
248 @return javax.swing.JButton
250 private JButton
getJButton() {
251 if (jButton
== null) {
252 jButton
= new JButton();
253 jButton
.setBounds(new java
.awt
.Rectangle(499, 404, 77, 20));
254 jButton
.setText("Insert");
255 jButton
.addActionListener(this);
259 } // @jve:decl-index=0:visual-constraint="11,7"