2 Java class PackageLibraryClass is GUI for create library definition elements of spd file.
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
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.
13 package org
.tianocore
.packaging
;
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
;
21 import java
.util
.Vector
;
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
;
37 GUI for create library definition elements of spd file.
39 @since PackageEditor 1.0
41 public class PackageLibraryClass
extends JFrame
implements ActionListener
{
44 private static String Separator
= "::";
46 private DefaultListModel listItem
= new DefaultListModel();
48 private SpdFileContents sfc
= null;
50 private JPanel jContentPane
= null;
52 private JRadioButton jRadioButtonAdd
= null;
54 private JRadioButton jRadioButtonSelect
= null;
56 private JTextField jTextFieldAdd
= null;
58 private JComboBox jComboBoxSelect
= null;
60 private JLabel jLabelUsage
= null;
62 private JComboBox jComboBoxUsage
= null;
64 private JScrollPane jScrollPane
= null;
66 private JList jListLibraryClassDefinitions
= null;
68 private JButton jButtonAdd
= null;
70 private JButton jButtonRemove
= null;
72 private JButton jButtonClearAll
= null;
74 private JButton jButtonCancel
= null;
76 private JButton jButtonOk
= null;
78 private JLabel jLabel
= null;
80 private JTextField jTextField
= null;
82 private JButton jButtonBrowse
= null;
85 This method initializes this
88 private void initialize() {
89 this.setTitle("Library Declarations");
90 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
95 This method initializes jRadioButtonAdd
97 @return javax.swing.JRadioButton
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);
107 return jRadioButtonAdd
;
111 This method initializes jRadioButtonSelect
113 @return javax.swing.JRadioButton
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);
123 return jRadioButtonSelect
;
127 This method initializes jTextFieldAdd
129 @return javax.swing.JTextField
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);
137 return jTextFieldAdd
;
141 This method initializes jComboBoxSelect
143 @return javax.swing.JComboBox
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);
151 return jComboBoxSelect
;
155 This method initializes jComboBoxUsage
157 @return javax.swing.JComboBox
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);
165 return jComboBoxUsage
;
169 This method initializes jScrollPane
171 @return javax.swing.JScrollPane
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());
183 This method initializes jListLibraryClassDefinitions
185 @return javax.swing.JList
187 private JList
getJListLibraryClassDefinitions() {
188 if (jListLibraryClassDefinitions
== null) {
189 jListLibraryClassDefinitions
= new JList(listItem
);
191 return jListLibraryClassDefinitions
;
195 This method initializes jButtonAdd
197 @return javax.swing.JButton
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);
210 This method initializes jButtonRemove
212 @return javax.swing.JButton
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);
221 return jButtonRemove
;
225 This method initializes jButtonRemoveAll
227 @return javax.swing.JButton
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);
236 return jButtonClearAll
;
240 This method initializes jButtonCancel
242 @return javax.swing.JButton
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);
253 return jButtonCancel
;
257 This method initializes jButton
259 @return javax.swing.JButton
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);
273 This is the default constructor
275 public PackageLibraryClass(SpdFileContents sfc
) {
283 Start the window at the center of screen
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);
292 Start the window at the center of screen
295 protected void centerWindow() {
296 centerWindow(this.getSize().width
, this.getSize().height
);
300 This method initializes this
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));
313 This method initializes jContentPane
315 @return javax.swing.JPanel
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);
348 fill ComboBoxes with pre-defined contents
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");
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");
399 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
401 public void actionPerformed(ActionEvent arg0
) {
402 if (arg0
.getSource() == jButtonOk
) {
407 if (arg0
.getSource() == jButtonCancel
) {
411 if (arg0
.getSource() == jButtonAdd
) {
412 String strLibClass
= "";
413 if (jRadioButtonAdd
.isSelected()) {
414 strLibClass
= jTextFieldAdd
.getText();
416 if (jRadioButtonSelect
.isSelected()) {
417 strLibClass
= jComboBoxSelect
.getSelectedItem().toString();
419 listItem
.addElement(jTextField
.getText().replace('\\', '/') + this.Separator
+ strLibClass
);
422 // remove selected line
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
]);
431 jListLibraryClassDefinitions
.getSelectionModel().clearSelection();
434 if (arg0
.getSource() == jButtonClearAll
) {
435 listItem
.removeAllElements();
438 if (arg0
.getSource() == jRadioButtonAdd
) {
439 if (jRadioButtonAdd
.isSelected()) {
440 jRadioButtonSelect
.setSelected(false);
441 jTextFieldAdd
.setEnabled(true);
442 jComboBoxSelect
.setEnabled(false);
444 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
445 jRadioButtonAdd
.setSelected(true);
446 jTextFieldAdd
.setEnabled(true);
447 jComboBoxSelect
.setEnabled(false);
451 if (arg0
.getSource() == jRadioButtonSelect
) {
452 if (jRadioButtonSelect
.isSelected()) {
453 jRadioButtonAdd
.setSelected(false);
454 jTextFieldAdd
.setEnabled(false);
455 jComboBoxSelect
.setEnabled(true);
457 if (!jRadioButtonSelect
.isSelected() && !jRadioButtonAdd
.isSelected()) {
458 jRadioButtonSelect
.setSelected(true);
459 jTextFieldAdd
.setEnabled(false);
460 jComboBoxSelect
.setEnabled(true);
466 Add contents in list to sfc
468 protected void save() {
470 int intLibraryCount
= listItem
.getSize();
472 if (intLibraryCount
> 0) {
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,
485 } catch (Exception e
) {
486 System
.out
.println(e
.toString());
491 This method initializes jTextField
493 @return javax.swing.JTextField
495 private JTextField
getJTextField() {
496 if (jTextField
== null) {
497 jTextField
= new JTextField();
498 jTextField
.setBounds(new java
.awt
.Rectangle(12,112,346,21));
504 This method initializes jButtonBrowse
506 @return javax.swing.JButton
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
) {
517 // Select files from current workspace
519 JFileChooser chooser
= new JFileChooser(System
.getenv("WORKSPACE"));
521 String headerDest
= null;
523 chooser
.setMultiSelectionEnabled(false);
524 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
525 int retval
= chooser
.showOpenDialog(frame
);
526 if (retval
== JFileChooser
.APPROVE_OPTION
) {
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!");
541 if (!theFile
.getPath().startsWith(PackagingMain
.dirForNewSpd
)) {
543 //ToDo: copy elsewhere header file to new pkg dir, prompt user to chooser a location
545 JOptionPane
.showMessageDialog(frame
, "You must copy header file into current package directory!");
549 headerDest
= theFile
.getPath();
550 int fileIndex
= headerDest
.indexOf(System
.getProperty("file.separator"), PackagingMain
.dirForNewSpd
.length());
552 jTextField
.setText(headerDest
.substring(fileIndex
+ 1).replace('\\', '/'));
557 return jButtonBrowse
;