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