]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Java class UpdatePCD is GUI for update PCD definitions in spd file.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | package org.tianocore.packaging;\r | |
14 | \r | |
15 | import javax.swing.DefaultCellEditor;\r | |
16 | import javax.swing.JComboBox;\r | |
17 | import javax.swing.JPanel;\r | |
18 | import javax.swing.JFrame;\r | |
19 | import javax.swing.JLabel;\r | |
20 | import javax.swing.JTextField;\r | |
21 | import javax.swing.JButton;\r | |
22 | \r | |
23 | import javax.swing.JScrollPane;\r | |
24 | import javax.swing.JTable;\r | |
25 | import javax.swing.table.*;\r | |
26 | \r | |
27 | import org.tianocore.common.Tools;\r | |
28 | \r | |
24dba7f3 | 29 | import java.awt.Dimension;\r |
30 | import java.awt.Toolkit;\r | |
878ddf1f | 31 | import java.awt.event.ActionEvent;\r |
32 | import java.awt.event.ActionListener;\r | |
33 | import java.io.*;\r | |
34 | \r | |
35 | /**\r | |
36 | GUI for update PCD definitions in spd file\r | |
37 | \r | |
38 | @since PackageEditor 1.0\r | |
39 | **/\r | |
40 | public class UpdatePCD extends JFrame implements ActionListener {\r | |
41 | \r | |
42 | private JPanel jContentPane = null;\r | |
43 | \r | |
44 | private SpdFileContents sfc = null;\r | |
45 | \r | |
46 | private JButton jButtonOk = null;\r | |
47 | \r | |
48 | private JButton jButtonCancel = null;\r | |
49 | \r | |
50 | private DefaultTableModel model = null;\r | |
51 | \r | |
52 | private String[][] saa = null;\r | |
53 | \r | |
54 | private JScrollPane jScrollPane = null;\r | |
55 | \r | |
56 | private JTable jTable = null;\r | |
57 | \r | |
58 | private JButton jButton = null;\r | |
59 | \r | |
60 | /**\r | |
61 | This is the default constructor\r | |
62 | **/\r | |
63 | public UpdatePCD(SpdFileContents sfc) {\r | |
64 | super();\r | |
65 | this.sfc = sfc;\r | |
66 | initialize();\r | |
67 | \r | |
68 | }\r | |
69 | \r | |
70 | public void actionPerformed(ActionEvent arg0) {\r | |
71 | if (arg0.getSource() == jButtonOk) {\r | |
72 | this.save();\r | |
73 | this.dispose();\r | |
74 | \r | |
75 | }\r | |
76 | if (arg0.getSource() == jButtonCancel) {\r | |
77 | this.dispose();\r | |
78 | \r | |
79 | }\r | |
80 | if (arg0.getSource() == jButton) {\r | |
81 | String[] o = { "FEATURE_FLAG", "", "", "UINT8", "0" };\r | |
82 | model.addRow(o);\r | |
83 | }\r | |
84 | \r | |
85 | }\r | |
86 | \r | |
87 | /**\r | |
88 | This method initializes this\r | |
89 | \r | |
90 | @return void\r | |
91 | **/\r | |
92 | private void initialize() {\r | |
93 | this.setSize(916, 486);\r | |
94 | this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r | |
95 | this.setTitle("Update PCD Definitions");\r | |
96 | this.setContentPane(getJContentPane());\r | |
24dba7f3 | 97 | this.centerWindow();\r |
98 | }\r | |
99 | /**\r | |
100 | Start the window at the center of screen\r | |
101 | \r | |
102 | **/\r | |
103 | protected void centerWindow(int intWidth, int intHeight) {\r | |
104 | Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r | |
105 | this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);\r | |
878ddf1f | 106 | }\r |
107 | \r | |
24dba7f3 | 108 | /**\r |
109 | Start the window at the center of screen\r | |
110 | \r | |
111 | **/\r | |
112 | protected void centerWindow() {\r | |
113 | centerWindow(this.getSize().width, this.getSize().height);\r | |
114 | }\r | |
878ddf1f | 115 | /**\r |
116 | This method initializes jContentPane\r | |
117 | \r | |
118 | @return javax.swing.JPanel\r | |
119 | **/\r | |
120 | private JPanel getJContentPane() {\r | |
121 | if (jContentPane == null) {\r | |
122 | jContentPane = new JPanel();\r | |
123 | jContentPane.setLayout(null);\r | |
124 | jContentPane.add(getJButtonOk(), null);\r | |
125 | jContentPane.add(getJButtonCancel(), null);\r | |
126 | jContentPane.add(getJScrollPane(), null);\r | |
127 | jContentPane.add(getJButton(), null);\r | |
128 | }\r | |
129 | return jContentPane;\r | |
130 | }\r | |
131 | \r | |
132 | /**\r | |
133 | Remove original Pcd definitions before saving updated ones\r | |
134 | **/\r | |
135 | protected void save() {\r | |
ee19dec6 | 136 | if (jTable.isEditing()) {\r |
137 | jTable.getCellEditor().stopCellEditing();\r | |
138 | }\r | |
878ddf1f | 139 | sfc.removeSpdPcdDefinition();\r |
140 | int rowCount = model.getRowCount();\r | |
141 | int i = 0;\r | |
142 | while (i < rowCount) {\r | |
143 | String cName = null;\r | |
144 | if (model.getValueAt(i, 1) != null) {\r | |
145 | cName = model.getValueAt(i, 1).toString();\r | |
146 | }\r | |
147 | String token = null;\r | |
148 | if (model.getValueAt(i, 2) != null) {\r | |
149 | token = model.getValueAt(i, 2).toString();\r | |
150 | }\r | |
151 | String defaultVal = null;\r | |
152 | if (model.getValueAt(i, 4) != null) {\r | |
153 | defaultVal = model.getValueAt(i, 4).toString();\r | |
154 | }\r | |
155 | sfc.genSpdPcdDefinitions(model.getValueAt(i, 0).toString(), cName, token,\r | |
156 | model.getValueAt(i, 3).toString(), null, null, null, null, null, null, defaultVal);\r | |
157 | i++;\r | |
158 | }\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | This method initializes jButtonOk \r | |
163 | \r | |
164 | @return javax.swing.JButton \r | |
165 | **/\r | |
166 | private JButton getJButtonOk() {\r | |
167 | if (jButtonOk == null) {\r | |
168 | jButtonOk = new JButton();\r | |
169 | jButtonOk.setText("Ok");\r | |
170 | jButtonOk.setSize(new java.awt.Dimension(84, 20));\r | |
171 | jButtonOk.setLocation(new java.awt.Point(605, 404));\r | |
172 | jButtonOk.addActionListener(this);\r | |
173 | }\r | |
174 | return jButtonOk;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | This method initializes jButtonCancel \r | |
179 | \r | |
180 | @return javax.swing.JButton \r | |
181 | **/\r | |
182 | private JButton getJButtonCancel() {\r | |
183 | if (jButtonCancel == null) {\r | |
184 | jButtonCancel = new JButton();\r | |
185 | jButtonCancel.setText("Cancel");\r | |
186 | jButtonCancel.setSize(new java.awt.Dimension(82, 20));\r | |
187 | jButtonCancel.setLocation(new java.awt.Point(712, 404));\r | |
188 | jButtonCancel.addActionListener(this);\r | |
189 | }\r | |
190 | return jButtonCancel;\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | This method initializes jScrollPane \r | |
195 | \r | |
196 | @return javax.swing.JScrollPane \r | |
197 | **/\r | |
198 | private JScrollPane getJScrollPane() {\r | |
199 | if (jScrollPane == null) {\r | |
200 | jScrollPane = new JScrollPane();\r | |
201 | jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);\r | |
202 | jScrollPane.setBounds(new java.awt.Rectangle(51, 62, 782, 304));\r | |
203 | jScrollPane.setViewportView(getJTable2());\r | |
204 | }\r | |
205 | return jScrollPane;\r | |
206 | }\r | |
207 | \r | |
208 | /**\r | |
209 | This method initializes jTable \r | |
210 | \r | |
211 | @return javax.swing.JTable \r | |
212 | **/\r | |
213 | private JTable getJTable2() {\r | |
214 | if (jTable == null) {\r | |
215 | model = new DefaultTableModel();\r | |
216 | jTable = new JTable(model);\r | |
217 | jTable.setRowHeight(20);\r | |
218 | model.addColumn("ItemType");\r | |
219 | model.addColumn("C_Name");\r | |
220 | model.addColumn("Token");\r | |
221 | model.addColumn("DataType");\r | |
222 | model.addColumn("DefaultValue");\r | |
223 | //\r | |
224 | // Using combobox to display ItemType in table\r | |
225 | //\r | |
226 | JComboBox jComboBoxItemType = new JComboBox();\r | |
227 | jComboBoxItemType.addItem("FEATURE_FLAG");\r | |
228 | jComboBoxItemType.addItem("FIXED_AT_BUILD");\r | |
229 | jComboBoxItemType.addItem("PATCHABLE_IN_MODULE");\r | |
230 | jComboBoxItemType.addItem("DYNAMIC");\r | |
231 | jComboBoxItemType.addItem("DYNAMIC_EX");\r | |
232 | TableColumn itemTypeColumn = jTable.getColumnModel().getColumn(0);\r | |
233 | itemTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxItemType));\r | |
234 | //\r | |
235 | // Using combobox to display data type in table\r | |
236 | //\r | |
237 | JComboBox jComboBoxDataType = new JComboBox();\r | |
238 | jComboBoxDataType.addItem("UINT8");\r | |
239 | jComboBoxDataType.addItem("UINT16");\r | |
240 | jComboBoxDataType.addItem("UINT32");\r | |
241 | jComboBoxDataType.addItem("UINT64");\r | |
242 | jComboBoxDataType.addItem("VOID*");\r | |
243 | jComboBoxDataType.addItem("BOOLEAN");\r | |
244 | TableColumn dataTypeColumn = jTable.getColumnModel().getColumn(3);\r | |
245 | dataTypeColumn.setCellEditor(new DefaultCellEditor(jComboBoxDataType));\r | |
246 | \r | |
247 | if (sfc.getSpdPcdDefinitionCount() == 0) {\r | |
248 | \r | |
249 | return jTable;\r | |
250 | }\r | |
251 | saa = new String[sfc.getSpdPcdDefinitionCount()][5];\r | |
252 | sfc.getSpdPcdDefinitions(saa);\r | |
253 | int i = 0;\r | |
254 | while (i < saa.length) {\r | |
255 | model.addRow(saa[i]);\r | |
256 | i++;\r | |
257 | }\r | |
258 | \r | |
259 | }\r | |
260 | return jTable;\r | |
261 | }\r | |
262 | \r | |
263 | /**\r | |
264 | This method initializes jButton \r | |
265 | \r | |
266 | @return javax.swing.JButton \r | |
267 | **/\r | |
268 | private JButton getJButton() {\r | |
269 | if (jButton == null) {\r | |
270 | jButton = new JButton();\r | |
271 | jButton.setBounds(new java.awt.Rectangle(499, 404, 77, 20));\r | |
272 | jButton.setText("Insert");\r | |
273 | jButton.addActionListener(this);\r | |
274 | }\r | |
275 | return jButton;\r | |
276 | }\r | |
277 | } // @jve:decl-index=0:visual-constraint="11,7"\r |