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
.Dimension
;
30 import java
.awt
.Toolkit
;
31 import java
.awt
.event
.ActionEvent
;
32 import java
.awt
.event
.ActionListener
;
36 GUI for update PCD definitions in spd file
38 @since PackageEditor 1.0
40 public class UpdatePCD
extends JFrame
implements ActionListener
{
42 private JPanel jContentPane
= null;
44 private SpdFileContents sfc
= null;
46 private JButton jButtonOk
= null;
48 private JButton jButtonCancel
= null;
50 private DefaultTableModel model
= null;
52 private String
[][] saa
= null;
54 private JScrollPane jScrollPane
= null;
56 private JTable jTable
= null;
58 private JButton jButton
= null;
61 This is the default constructor
63 public UpdatePCD(SpdFileContents sfc
) {
70 public void actionPerformed(ActionEvent arg0
) {
71 if (arg0
.getSource() == jButtonOk
) {
76 if (arg0
.getSource() == jButtonCancel
) {
80 if (arg0
.getSource() == jButton
) {
81 String
[] o
= { "FEATURE_FLAG", "", "", "UINT8", "0" };
88 This method initializes this
92 private void initialize() {
93 this.setSize(916, 486);
94 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
95 this.setTitle("Update PCD Definitions");
96 this.setContentPane(getJContentPane());
100 Start the window at the center of screen
103 protected void centerWindow(int intWidth
, int intHeight
) {
104 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
105 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
109 Start the window at the center of screen
112 protected void centerWindow() {
113 centerWindow(this.getSize().width
, this.getSize().height
);
116 This method initializes jContentPane
118 @return javax.swing.JPanel
120 private JPanel
getJContentPane() {
121 if (jContentPane
== null) {
122 jContentPane
= new JPanel();
123 jContentPane
.setLayout(null);
124 jContentPane
.add(getJButtonOk(), null);
125 jContentPane
.add(getJButtonCancel(), null);
126 jContentPane
.add(getJScrollPane(), null);
127 jContentPane
.add(getJButton(), null);
133 Remove original Pcd definitions before saving updated ones
135 protected void save() {
136 if (jTable
.isEditing()) {
137 jTable
.getCellEditor().stopCellEditing();
139 sfc
.removeSpdPcdDefinition();
140 int rowCount
= model
.getRowCount();
142 while (i
< rowCount
) {
144 if (model
.getValueAt(i
, 1) != null) {
145 cName
= model
.getValueAt(i
, 1).toString();
148 if (model
.getValueAt(i
, 2) != null) {
149 token
= model
.getValueAt(i
, 2).toString();
151 String defaultVal
= null;
152 if (model
.getValueAt(i
, 4) != null) {
153 defaultVal
= model
.getValueAt(i
, 4).toString();
155 sfc
.genSpdPcdDefinitions(model
.getValueAt(i
, 0).toString(), cName
, token
,
156 model
.getValueAt(i
, 3).toString(), null, null, null, null, null, null, defaultVal
);
162 This method initializes jButtonOk
164 @return javax.swing.JButton
166 private JButton
getJButtonOk() {
167 if (jButtonOk
== null) {
168 jButtonOk
= new JButton();
169 jButtonOk
.setText("Ok");
170 jButtonOk
.setSize(new java
.awt
.Dimension(84, 20));
171 jButtonOk
.setLocation(new java
.awt
.Point(605, 404));
172 jButtonOk
.addActionListener(this);
178 This method initializes jButtonCancel
180 @return javax.swing.JButton
182 private JButton
getJButtonCancel() {
183 if (jButtonCancel
== null) {
184 jButtonCancel
= new JButton();
185 jButtonCancel
.setText("Cancel");
186 jButtonCancel
.setSize(new java
.awt
.Dimension(82, 20));
187 jButtonCancel
.setLocation(new java
.awt
.Point(712, 404));
188 jButtonCancel
.addActionListener(this);
190 return jButtonCancel
;
194 This method initializes jScrollPane
196 @return javax.swing.JScrollPane
198 private JScrollPane
getJScrollPane() {
199 if (jScrollPane
== null) {
200 jScrollPane
= new JScrollPane();
201 jScrollPane
.setHorizontalScrollBarPolicy(javax
.swing
.JScrollPane
.HORIZONTAL_SCROLLBAR_AS_NEEDED
);
202 jScrollPane
.setBounds(new java
.awt
.Rectangle(51, 62, 782, 304));
203 jScrollPane
.setViewportView(getJTable2());
209 This method initializes jTable
211 @return javax.swing.JTable
213 private JTable
getJTable2() {
214 if (jTable
== null) {
215 model
= new DefaultTableModel();
216 jTable
= new JTable(model
);
217 jTable
.setRowHeight(20);
218 model
.addColumn("ItemType");
219 model
.addColumn("C_Name");
220 model
.addColumn("Token");
221 model
.addColumn("DataType");
222 model
.addColumn("DefaultValue");
224 // Using combobox to display ItemType in table
226 JComboBox jComboBoxItemType
= new JComboBox();
227 jComboBoxItemType
.addItem("FEATURE_FLAG");
228 jComboBoxItemType
.addItem("FIXED_AT_BUILD");
229 jComboBoxItemType
.addItem("PATCHABLE_IN_MODULE");
230 jComboBoxItemType
.addItem("DYNAMIC");
231 jComboBoxItemType
.addItem("DYNAMIC_EX");
232 TableColumn itemTypeColumn
= jTable
.getColumnModel().getColumn(0);
233 itemTypeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxItemType
));
235 // Using combobox to display data type in table
237 JComboBox jComboBoxDataType
= new JComboBox();
238 jComboBoxDataType
.addItem("UINT8");
239 jComboBoxDataType
.addItem("UINT16");
240 jComboBoxDataType
.addItem("UINT32");
241 jComboBoxDataType
.addItem("UINT64");
242 jComboBoxDataType
.addItem("VOID*");
243 jComboBoxDataType
.addItem("BOOLEAN");
244 TableColumn dataTypeColumn
= jTable
.getColumnModel().getColumn(3);
245 dataTypeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxDataType
));
247 if (sfc
.getSpdPcdDefinitionCount() == 0) {
251 saa
= new String
[sfc
.getSpdPcdDefinitionCount()][5];
252 sfc
.getSpdPcdDefinitions(saa
);
254 while (i
< saa
.length
) {
255 model
.addRow(saa
[i
]);
264 This method initializes jButton
266 @return javax.swing.JButton
268 private JButton
getJButton() {
269 if (jButton
== null) {
270 jButton
= new JButton();
271 jButton
.setBounds(new java
.awt
.Rectangle(499, 404, 77, 20));
272 jButton
.setText("Insert");
273 jButton
.addActionListener(this);
277 } // @jve:decl-index=0:visual-constraint="11,7"