]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/PackageLibraryClass.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 / PackageLibraryClass.java
1 /** @file
2 Java class PackageLibraryClass is GUI for create library definition 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.io.File;
21 import java.util.Vector;
22
23 import javax.swing.DefaultListModel;
24 import javax.swing.JFileChooser;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.JRadioButton;
28 import javax.swing.JTextField;
29 import javax.swing.JComboBox;
30 import javax.swing.JLabel;
31 import javax.swing.JList;
32 import javax.swing.JScrollPane;
33 import javax.swing.JButton;
34 import javax.swing.JFrame;
35
36 /**
37 GUI for create library definition elements of spd file.
38
39 @since PackageEditor 1.0
40 **/
41 public class PackageLibraryClass extends JFrame implements ActionListener {
42 static JFrame frame;
43
44 private static String Separator = "::";
45
46 private DefaultListModel listItem = new DefaultListModel();
47
48 private SpdFileContents sfc = null;
49
50 private JPanel jContentPane = null;
51
52 private JRadioButton jRadioButtonAdd = null;
53
54 private JRadioButton jRadioButtonSelect = null;
55
56 private JTextField jTextFieldAdd = null;
57
58 private JComboBox jComboBoxSelect = null;
59
60 private JLabel jLabelUsage = null;
61
62 private JComboBox jComboBoxUsage = null;
63
64 private JScrollPane jScrollPane = null;
65
66 private JList jListLibraryClassDefinitions = null;
67
68 private JButton jButtonAdd = null;
69
70 private JButton jButtonRemove = null;
71
72 private JButton jButtonClearAll = null;
73
74 private JButton jButtonCancel = null;
75
76 private JButton jButtonOk = null;
77
78 private JLabel jLabel = null;
79
80 private JTextField jTextField = null;
81
82 private JButton jButtonBrowse = null;
83
84 /**
85 This method initializes this
86
87 **/
88 private void initialize() {
89 this.setTitle("Library Declarations");
90 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
91
92 }
93
94 /**
95 This method initializes jRadioButtonAdd
96
97 @return javax.swing.JRadioButton
98 **/
99 private JRadioButton getJRadioButtonAdd() {
100 if (jRadioButtonAdd == null) {
101 jRadioButtonAdd = new JRadioButton();
102 jRadioButtonAdd.setBounds(new java.awt.Rectangle(10, 35, 205, 20));
103 jRadioButtonAdd.setText("Add a new Library Class");
104 jRadioButtonAdd.addActionListener(this);
105 jRadioButtonAdd.setSelected(false);
106 }
107 return jRadioButtonAdd;
108 }
109
110 /**
111 This method initializes jRadioButtonSelect
112
113 @return javax.swing.JRadioButton
114 **/
115 private JRadioButton getJRadioButtonSelect() {
116 if (jRadioButtonSelect == null) {
117 jRadioButtonSelect = new JRadioButton();
118 jRadioButtonSelect.setBounds(new java.awt.Rectangle(10, 10, 205, 20));
119 jRadioButtonSelect.setText("Select Existing Library Class");
120 jRadioButtonSelect.addActionListener(this);
121 jRadioButtonSelect.setSelected(true);
122 }
123 return jRadioButtonSelect;
124 }
125
126 /**
127 This method initializes jTextFieldAdd
128
129 @return javax.swing.JTextField
130 **/
131 private JTextField getJTextFieldAdd() {
132 if (jTextFieldAdd == null) {
133 jTextFieldAdd = new JTextField();
134 jTextFieldAdd.setBounds(new java.awt.Rectangle(220, 35, 260, 20));
135 jTextFieldAdd.setEnabled(false);
136 }
137 return jTextFieldAdd;
138 }
139
140 /**
141 This method initializes jComboBoxSelect
142
143 @return javax.swing.JComboBox
144 **/
145 private JComboBox getJComboBoxSelect() {
146 if (jComboBoxSelect == null) {
147 jComboBoxSelect = new JComboBox();
148 jComboBoxSelect.setBounds(new java.awt.Rectangle(220, 10, 260, 20));
149 jComboBoxSelect.setEnabled(true);
150 }
151 return jComboBoxSelect;
152 }
153
154 /**
155 This method initializes jComboBoxUsage
156
157 @return javax.swing.JComboBox
158 **/
159 private JComboBox getJComboBoxUsage() {
160 if (jComboBoxUsage == null) {
161 jComboBoxUsage = new JComboBox();
162 jComboBoxUsage.setBounds(new java.awt.Rectangle(220, 60, 260, 20));
163 jComboBoxUsage.setEnabled(false);
164 }
165 return jComboBoxUsage;
166 }
167
168 /**
169 This method initializes jScrollPane
170
171 @return javax.swing.JScrollPane
172 **/
173 private JScrollPane getJScrollPane() {
174 if (jScrollPane == null) {
175 jScrollPane = new JScrollPane();
176 jScrollPane.setBounds(new java.awt.Rectangle(10,149,350,146));
177 jScrollPane.setViewportView(getJListLibraryClassDefinitions());
178 }
179 return jScrollPane;
180 }
181
182 /**
183 This method initializes jListLibraryClassDefinitions
184
185 @return javax.swing.JList
186 **/
187 private JList getJListLibraryClassDefinitions() {
188 if (jListLibraryClassDefinitions == null) {
189 jListLibraryClassDefinitions = new JList(listItem);
190 }
191 return jListLibraryClassDefinitions;
192 }
193
194 /**
195 This method initializes jButtonAdd
196
197 @return javax.swing.JButton
198 **/
199 private JButton getJButtonAdd() {
200 if (jButtonAdd == null) {
201 jButtonAdd = new JButton();
202 jButtonAdd.setBounds(new java.awt.Rectangle(375,152,90,20));
203 jButtonAdd.setText("Add");
204 jButtonAdd.addActionListener(this);
205 }
206 return jButtonAdd;
207 }
208
209 /**
210 This method initializes jButtonRemove
211
212 @return javax.swing.JButton
213 **/
214 private JButton getJButtonRemove() {
215 if (jButtonRemove == null) {
216 jButtonRemove = new JButton();
217 jButtonRemove.setBounds(new java.awt.Rectangle(375, 230, 90, 20));
218 jButtonRemove.setText("Remove");
219 jButtonRemove.addActionListener(this);
220 }
221 return jButtonRemove;
222 }
223
224 /**
225 This method initializes jButtonRemoveAll
226
227 @return javax.swing.JButton
228 **/
229 private JButton getJButtonClearAll() {
230 if (jButtonClearAll == null) {
231 jButtonClearAll = new JButton();
232 jButtonClearAll.setBounds(new java.awt.Rectangle(375, 260, 90, 20));
233 jButtonClearAll.setText("Clear All");
234 jButtonClearAll.addActionListener(this);
235 }
236 return jButtonClearAll;
237 }
238
239 /**
240 This method initializes jButtonCancel
241
242 @return javax.swing.JButton
243 **/
244 private JButton getJButtonCancel() {
245 if (jButtonCancel == null) {
246 jButtonCancel = new JButton();
247 jButtonCancel.setPreferredSize(new java.awt.Dimension(90, 20));
248 jButtonCancel.setLocation(new java.awt.Point(390, 305));
249 jButtonCancel.setText("Cancel");
250 jButtonCancel.setSize(new java.awt.Dimension(90, 20));
251 jButtonCancel.addActionListener(this);
252 }
253 return jButtonCancel;
254 }
255
256 /**
257 This method initializes jButton
258
259 @return javax.swing.JButton
260 **/
261 private JButton getJButtonOk() {
262 if (jButtonOk == null) {
263 jButtonOk = new JButton();
264 jButtonOk.setSize(new java.awt.Dimension(90, 20));
265 jButtonOk.setText("OK");
266 jButtonOk.setLocation(new java.awt.Point(290, 305));
267 jButtonOk.addActionListener(this);
268 }
269 return jButtonOk;
270 }
271
272 /**
273 This is the default constructor
274 **/
275 public PackageLibraryClass(SpdFileContents sfc) {
276 super();
277 initialize();
278 init();
279 this.sfc = sfc;
280 }
281
282 /**
283 Start the window at the center of screen
284
285 **/
286 protected void centerWindow(int intWidth, int intHeight) {
287 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
288 this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2);
289 }
290
291 /**
292 Start the window at the center of screen
293
294 **/
295 protected void centerWindow() {
296 centerWindow(this.getSize().width, this.getSize().height);
297 }
298
299 /**
300 This method initializes this
301
302 @return void
303 **/
304 private void init() {
305 this.setContentPane(getJContentPane());
306 this.setTitle("Library Class Declarations");
307 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
308 this.centerWindow();
309 initFrame();
310 }
311
312 /**
313 This method initializes jContentPane
314
315 @return javax.swing.JPanel
316 **/
317 private JPanel getJContentPane() {
318 if (jContentPane == null) {
319 jLabel = new JLabel();
320 jLabel.setBounds(new java.awt.Rectangle(14, 85, 201, 22));
321 jLabel.setText("Include Header for Selected Class");
322 jLabelUsage = new JLabel();
323 jLabelUsage.setBounds(new java.awt.Rectangle(15, 60, 200, 20));
324 jLabelUsage.setEnabled(false);
325 jLabelUsage.setText("Usage");
326 jContentPane = new JPanel();
327 jContentPane.setLayout(null);
328 jContentPane.add(getJRadioButtonAdd(), null);
329 jContentPane.add(getJRadioButtonSelect(), null);
330 jContentPane.add(getJTextFieldAdd(), null);
331 jContentPane.add(getJComboBoxSelect(), null);
332 jContentPane.add(jLabelUsage, null);
333 jContentPane.add(getJComboBoxUsage(), null);
334 jContentPane.add(getJScrollPane(), null);
335 jContentPane.add(getJButtonAdd(), null);
336 jContentPane.add(getJButtonRemove(), null);
337 jContentPane.add(getJButtonClearAll(), null);
338 jContentPane.add(getJButtonCancel(), null);
339 jContentPane.add(getJButtonOk(), null);
340 jContentPane.add(jLabel, null);
341 jContentPane.add(getJTextField(), null);
342 jContentPane.add(getJButtonBrowse(), null);
343 }
344 return jContentPane;
345 }
346
347 /**
348 fill ComboBoxes with pre-defined contents
349 **/
350 private void initFrame() {
351 jComboBoxSelect.addItem("BaseCpuICacheFlush");
352 jComboBoxSelect.addItem("BaseDebugLibNull");
353 jComboBoxSelect.addItem("BaseDebugLibReportStatusCode");
354 jComboBoxSelect.addItem("BaseIoLibIntrinsic");
355 jComboBoxSelect.addItem("BaseLib");
356 jComboBoxSelect.addItem("BaseMemoryLib");
357 jComboBoxSelect.addItem("BaseMemoryLibMmx");
358 jComboBoxSelect.addItem("BaseMemoryLibSse2");
359 jComboBoxSelect.addItem("BasePeCoffGetEntryPointLib");
360 jComboBoxSelect.addItem("BasePeCoffLib");
361 jComboBoxSelect.addItem("BasePrintLib");
362 jComboBoxSelect.addItem("BaseReportStatusCodeLibNull");
363 jComboBoxSelect.addItem("CommonPciCf8Lib");
364 jComboBoxSelect.addItem("CommonPciExpressLib");
365 jComboBoxSelect.addItem("CommonPciLibCf8");
366 jComboBoxSelect.addItem("CommonPciLibPciExpress");
367 jComboBoxSelect.addItem("DxeCoreEntryPoint");
368 jComboBoxSelect.addItem("DxeHobLib");
369 jComboBoxSelect.addItem("DxeIoLibCpuIo");
370 jComboBoxSelect.addItem("DxeLib");
371 jComboBoxSelect.addItem("DxePcdLib");
372 jComboBoxSelect.addItem("DxeReportStatusCodeLib");
373 jComboBoxSelect.addItem("DxeServicesTableLib");
374 jComboBoxSelect.addItem("PeiCoreEntryPoint");
375 jComboBoxSelect.addItem("PeiMemoryLib");
376 jComboBoxSelect.addItem("PeimEntryPoint");
377 jComboBoxSelect.addItem("PeiReportStatusCodeLib");
378 jComboBoxSelect.addItem("PeiServicesTablePointerLib");
379 jComboBoxSelect.addItem("PeiServicesTablePointerLibMm7");
380 jComboBoxSelect.addItem("UefiDebugLibConOut");
381 jComboBoxSelect.addItem("UefiDebugLibStdErr");
382 jComboBoxSelect.addItem("UefiDriverEntryPointMultiple");
383 jComboBoxSelect.addItem("UefiDriverEntryPointSingle");
384 jComboBoxSelect.addItem("UefiDriverEntryPointSingleUnload");
385 jComboBoxSelect.addItem("UefiDriverModelLib");
386 jComboBoxSelect.addItem("UefiDriverModelLibNoConfigNoDiag");
387 jComboBoxSelect.addItem("UefiLib");
388 jComboBoxSelect.addItem("UefiMemoryLib");
389
390 jComboBoxUsage.addItem("ALWAYS_CONSUMED");
391 jComboBoxUsage.addItem("SOMETIMES_CONSUMED");
392 jComboBoxUsage.addItem("ALWAYS_PRODUCED");
393 jComboBoxUsage.addItem("SOMETIMES_PRODUCED");
394 jComboBoxUsage.addItem("DEFAULT");
395 jComboBoxUsage.addItem("PRIVATE");
396 }
397
398 /* (non-Javadoc)
399 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
400 */
401 public void actionPerformed(ActionEvent arg0) {
402 if (arg0.getSource() == jButtonOk) {
403 this.save();
404 this.dispose();
405
406 }
407 if (arg0.getSource() == jButtonCancel) {
408 this.dispose();
409 }
410
411 if (arg0.getSource() == jButtonAdd) {
412 String strLibClass = "";
413 if (jRadioButtonAdd.isSelected()) {
414 strLibClass = jTextFieldAdd.getText();
415 }
416 if (jRadioButtonSelect.isSelected()) {
417 strLibClass = jComboBoxSelect.getSelectedItem().toString();
418 }
419 listItem.addElement(jTextField.getText().replace('\\', '/') + this.Separator + strLibClass);
420 }
421 //
422 // remove selected line
423 //
424 if (arg0.getSource() == jButtonRemove) {
425 int intSelected[] = jListLibraryClassDefinitions.getSelectedIndices();
426 if (intSelected.length > 0) {
427 for (int index = intSelected.length - 1; index > -1; index--) {
428 listItem.removeElementAt(intSelected[index]);
429 }
430 }
431 jListLibraryClassDefinitions.getSelectionModel().clearSelection();
432 }
433
434 if (arg0.getSource() == jButtonClearAll) {
435 listItem.removeAllElements();
436 }
437
438 if (arg0.getSource() == jRadioButtonAdd) {
439 if (jRadioButtonAdd.isSelected()) {
440 jRadioButtonSelect.setSelected(false);
441 jTextFieldAdd.setEnabled(true);
442 jComboBoxSelect.setEnabled(false);
443 }
444 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
445 jRadioButtonAdd.setSelected(true);
446 jTextFieldAdd.setEnabled(true);
447 jComboBoxSelect.setEnabled(false);
448 }
449 }
450
451 if (arg0.getSource() == jRadioButtonSelect) {
452 if (jRadioButtonSelect.isSelected()) {
453 jRadioButtonAdd.setSelected(false);
454 jTextFieldAdd.setEnabled(false);
455 jComboBoxSelect.setEnabled(true);
456 }
457 if (!jRadioButtonSelect.isSelected() && !jRadioButtonAdd.isSelected()) {
458 jRadioButtonSelect.setSelected(true);
459 jTextFieldAdd.setEnabled(false);
460 jComboBoxSelect.setEnabled(true);
461 }
462 }
463 }
464
465 /**
466 Add contents in list to sfc
467 **/
468 protected void save() {
469 try {
470 int intLibraryCount = listItem.getSize();
471
472 if (intLibraryCount > 0) {
473
474 for (int index = 0; index < intLibraryCount; index++) {
475 String strAll = listItem.get(index).toString();
476 String strInclude = strAll.substring(0, strAll.indexOf(Separator));
477 String strLibraryClass = strAll.substring(strAll.indexOf(Separator) + Separator.length());
478 sfc.genSpdLibClassDeclarations(strLibraryClass, null, strInclude, null, null, null, null, null,
479 null, null);
480 }
481 } else {
482
483 }
484
485 } catch (Exception e) {
486 System.out.println(e.toString());
487 }
488 }
489
490 /**
491 This method initializes jTextField
492
493 @return javax.swing.JTextField
494 **/
495 private JTextField getJTextField() {
496 if (jTextField == null) {
497 jTextField = new JTextField();
498 jTextField.setBounds(new java.awt.Rectangle(12,112,346,21));
499 }
500 return jTextField;
501 }
502
503 /**
504 This method initializes jButtonBrowse
505
506 @return javax.swing.JButton
507 **/
508 private JButton getJButtonBrowse() {
509 if (jButtonBrowse == null) {
510 jButtonBrowse = new JButton();
511 jButtonBrowse.setBounds(new java.awt.Rectangle(374,111,92,21));
512 jButtonBrowse.setText("Browse");
513 jButtonBrowse.setPreferredSize(new java.awt.Dimension(34,20));
514 jButtonBrowse.addMouseListener(new java.awt.event.MouseAdapter() {
515 public void mouseClicked(java.awt.event.MouseEvent e) {
516 //
517 // Select files from current workspace
518 //
519 JFileChooser chooser = new JFileChooser(System.getenv("WORKSPACE"));
520 File theFile = null;
521 String headerDest = null;
522
523 chooser.setMultiSelectionEnabled(false);
524 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
525 int retval = chooser.showOpenDialog(frame);
526 if (retval == JFileChooser.APPROVE_OPTION) {
527
528 theFile = chooser.getSelectedFile();
529 String file = theFile.getPath();
530 if (!file.startsWith(System.getenv("WORKSPACE"))) {
531 JOptionPane.showMessageDialog(frame, "You can only select files in current workspace!");
532 return;
533 }
534
535
536 }
537 else {
538 return;
539 }
540
541 if (!theFile.getPath().startsWith(PackagingMain.dirForNewSpd)) {
542 //
543 //ToDo: copy elsewhere header file to new pkg dir, prompt user to chooser a location
544 //
545 JOptionPane.showMessageDialog(frame, "You must copy header file into current package directory!");
546 return;
547 }
548
549 headerDest = theFile.getPath();
550 int fileIndex = headerDest.indexOf(System.getProperty("file.separator"), PackagingMain.dirForNewSpd.length());
551
552 jTextField.setText(headerDest.substring(fileIndex + 1).replace('\\', '/'));
553
554 }
555 });
556 }
557 return jButtonBrowse;
558 }
559
560 }