]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/UpdatePkgHeader.java
Initial import.
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / UpdatePkgHeader.java
1 /** @file
2 Java class UpdatePkgHeader is GUI for update Package Header 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.DefaultCellEditor;
16 import javax.swing.JComboBox;
17 import javax.swing.JPanel;
18 import javax.swing.JFrame;
19 import javax.swing.JLabel;
20 import javax.swing.JTextField;
21 import javax.swing.JButton;
22
23 import javax.swing.JScrollPane;
24 import javax.swing.JTable;
25 import javax.swing.table.*;
26
27 import org.tianocore.common.Tools;
28
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31 import java.io.*;
32
33 /**
34 GUI for update Package Header in spd file
35
36 @since PackageEditor 1.0
37 **/
38 public class UpdatePkgHeader 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 UpdatePkgHeader(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 = { "BASE", "" };
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 Package Headers");
92 this.setContentPane(getJContentPane());
93 }
94
95 /**
96 This method initializes jContentPane
97
98 @return javax.swing.JPanel
99 **/
100 private JPanel getJContentPane() {
101 if (jContentPane == null) {
102 jContentPane = new JPanel();
103 jContentPane.setLayout(null);
104 jContentPane.add(getJScrollPane(), null);
105 jContentPane.add(getJButtonOk(), null);
106 jContentPane.add(getJButtonCancel(), null);
107 jContentPane.add(getJButton(), null);
108 }
109 return jContentPane;
110 }
111
112 /**
113 This method initializes jScrollPane
114
115 @return javax.swing.JScrollPane
116 **/
117 private JScrollPane getJScrollPane() {
118 if (jScrollPane == null) {
119 jScrollPane = new JScrollPane();
120 jScrollPane.setBounds(new java.awt.Rectangle(38, 45, 453, 419));
121 jScrollPane.setViewportView(getJTable());
122 }
123 return jScrollPane;
124 }
125
126 /**
127 This method initializes jTable
128
129 @return javax.swing.JTable
130 **/
131 private JTable getJTable() {
132 if (jTable == null) {
133 model = new DefaultTableModel();
134 jTable = new JTable(model);
135 jTable.setRowHeight(20);
136 model.addColumn("ModuleType");
137 model.addColumn("IncludeHeader");
138 //
139 // Using combobox to display ModuleType in table
140 //
141 TableColumn typeColumn = jTable.getColumnModel().getColumn(0);
142 JComboBox jComboBoxSelect = new JComboBox();
143 jComboBoxSelect.addItem("BASE");
144 jComboBoxSelect.addItem("SEC");
145 jComboBoxSelect.addItem("PEI_CORE");
146 jComboBoxSelect.addItem("PEIM");
147 jComboBoxSelect.addItem("DXE_CORE");
148 jComboBoxSelect.addItem("DXE_DRIVER");
149 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");
150 jComboBoxSelect.addItem("DXE_SAL_DRIVER");
151 jComboBoxSelect.addItem("DXE_SMM_DRIVER");
152 jComboBoxSelect.addItem("TOOLS");
153 jComboBoxSelect.addItem("UEFI_DRIVER");
154 jComboBoxSelect.addItem("UEFI_APPLICATION");
155 jComboBoxSelect.addItem("USER_DEFINED");
156 typeColumn.setCellEditor(new DefaultCellEditor(jComboBoxSelect));
157
158 if (sfc.getSpdPackageHeaderCount() == 0) {
159 return jTable;
160 }
161 String[][] saa = new String[sfc.getSpdPackageHeaderCount()][2];
162 sfc.getSpdPackageHeaders(saa);
163 int i = 0;
164 while (i < saa.length) {
165 model.addRow(saa[i]);
166 i++;
167 }
168
169 }
170 return jTable;
171 }
172
173 /**
174 Remove original package headers before saving updated ones
175 **/
176 protected void save() {
177 sfc.removeSpdPkgHeader();
178 int rowCount = model.getRowCount();
179 int i = 0;
180 while (i < rowCount) {
181 String headFile = null;
182 if (model.getValueAt(i, 1) != null) {
183 headFile = model.getValueAt(i, 1).toString();
184 }
185 sfc.genSpdModuleHeaders(model.getValueAt(i, 0).toString(), headFile, null, null, null, null, null, null);
186 i++;
187 }
188 }
189
190 /**
191 This method initializes jButtonOk
192
193 @return javax.swing.JButton
194 **/
195 private JButton getJButtonOk() {
196 if (jButtonOk == null) {
197 jButtonOk = new JButton();
198 jButtonOk.setText("Ok");
199 jButtonOk.setSize(new java.awt.Dimension(84, 20));
200 jButtonOk.setLocation(new java.awt.Point(316, 486));
201 jButtonOk.addActionListener(this);
202 }
203 return jButtonOk;
204 }
205
206 /**
207 This method initializes jButtonCancel
208
209 @return javax.swing.JButton
210 **/
211 private JButton getJButtonCancel() {
212 if (jButtonCancel == null) {
213 jButtonCancel = new JButton();
214 jButtonCancel.setText("Cancel");
215 jButtonCancel.setSize(new java.awt.Dimension(82, 20));
216 jButtonCancel.setLocation(new java.awt.Point(411, 486));
217 jButtonCancel.addActionListener(this);
218 }
219 return jButtonCancel;
220 }
221
222 /**
223 This method initializes jButton
224
225 @return javax.swing.JButton
226 **/
227 private JButton getJButton() {
228 if (jButton == null) {
229 jButton = new JButton();
230 jButton.setBounds(new java.awt.Rectangle(220, 486, 85, 20));
231 jButton.setText("Insert");
232 jButton.addActionListener(this);
233 }
234 return jButton;
235 }
236 } // @jve:decl-index=0:visual-constraint="11,7"