]> 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@21 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
27import java.awt.event.ActionEvent;\r
28import java.awt.event.ActionListener;\r
29import java.io.*;\r
30\r
31/**\r
32 GUI for update protocol declarations in spd file\r
33 \r
34 @since PackageEditor 1.0\r
35**/\r
36public class UpdateProtocols extends JFrame implements ActionListener {\r
37\r
38 private JPanel jContentPane = null;\r
39\r
40 private JScrollPane jScrollPane = null;\r
41\r
42 private JTable jTable = 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 JButton jButton = null;\r
53\r
54 /**\r
55 This is the default constructor\r
56 **/\r
57 public UpdateProtocols(SpdFileContents sfc) {\r
58 super();\r
59 this.sfc = sfc;\r
60 initialize();\r
61\r
62 }\r
63\r
64 public void actionPerformed(ActionEvent arg0) {\r
65 if (arg0.getSource() == jButtonOk) {\r
66 this.save();\r
67 this.dispose();\r
68\r
69 }\r
70 if (arg0.getSource() == jButtonCancel) {\r
71 this.dispose();\r
72\r
73 }\r
74\r
75 if (arg0.getSource() == jButton) {\r
76 String[] o = { "", "", "" };\r
77 model.addRow(o);\r
78 }\r
79 }\r
80\r
81 /**\r
82 This method initializes this\r
83 \r
84 @return void\r
85 **/\r
86 private void initialize() {\r
87 this.setSize(604, 553);\r
88 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);\r
89 this.setTitle("Update Protocol Declarations");\r
90 this.setContentPane(getJContentPane());\r
91 }\r
92\r
93 /**\r
94 This method initializes jContentPane\r
95 \r
96 @return javax.swing.JPanel\r
97 **/\r
98 private JPanel getJContentPane() {\r
99 if (jContentPane == null) {\r
100 jContentPane = new JPanel();\r
101 jContentPane.setLayout(null);\r
102 jContentPane.add(getJScrollPane(), null);\r
103 jContentPane.add(getJButtonOk(), null);\r
104 jContentPane.add(getJButtonCancel(), null);\r
105 jContentPane.add(getJButton(), null);\r
106 }\r
107 return jContentPane;\r
108 }\r
109\r
110 /**\r
111 This method initializes jScrollPane \r
112 \r
113 @return javax.swing.JScrollPane \r
114 **/\r
115 private JScrollPane getJScrollPane() {\r
116 if (jScrollPane == null) {\r
117 jScrollPane = new JScrollPane();\r
118 jScrollPane.setBounds(new java.awt.Rectangle(38, 45, 453, 419));\r
119 jScrollPane.setViewportView(getJTable());\r
120 }\r
121 return jScrollPane;\r
122 }\r
123\r
124 /**\r
125 This method initializes jTable \r
126 \r
127 @return javax.swing.JTable \r
128 **/\r
129 private JTable getJTable() {\r
130 if (jTable == null) {\r
131 model = new DefaultTableModel();\r
132 jTable = new JTable(model);\r
133 jTable.setRowHeight(20);\r
134 model.addColumn("Name");\r
135 model.addColumn("C_Name");\r
136 model.addColumn("GUID");\r
137 //\r
138 // initialize table using SpdFileContents object\r
139 //\r
140 if (sfc.getSpdProtocolDeclarationCount() == 0) {\r
141 return jTable;\r
142 }\r
143 String[][] saa = new String[sfc.getSpdProtocolDeclarationCount()][3];\r
144 sfc.getSpdProtocolDeclarations(saa);\r
145 int i = 0;\r
146 while (i < saa.length) {\r
147 model.addRow(saa[i]);\r
148 i++;\r
149 }\r
150\r
151 }\r
152 return jTable;\r
153 }\r
154\r
155 /**\r
156 Remove original protocol declarations before saving updated ones\r
157 **/\r
158 protected void save() {\r
159 sfc.removeSpdProtocolDeclaration();\r
160 int rowCount = model.getRowCount();\r
161 int i = 0;\r
162 while (i < rowCount) {\r
163 String name = null;\r
164 if (model.getValueAt(i, 0) != null) {\r
165 name = model.getValueAt(i, 0).toString();\r
166 }\r
167 String cName = null;\r
168 if (model.getValueAt(i, 1) != null) {\r
169 cName = model.getValueAt(i, 1).toString();\r
170 }\r
171 String guid = null;\r
172 if (model.getValueAt(i, 2) != null) {\r
173 guid = model.getValueAt(i, 2).toString();\r
174 }\r
175 sfc.genSpdProtocolDeclarations(name, cName, guid, null);\r
176 i++;\r
177 }\r
178 }\r
179\r
180 /**\r
181 This method initializes jButtonOk \r
182 \r
183 @return javax.swing.JButton \r
184 **/\r
185 private JButton getJButtonOk() {\r
186 if (jButtonOk == null) {\r
187 jButtonOk = new JButton();\r
188 jButtonOk.setText("Ok");\r
189 jButtonOk.setSize(new java.awt.Dimension(84, 20));\r
190 jButtonOk.setLocation(new java.awt.Point(316, 486));\r
191 jButtonOk.addActionListener(this);\r
192 }\r
193 return jButtonOk;\r
194 }\r
195\r
196 /**\r
197 This method initializes jButtonCancel \r
198 \r
199 @return javax.swing.JButton \r
200 **/\r
201 private JButton getJButtonCancel() {\r
202 if (jButtonCancel == null) {\r
203 jButtonCancel = new JButton();\r
204 jButtonCancel.setText("Cancel");\r
205 jButtonCancel.setSize(new java.awt.Dimension(82, 20));\r
206 jButtonCancel.setLocation(new java.awt.Point(411, 486));\r
207 jButtonCancel.addActionListener(this);\r
208 }\r
209 return jButtonCancel;\r
210 }\r
211\r
212 /**\r
213 This method initializes jButton \r
214 \r
215 @return javax.swing.JButton \r
216 **/\r
217 private JButton getJButton() {\r
218 if (jButton == null) {\r
219 jButton = new JButton();\r
220 jButton.setBounds(new java.awt.Rectangle(232, 486, 71, 19));\r
221 jButton.setText("Insert");\r
222 jButton.addActionListener(this);\r
223 }\r
224 return jButton;\r
225 }\r
226} // @jve:decl-index=0:visual-constraint="11,7"\r