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