]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/UpdatePCD.java
Initial import.
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / UpdatePCD.java
1 /** @file
2 Java class UpdatePCD is GUI for update PCD definitions in spd file.
3
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
9
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.
12 **/
13 package org.tianocore.packaging;
14
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;
22
23 import javax.swing.JScrollPane;
24 import javax.swing.JTable;
25 import javax.swing.table.*;
26
27 import org.tianocore.common.Tools;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.io.*;
32
33 /**
34 GUI for update PCD definitions in spd file
35
36 @since PackageEditor 1.0
37 **/
38 public class UpdatePCD extends JFrame implements ActionListener {
39
40 private JPanel jContentPane = null;
41
42 private SpdFileContents sfc = null;
43
44 private JButton jButtonOk = null;
45
46 private JButton jButtonCancel = null;
47
48 private DefaultTableModel model = null;
49
50 private String[][] saa = null;
51
52 private JScrollPane jScrollPane = null;
53
54 private JTable jTable = null;
55
56 private JButton jButton = null;
57
58 /**
59 This is the default constructor
60 **/
61 public UpdatePCD(SpdFileContents sfc) {
62 super();
63 this.sfc = sfc;
64 initialize();
65
66 }
67
68 public void actionPerformed(ActionEvent arg0) {
69 if (arg0.getSource() == jButtonOk) {
70 this.save();
71 this.dispose();
72
73 }
74 if (arg0.getSource() == jButtonCancel) {
75 this.dispose();
76
77 }
78 if (arg0.getSource() == jButton) {
79 String[] o = { "FEATURE_FLAG", "", "", "UINT8", "0" };
80 model.addRow(o);
81 }
82
83 }
84
85 /**
86 This method initializes this
87
88 @return void
89 **/
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());
95 }
96
97 /**
98 This method initializes jContentPane
99
100 @return javax.swing.JPanel
101 **/
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);
110 }
111 return jContentPane;
112 }
113
114 /**
115 Remove original Pcd definitions before saving updated ones
116 **/
117 protected void save() {
118 sfc.removeSpdPcdDefinition();
119 int rowCount = model.getRowCount();
120 int i = 0;
121 while (i < rowCount) {
122 String cName = null;
123 if (model.getValueAt(i, 1) != null) {
124 cName = model.getValueAt(i, 1).toString();
125 }
126 String token = null;
127 if (model.getValueAt(i, 2) != null) {
128 token = model.getValueAt(i, 2).toString();
129 }
130 String defaultVal = null;
131 if (model.getValueAt(i, 4) != null) {
132 defaultVal = model.getValueAt(i, 4).toString();
133 }
134 sfc.genSpdPcdDefinitions(model.getValueAt(i, 0).toString(), cName, token,
135 model.getValueAt(i, 3).toString(), null, null, null, null, null, null, defaultVal);
136 i++;
137 }
138 }
139
140 /**
141 This method initializes jButtonOk
142
143 @return javax.swing.JButton
144 **/
145 private JButton getJButtonOk() {
146 if (jButtonOk == null) {
147 jButtonOk = new JButton();
148 jButtonOk.setText("Ok");
149 jButtonOk.setSize(new java.awt.Dimension(84, 20));
150 jButtonOk.setLocation(new java.awt.Point(605, 404));
151 jButtonOk.addActionListener(this);
152 }
153 return jButtonOk;
154 }
155
156 /**
157 This method initializes jButtonCancel
158
159 @return javax.swing.JButton
160 **/
161 private JButton getJButtonCancel() {
162 if (jButtonCancel == null) {
163 jButtonCancel = new JButton();
164 jButtonCancel.setText("Cancel");
165 jButtonCancel.setSize(new java.awt.Dimension(82, 20));
166 jButtonCancel.setLocation(new java.awt.Point(712, 404));
167 jButtonCancel.addActionListener(this);
168 }
169 return jButtonCancel;
170 }
171
172 /**
173 This method initializes jScrollPane
174
175 @return javax.swing.JScrollPane
176 **/
177 private JScrollPane getJScrollPane() {
178 if (jScrollPane == null) {
179 jScrollPane = new JScrollPane();
180 jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
181 jScrollPane.setBounds(new java.awt.Rectangle(51, 62, 782, 304));
182 jScrollPane.setViewportView(getJTable2());
183 }
184 return jScrollPane;
185 }
186
187 /**
188 This method initializes jTable
189
190 @return javax.swing.JTable
191 **/
192 private JTable getJTable2() {
193 if (jTable == null) {
194 model = new DefaultTableModel();
195 jTable = new JTable(model);
196 jTable.setRowHeight(20);
197 model.addColumn("ItemType");
198 model.addColumn("C_Name");
199 model.addColumn("Token");
200 model.addColumn("DataType");
201 model.addColumn("DefaultValue");
202 //
203 // Using combobox to display ItemType in table
204 //
205 JComboBox jComboBoxItemType = new JComboBox();
206 jComboBoxItemType.addItem("FEATURE_FLAG");
207 jComboBoxItemType.addItem("FIXED_AT_BUILD");
208 jComboBoxItemType.addItem("PATCHABLE_IN_MODULE");
209 jComboBoxItemType.addItem("DYNAMIC");
210 jComboBoxItemType.addItem("DYNAMIC_EX");
211 TableColumn itemTypeColumn = jTable.getColumnModel().getColumn(0);
212 itemTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxItemType));
213 //
214 // Using combobox to display data type in table
215 //
216 JComboBox jComboBoxDataType = new JComboBox();
217 jComboBoxDataType.addItem("UINT8");
218 jComboBoxDataType.addItem("UINT16");
219 jComboBoxDataType.addItem("UINT32");
220 jComboBoxDataType.addItem("UINT64");
221 jComboBoxDataType.addItem("VOID*");
222 jComboBoxDataType.addItem("BOOLEAN");
223 TableColumn dataTypeColumn = jTable.getColumnModel().getColumn(3);
224 dataTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxDataType));
225
226 if (sfc.getSpdPcdDefinitionCount() == 0) {
227
228 return jTable;
229 }
230 saa = new String[sfc.getSpdPcdDefinitionCount()][5];
231 sfc.getSpdPcdDefinitions(saa);
232 int i = 0;
233 while (i < saa.length) {
234 model.addRow(saa[i]);
235 i++;
236 }
237
238 }
239 return jTable;
240 }
241
242 /**
243 This method initializes jButton
244
245 @return javax.swing.JButton
246 **/
247 private JButton getJButton() {
248 if (jButton == null) {
249 jButton = new JButton();
250 jButton.setBounds(new java.awt.Rectangle(499, 404, 77, 20));
251 jButton.setText("Insert");
252 jButton.addActionListener(this);
253 }
254 return jButton;
255 }
256 } // @jve:decl-index=0:visual-constraint="11,7"