]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/PackageEditor/src/org/tianocore/packaging/UpdateProtocols.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / UpdateProtocols.java
CommitLineData
878ddf1f 1/** @file\r
2 Java class UpdateProtocols is GUI for update protocol declarations in spd file.\r
3 \r
4Copyright (c) 2006, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13package org.tianocore.packaging;\r
14\r
15import javax.swing.JPanel;\r
16import javax.swing.JFrame;\r
17import javax.swing.JLabel;\r
18import javax.swing.JTextField;\r
19import javax.swing.JButton;\r
20\r
21import javax.swing.JScrollPane;\r
22import javax.swing.JTable;\r
23import javax.swing.table.*;\r
24\r
25import org.tianocore.common.Tools;\r
26\r
24dba7f3 27import java.awt.Dimension;\r
28import java.awt.Toolkit;\r
878ddf1f 29import java.awt.event.ActionEvent;\r
30import java.awt.event.ActionListener;\r
31import java.io.*;\r
32\r
33/**\r
34 GUI for update protocol declarations in spd file\r
35 \r
36 @since PackageEditor 1.0\r
37**/\r
38public class UpdateProtocols extends JFrame implements ActionListener {\r
39\r
40 private JPanel jContentPane = null;\r
41\r
42 private JScrollPane jScrollPane = null;\r
43\r
44 private JTable jTable = null;\r
45\r
46 private SpdFileContents sfc = null;\r
47\r
48 private JButton jButtonOk = null;\r
49\r
50 private JButton jButtonCancel = null;\r
51\r
52 private DefaultTableModel model = null;\r
53\r
54 private JButton jButton = null;\r
55\r
56 /**\r
57 This is the default constructor\r
58 **/\r
59 public UpdateProtocols(SpdFileContents sfc) {\r
60 super();\r
61 this.sfc = sfc;\r
62 initialize();\r
63\r
64 }\r
65\r
66 public void actionPerformed(ActionEvent arg0) {\r
67 if (arg0.getSource() == jButtonOk) {\r
68 this.save();\r
69 this.dispose();\r
70\r
71 }\r
72 if (arg0.getSource() == jButtonCancel) {\r
73 this.dispose();\r
74\r
75 }\r
76\r
77 if (arg0.getSource() == jButton) {\r
78 String[] o = { "", "", "" };\r
79 model.addRow(o);\r
80 }\r
81 }\r
82\r
83 /**\r
84 This method initializes this\r
85 \r
86 @return void\r
87 **/\r
88 private void initialize() {\r
89 this.setSize(604, 553);\r
90 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
91 this.setTitle("Update Protocol Declarations");\r
92 this.setContentPane(getJContentPane());\r
24dba7f3 93 this.centerWindow();\r
878ddf1f 94 }\r
95\r
24dba7f3 96 /**\r
97 Start the window at the center of screen\r
98 \r
99 **/\r
100 protected void centerWindow(int intWidth, int intHeight) {\r
101 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();\r
102 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);\r
103 }\r
104\r
105 /**\r
106 Start the window at the center of screen\r
107 \r
108 **/\r
109 protected void centerWindow() {\r
110 centerWindow(this.getSize().width, this.getSize().height);\r
111 }\r
878ddf1f 112 /**\r
113 This method initializes jContentPane\r
114 \r
115 @return javax.swing.JPanel\r
116 **/\r
117 private JPanel getJContentPane() {\r
118 if (jContentPane == null) {\r
119 jContentPane = new JPanel();\r
120 jContentPane.setLayout(null);\r
121 jContentPane.add(getJScrollPane(), null);\r
122 jContentPane.add(getJButtonOk(), null);\r
123 jContentPane.add(getJButtonCancel(), null);\r
124 jContentPane.add(getJButton(), null);\r
125 }\r
126 return jContentPane;\r
127 }\r
128\r
129 /**\r
130 This method initializes jScrollPane \r
131 \r
132 @return javax.swing.JScrollPane \r
133 **/\r
134 private JScrollPane getJScrollPane() {\r
135 if (jScrollPane == null) {\r
136 jScrollPane = new JScrollPane();\r
137 jScrollPane.setBounds(new java.awt.Rectangle(38, 45, 453, 419));\r
138 jScrollPane.setViewportView(getJTable());\r
139 }\r
140 return jScrollPane;\r
141 }\r
142\r
143 /**\r
144 This method initializes jTable \r
145 \r
146 @return javax.swing.JTable \r
147 **/\r
148 private JTable getJTable() {\r
149 if (jTable == null) {\r
150 model = new DefaultTableModel();\r
151 jTable = new JTable(model);\r
152 jTable.setRowHeight(20);\r
153 model.addColumn("Name");\r
154 model.addColumn("C_Name");\r
155 model.addColumn("GUID");\r
156 //\r
157 // initialize table using SpdFileContents object\r
158 //\r
159 if (sfc.getSpdProtocolDeclarationCount() == 0) {\r
160 return jTable;\r
161 }\r
162 String[][] saa = new String[sfc.getSpdProtocolDeclarationCount()][3];\r
163 sfc.getSpdProtocolDeclarations(saa);\r
164 int i = 0;\r
165 while (i < saa.length) {\r
166 model.addRow(saa[i]);\r
167 i++;\r
168 }\r
169\r
24dba7f3 170 jTable.getColumnModel().getColumn(2).setCellEditor(new GuidEditor());\r
171\r
878ddf1f 172 }\r
173 return jTable;\r
174 }\r
175\r
176 /**\r
177 Remove original protocol declarations before saving updated ones\r
178 **/\r
179 protected void save() {\r
ee19dec6 180 if (jTable.isEditing()) {\r
181 jTable.getCellEditor().stopCellEditing();\r
182 }\r
878ddf1f 183 sfc.removeSpdProtocolDeclaration();\r
184 int rowCount = model.getRowCount();\r
185 int i = 0;\r
186 while (i < rowCount) {\r
187 String name = null;\r
188 if (model.getValueAt(i, 0) != null) {\r
189 name = model.getValueAt(i, 0).toString();\r
190 }\r
191 String cName = null;\r
192 if (model.getValueAt(i, 1) != null) {\r
193 cName = model.getValueAt(i, 1).toString();\r
194 }\r
195 String guid = null;\r
196 if (model.getValueAt(i, 2) != null) {\r
197 guid = model.getValueAt(i, 2).toString();\r
198 }\r
199 sfc.genSpdProtocolDeclarations(name, cName, guid, null);\r
200 i++;\r
201 }\r
202 }\r
203\r
204 /**\r
205 This method initializes jButtonOk \r
206 \r
207 @return javax.swing.JButton \r
208 **/\r
209 private JButton getJButtonOk() {\r
210 if (jButtonOk == null) {\r
211 jButtonOk = new JButton();\r
212 jButtonOk.setText("Ok");\r
213 jButtonOk.setSize(new java.awt.Dimension(84, 20));\r
214 jButtonOk.setLocation(new java.awt.Point(316, 486));\r
215 jButtonOk.addActionListener(this);\r
216 }\r
217 return jButtonOk;\r
218 }\r
219\r
220 /**\r
221 This method initializes jButtonCancel \r
222 \r
223 @return javax.swing.JButton \r
224 **/\r
225 private JButton getJButtonCancel() {\r
226 if (jButtonCancel == null) {\r
227 jButtonCancel = new JButton();\r
228 jButtonCancel.setText("Cancel");\r
229 jButtonCancel.setSize(new java.awt.Dimension(82, 20));\r
230 jButtonCancel.setLocation(new java.awt.Point(411, 486));\r
231 jButtonCancel.addActionListener(this);\r
232 }\r
233 return jButtonCancel;\r
234 }\r
235\r
236 /**\r
237 This method initializes jButton \r
238 \r
239 @return javax.swing.JButton \r
240 **/\r
241 private JButton getJButton() {\r
242 if (jButton == null) {\r
243 jButton = new JButton();\r
244 jButton.setBounds(new java.awt.Rectangle(232, 486, 71, 19));\r
245 jButton.setText("Insert");\r
246 jButton.addActionListener(this);\r
247 }\r
248 return jButton;\r
249 }\r
250} // @jve:decl-index=0:visual-constraint="11,7"\r