]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackagePkgHeader.java
Remove the assumption of package location under workspace and prompt user to specify...
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / PackagePkgHeader.java
1 /** @file
2 Java class PackagePkgHeader is GUI for create Package header elements of 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 java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.awt.Toolkit;
18 import java.awt.event.ActionEvent;
19 import java.awt.event.ActionListener;
20 import java.util.Vector;
21
22 import javax.swing.DefaultListModel;
23 import javax.swing.JPanel;
24 import javax.swing.JRadioButton;
25 import javax.swing.JTextField;
26 import javax.swing.JComboBox;
27 import javax.swing.JLabel;
28 import javax.swing.JList;
29 import javax.swing.JScrollPane;
30 import javax.swing.JButton;
31 import javax.swing.JFrame;
32
33 import org.tianocore.packaging.common.ui.StarLabel;
34
35 /**
36 GUI for create Package header elements of spd file
37
38 @since PackageEditor 1.0
39 **/
40 public class PackagePkgHeader extends JFrame implements ActionListener {
41 private static String Separator = "::";
42
43 private DefaultListModel listItem = new DefaultListModel();
44
45 private SpdFileContents sfc = null;
46
47 private JPanel jContentPane = null;
48
49 private JRadioButton jRadioButtonAdd = null;
50
51 private JRadioButton jRadioButtonSelect = null;
52
53 private JTextField jTextFieldAdd = null;
54
55 private JComboBox jComboBoxSelect = null;
56
57 private JScrollPane jScrollPane = null;
58
59 private JList jListLibraryClassDefinitions = null;
60
61 private JButton jButtonAdd = null;
62
63 private JButton jButtonRemove = null;
64
65 private JButton jButtonClearAll = null;
66
67 private JButton jButtonCancel = null;
68
69 private JButton jButtonOk = null;
70
71 private JLabel jLabel = null;
72
73 private JTextField jTextField = null;
74
75 private StarLabel starLabel = null;
76
77 /**
78 This method initializes this
79
80 **/
81 private void initialize() {
82 this.setTitle("Package Headers");
83 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
84
85 }
86
87 /**
88 This method initializes jRadioButtonAdd
89
90 @return javax.swing.JRadioButton
91 **/
92 private JRadioButton getJRadioButtonAdd() {
93 if (jRadioButtonAdd == null) {
94 jRadioButtonAdd = new JRadioButton();
95 jRadioButtonAdd.setBounds(new java.awt.Rectangle(10, 35, 205, 20));
96 jRadioButtonAdd.setText("Add a new Module Type");
97 jRadioButtonAdd.setEnabled(false);
98 jRadioButtonAdd.addActionListener(this);
99 jRadioButtonAdd.setSelected(false);
100 }
101 return jRadioButtonAdd;
102 }
103
104 /**
105 This method initializes jRadioButtonSelect
106
107 @return javax.swing.JRadioButton
108 **/
109 private JRadioButton getJRadioButtonSelect() {
110 if (jRadioButtonSelect == null) {
111 jRadioButtonSelect = new JRadioButton();
112 jRadioButtonSelect.setBounds(new java.awt.Rectangle(10, 10, 205, 20));
113 jRadioButtonSelect.setText("Select an existed Module Type");
114 jRadioButtonSelect.setActionCommand("Select an existed Module Type");
115 jRadioButtonSelect.addActionListener(this);
116 jRadioButtonSelect.setSelected(true);
117 }
118 return jRadioButtonSelect;
119 }
120
121 /**
122 This method initializes jTextFieldAdd
123
124 @return javax.swing.JTextField
125 **/
126 private JTextField getJTextFieldAdd() {
127 if (jTextFieldAdd == null) {
128 jTextFieldAdd = new JTextField();
129 jTextFieldAdd.setBounds(new java.awt.Rectangle(220, 35, 260, 20));
130 jTextFieldAdd.setEditable(false);
131 jTextFieldAdd.setEnabled(false);
132 }
133 return jTextFieldAdd;
134 }
135
136 /**
137 This method initializes jComboBoxSelect
138
139 @return javax.swing.JComboBox
140 **/
141 private JComboBox getJComboBoxSelect() {
142 if (jComboBoxSelect == null) {
143 jComboBoxSelect = new JComboBox();
144 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));
145 jComboBoxSelect.setEnabled(true);
146 }
147 return jComboBoxSelect;
148 }
149
150 /**
151 This method initializes jScrollPane
152
153 @return javax.swing.JScrollPane
154 **/
155 private JScrollPane getJScrollPane() {
156 if (jScrollPane == null) {
157 jScrollPane = new JScrollPane();
158 jScrollPane.setBounds(new java.awt.Rectangle(10, 121, 350, 174));
159 jScrollPane.setViewportView(getJListLibraryClassDefinitions());
160 }
161 return jScrollPane;
162 }
163
164 /**
165 This method initializes jListLibraryClassDefinitions
166
167 @return javax.swing.JList
168 **/
169 private JList getJListLibraryClassDefinitions() {
170 if (jListLibraryClassDefinitions == null) {
171 jListLibraryClassDefinitions = new JList(listItem);
172 }
173 return jListLibraryClassDefinitions;
174 }
175
176 /**
177 This method initializes jButtonAdd
178
179 @return javax.swing.JButton
180 **/
181 private JButton getJButtonAdd() {
182 if (jButtonAdd == null) {
183 jButtonAdd = new JButton();
184 jButtonAdd.setBounds(new java.awt.Rectangle(375, 132, 90, 20));
185 jButtonAdd.setText("Add");
186 jButtonAdd.addActionListener(this);
187 }
188 return jButtonAdd;
189 }
190
191 /**
192 This method initializes jButtonRemove
193
194 @return javax.swing.JButton
195 **/
196 private JButton getJButtonRemove() {
197 if (jButtonRemove == null) {
198 jButtonRemove = new JButton();
199 jButtonRemove.setBounds(new java.awt.Rectangle(375, 230, 90, 20));
200 jButtonRemove.setText("Remove");
201 jButtonRemove.addActionListener(this);
202 }
203 return jButtonRemove;
204 }
205
206 /**
207 This method initializes jButtonRemoveAll
208
209 @return javax.swing.JButton
210 **/
211 private JButton getJButtonClearAll() {
212 if (jButtonClearAll == null) {
213 jButtonClearAll = new JButton();
214 jButtonClearAll.setBounds(new java.awt.Rectangle(375, 260, 90, 20));
215 jButtonClearAll.setText("Clear All");
216 jButtonClearAll.addActionListener(this);
217 }
218 return jButtonClearAll;
219 }
220
221 /**
222 This method initializes jButtonCancel
223
224 @return javax.swing.JButton
225 **/
226 private JButton getJButtonCancel() {
227 if (jButtonCancel == null) {
228 jButtonCancel = new JButton();
229 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
230 jButtonCancel.setLocation(new java.awt.Point(390, 305));
231 jButtonCancel.setText("Cancel");
232 jButtonCancel.setSize(new java.awt.Dimension(90, 20));
233 jButtonCancel.addActionListener(this);
234 }
235 return jButtonCancel;
236 }
237
238 /**
239 This method initializes jButton
240
241 @return javax.swing.JButton
242 **/
243 private JButton getJButtonOk() {
244 if (jButtonOk == null) {
245 jButtonOk = new JButton();
246 jButtonOk.setSize(new java.awt.Dimension(90, 20));
247 jButtonOk.setText("OK");
248 jButtonOk.setLocation(new java.awt.Point(290, 305));
249 jButtonOk.addActionListener(this);
250 }
251 return jButtonOk;
252 }
253
254 /**
255 This is the default constructor
256 **/
257 public PackagePkgHeader(SpdFileContents sfc) {
258 super();
259 initialize();
260 init();
261 this.sfc = sfc;
262 }
263
264 /**
265 Start the window at the center of screen
266 *
267 **/
268 protected void centerWindow(int intWidth, int intHeight) {
269 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
270 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
271 }
272
273 /**
274 Start the window at the center of screen
275 *
276 **/
277 protected void centerWindow() {
278 centerWindow(this.getSize().width, this.getSize().height);
279 }
280
281 // private void init(LibraryClassDefinitionsDocument.LibraryClassDefinitions inLibraryClassDefinitions) {
282 // init();
283 // this.setLibraryClassDefinitions(inLibraryClassDefinitions);
284 // int intLibraryCount = this.libraryClassDefinitions.getLibraryClassArray().length;
285 // if (intLibraryCount > 0) {
286 // for (int index = 0; index < intLibraryCount; index++) {
287 // listItem.addElement(this.libraryClassDefinitions.getLibraryClassArray(index).getUsage().toString() +
288 // this.Separator +
289 // this.libraryClassDefinitions.getLibraryClassArray(index).getStringValue());
290 // this.libraryClassDefinitions.getLibraryClassArray();
291 // }
292 // }
293 // }
294
295 /**
296 This method initializes this
297
298 @return void
299 **/
300 private void init() {
301 this.setContentPane(getJContentPane());
302 this.setTitle("Library Class Declarations");
303 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
304 this.centerWindow();
305 initFrame();
306 }
307
308 /**
309 This method initializes jContentPane
310
311 @return javax.swing.JPanel
312 **/
313 private JPanel getJContentPane() {
314 if (jContentPane == null) {
315 starLabel = new StarLabel();
316 starLabel.setBounds(new java.awt.Rectangle(5, 85, 10, 20));
317 jLabel = new JLabel();
318 jLabel.setBounds(new java.awt.Rectangle(14, 85, 201, 22));
319 jLabel.setText("Include Header for Selected Type");
320 jContentPane = new JPanel();
321 jContentPane.setLayout(null);
322 jContentPane.add(getJRadioButtonAdd(), null);
323 jContentPane.add(getJRadioButtonSelect(), null);
324 jContentPane.add(getJTextFieldAdd(), null);
325 jContentPane.add(getJComboBoxSelect(), null);
326 jContentPane.add(getJScrollPane(), null);
327 jContentPane.add(getJButtonAdd(), null);
328 jContentPane.add(getJButtonRemove(), null);
329 jContentPane.add(getJButtonClearAll(), null);
330 jContentPane.add(getJButtonCancel(), null);
331 jContentPane.add(getJButtonOk(), null);
332 jContentPane.add(jLabel, null);
333 jContentPane.add(getJTextField(), null);
334 jContentPane.add(starLabel, null);
335 }
336 return jContentPane;
337 }
338
339 private void initFrame() {
340 jComboBoxSelect.addItem("BASE");
341 jComboBoxSelect.addItem("SEC");
342 jComboBoxSelect.addItem("PEI_CORE");
343 jComboBoxSelect.addItem("PEIM");
344 jComboBoxSelect.addItem("DXE_CORE");
345 jComboBoxSelect.addItem("DXE_DRIVER");
346 jComboBoxSelect.addItem("DXE_RUNTIME_DRIVER");
347 jComboBoxSelect.addItem("DXE_SAL_DRIVER");
348 jComboBoxSelect.addItem("DXE_SMM_DRIVER");
349 jComboBoxSelect.addItem("TOOLS");
350 jComboBoxSelect.addItem("UEFI_DRIVER");
351 jComboBoxSelect.addItem("UEFI_APPLICATION");
352 jComboBoxSelect.addItem("USER_DEFINED");
353
354 }
355
356 public void actionPerformed(ActionEvent arg0) {
357 if (arg0.getSource() == jButtonOk) {
358 this.save();
359 this.dispose();
360
361 }
362 if (arg0.getSource() == jButtonCancel) {
363 this.dispose();
364 }
365
366 if (arg0.getSource() == jButtonAdd) {
367 String strLibClass = "";
368
369 if (jRadioButtonAdd.isSelected()) {
370 strLibClass = jTextFieldAdd.getText();
371 }
372 if (jRadioButtonSelect.isSelected()) {
373 strLibClass = jComboBoxSelect.getSelectedItem().toString();
374 }
375
376 listItem.addElement(jTextField.getText().replace('\\', '/') + Separator + strLibClass);
377 }
378
379 if (arg0.getSource() == jButtonRemove) {
380 int intSelected[] = jListLibraryClassDefinitions.getSelectedIndices();
381 if (intSelected.length > 0) {
382 for (int index = intSelected.length - 1; index > -1; index--) {
383 listItem.removeElementAt(intSelected[index]);
384 }
385 }
386 jListLibraryClassDefinitions.getSelectionModel().clearSelection();
387 }
388
389 if (arg0.getSource() == jButtonClearAll) {
390 listItem.removeAllElements();
391 }
392
393 if (arg0.getSource() == jRadioButtonAdd) {
394 if (jRadioButtonAdd.isSelected()) {
395 jRadioButtonSelect.setSelected(false);
396 jTextFieldAdd.setEnabled(true);
397 jComboBoxSelect.setEnabled(false);
398 }
399 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
400 jRadioButtonAdd.setSelected(true);
401 jTextFieldAdd.setEnabled(true);
402 jComboBoxSelect.setEnabled(false);
403 }
404 }
405
406 if (arg0.getSource() == jRadioButtonSelect) {
407 if (jRadioButtonSelect.isSelected()) {
408 jRadioButtonAdd.setSelected(false);
409 jTextFieldAdd.setEnabled(false);
410 jComboBoxSelect.setEnabled(true);
411 }
412 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
413 jRadioButtonSelect.setSelected(true);
414 jTextFieldAdd.setEnabled(false);
415 jComboBoxSelect.setEnabled(true);
416 }
417 }
418 }
419
420 private void save() {
421 try {
422 int intLibraryCount = listItem.getSize();
423
424 if (intLibraryCount > 0) {
425
426 for (int index = 0; index < intLibraryCount; index++) {
427 String strAll = listItem.get(index).toString();
428 String strInclude = strAll.substring(0, strAll.indexOf(Separator));
429 String strType = strAll.substring(strAll.indexOf(Separator) + Separator.length());
430 sfc.genSpdModuleHeaders(strType, strInclude, null, null, null, null, null, null);
431 }
432 } else {
433
434 }
435
436 } catch (Exception e) {
437 System.out.println(e.toString());
438 }
439 }
440
441 /**
442 This method initializes jTextField
443
444 @return javax.swing.JTextField
445 **/
446 private JTextField getJTextField() {
447 if (jTextField == null) {
448 jTextField = new JTextField();
449 jTextField.setBounds(new java.awt.Rectangle(221, 86, 257, 21));
450 }
451 return jTextField;
452 }
453
454 }