2 Java class SpdPackageHeaders 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
.frameworkwizard
.packaging
.ui
;
15 import java
.awt
.Dimension
;
16 import java
.awt
.event
.ActionEvent
;
17 import java
.awt
.event
.ComponentEvent
;
20 import javax
.swing
.DefaultCellEditor
;
21 import javax
.swing
.JFileChooser
;
22 import javax
.swing
.JOptionPane
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JRadioButton
;
25 import javax
.swing
.JTable
;
26 import javax
.swing
.JTextField
;
27 import javax
.swing
.JComboBox
;
28 import javax
.swing
.JLabel
;
29 import javax
.swing
.JScrollPane
;
30 import javax
.swing
.JButton
;
31 import javax
.swing
.JFrame
;
32 import javax
.swing
.ListSelectionModel
;
33 import javax
.swing
.event
.InternalFrameAdapter
;
34 import javax
.swing
.event
.InternalFrameEvent
;
35 import javax
.swing
.event
.ListSelectionEvent
;
36 import javax
.swing
.event
.ListSelectionListener
;
37 import javax
.swing
.event
.TableModelEvent
;
38 import javax
.swing
.event
.TableModelListener
;
39 import javax
.swing
.table
.DefaultTableModel
;
40 import javax
.swing
.table
.TableColumn
;
41 import javax
.swing
.table
.TableModel
;
43 import org
.tianocore
.PackageSurfaceAreaDocument
;
44 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
45 import org
.tianocore
.frameworkwizard
.common
.Tools
;
46 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
47 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
50 GUI for create library definition elements of spd file.
52 @since PackageEditor 1.0
54 public class SpdPackageHeaders
extends IInternalFrame
implements TableModelListener
{
58 private static final long serialVersionUID
= 1L;
62 private SpdFileContents sfc
= null;
64 private DefaultTableModel model
= null;
66 private JPanel jContentPane
= null;
68 private JRadioButton jRadioButtonSelect
= null;
70 private JComboBox jComboBoxSelect
= null;
72 private JButton jButtonAdd
= null;
74 private JButton jButtonRemove
= null;
76 private JButton jButtonClearAll
= null;
78 private JButton jButtonCancel
= null;
80 private JButton jButtonOk
= null;
82 private JLabel jLabel
= null;
84 private JTextField jTextField
= null;
86 private JButton jButtonBrowse
= null;
88 private StarLabel jStarLabel1
= null;
90 private StarLabel jStarLabel2
= null;
92 private JScrollPane jScrollPane
= null;
94 private JScrollPane jScrollPane1
= null;
96 private int selectedRow
= -1;
98 private JTable jTable
= null;
103 This method initializes this
106 private void initialize() {
108 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
113 This method initializes jRadioButtonSelect
115 @return javax.swing.JRadioButton
117 private JRadioButton
getJRadioButtonSelect() {
118 if (jRadioButtonSelect
== null) {
119 jRadioButtonSelect
= new JRadioButton();
120 jRadioButtonSelect
.setBounds(new java
.awt
.Rectangle(9,10,198,20));
121 jRadioButtonSelect
.setText("Select Existing ModuleType");
122 jRadioButtonSelect
.addActionListener(this);
123 jRadioButtonSelect
.setSelected(true);
125 return jRadioButtonSelect
;
129 This method initializes jComboBoxSelect
131 @return javax.swing.JComboBox
133 private JComboBox
getJComboBoxSelect() {
134 if (jComboBoxSelect
== null) {
135 jComboBoxSelect
= new JComboBox();
136 jComboBoxSelect
.setBounds(new java
.awt
.Rectangle(220, 10, 260, 20));
137 jComboBoxSelect
.setPreferredSize(new java
.awt
.Dimension(260,20));
139 jComboBoxSelect
.setEnabled(true);
141 return jComboBoxSelect
;
145 This method initializes jTable
147 @return javax.swing.JTable
149 private JTable getJTable() {
150 if (jTable == null) {
151 model = new PackageHeaderTableModel();
152 model.addColumn("ModuleType");
153 model.addColumn("IncludeHeader");
160 This method initializes jButtonAdd
162 @return javax.swing.JButton
164 private JButton
getJButtonAdd() {
165 if (jButtonAdd
== null) {
166 jButtonAdd
= new JButton();
167 jButtonAdd
.setBounds(new java
.awt
.Rectangle(189,119,73,20));
168 jButtonAdd
.setText("Add");
169 jButtonAdd
.addActionListener(this);
175 This method initializes jButtonRemove
177 @return javax.swing.JButton
179 private JButton
getJButtonRemove() {
180 if (jButtonRemove
== null) {
181 jButtonRemove
= new JButton();
182 jButtonRemove
.setBounds(new java
.awt
.Rectangle(271,119,87,20));
183 jButtonRemove
.setText("Remove");
184 jButtonRemove
.addActionListener(this);
186 return jButtonRemove
;
190 This method initializes jButtonRemoveAll
192 @return javax.swing.JButton
194 private JButton
getJButtonClearAll() {
195 if (jButtonClearAll
== null) {
196 jButtonClearAll
= new JButton();
197 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(374,119,90,20));
198 jButtonClearAll
.setText("Clear All");
199 jButtonClearAll
.addActionListener(this);
201 return jButtonClearAll
;
205 This method initializes jButtonCancel
207 @return javax.swing.JButton
209 private JButton
getJButtonCancel() {
210 if (jButtonCancel
== null) {
211 jButtonCancel
= new JButton();
212 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
213 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
214 jButtonCancel
.setText("Cancel");
215 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
216 jButtonCancel
.setVisible(false);
217 jButtonCancel
.addActionListener(this);
219 return jButtonCancel
;
223 This method initializes jButton
225 @return javax.swing.JButton
227 private JButton
getJButtonOk() {
228 if (jButtonOk
== null) {
229 jButtonOk
= new JButton();
230 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
231 jButtonOk
.setText("OK");
232 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
233 jButtonOk
.setVisible(false);
234 jButtonOk
.addActionListener(this);
240 This is the default constructor
242 public SpdPackageHeaders() {
249 public SpdPackageHeaders(PackageSurfaceAreaDocument
.PackageSurfaceArea inPsa
){
251 sfc
= new SpdFileContents(inPsa
);
255 This method initializes this
259 private void init() {
261 this.setContentPane(getJScrollPane());
262 this.setTitle("Library Class Declarations");
263 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
264 this.setVisible(true);
265 this.addInternalFrameListener(new InternalFrameAdapter(){
266 public void internalFrameDeactivated(InternalFrameEvent e
){
267 if (jTable
.isEditing()) {
268 jTable
.getCellEditor().stopCellEditing();
275 private void init(SpdFileContents sfc
){
276 if (sfc
.getSpdPackageHeaderCount() == 0) {
279 String
[][] saa
= new String
[sfc
.getSpdPackageHeaderCount()][2];
280 sfc
.getSpdPackageHeaders(saa
);
282 while (i
< saa
.length
) {
283 model
.addRow(saa
[i
]);
288 private JScrollPane
getJScrollPane(){
289 if (jScrollPane
== null){
290 jScrollPane
= new JScrollPane();
291 jScrollPane
.setViewportView(getJContentPane());
296 This method initializes jContentPane
298 @return javax.swing.JPanel
300 private JPanel
getJContentPane() {
301 if (jContentPane
== null) {
302 jStarLabel1
= new StarLabel();
303 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
304 jStarLabel2
= new StarLabel();
305 jStarLabel2
.setLocation(new java
.awt
.Point(0,62));
306 jLabel
= new JLabel();
307 jLabel
.setBounds(new java
.awt
.Rectangle(14,62,199,22));
308 jLabel
.setText("Include Header for Module Type");
310 jContentPane
= new JPanel();
311 jContentPane
.setPreferredSize(new Dimension(480, 325));
312 jContentPane
.setLayout(null);
313 jContentPane
.add(jLabel
, null);
314 jContentPane
.add(jStarLabel1
, null);
315 jContentPane
.add(jStarLabel2
, null);
316 jContentPane
.add(getJRadioButtonSelect(), null);
317 jContentPane
.add(getJComboBoxSelect(), null);
318 jContentPane
.add(getJButtonAdd(), null);
319 jContentPane
.add(getJButtonRemove(), null);
320 jContentPane
.add(getJButtonClearAll(), null);
321 jContentPane
.add(getJButtonCancel(), null);
322 jContentPane
.add(getJButtonOk(), null);
324 jContentPane
.add(getJTextField(), null);
325 jContentPane
.add(getJButtonBrowse(), null);
326 jContentPane
.add(getJScrollPane1(), null);
332 fill ComboBoxes with pre-defined contents
334 private void initFrame() {
335 jComboBoxSelect
.addItem("BASE");
336 jComboBoxSelect
.addItem("SEC");
337 jComboBoxSelect
.addItem("PEI_CORE");
338 jComboBoxSelect
.addItem("PEIM");
339 jComboBoxSelect
.addItem("DXE_CORE");
340 jComboBoxSelect
.addItem("DXE_DRIVER");
341 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
342 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
343 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
344 jComboBoxSelect
.addItem("TOOLS");
345 jComboBoxSelect
.addItem("UEFI_DRIVER");
346 jComboBoxSelect
.addItem("UEFI_APPLICATION");
347 jComboBoxSelect
.addItem("USER_DEFINED");
348 jComboBoxSelect
.setSelectedIndex(0);
352 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
354 public void actionPerformed(ActionEvent arg0
) {
355 if (arg0
.getSource() == jButtonOk
) {
360 if (arg0
.getSource() == jButtonCancel
) {
364 if (arg0
.getSource() == jButtonAdd
) {
365 String strLibClass
= "";
367 if (jRadioButtonSelect
.isSelected()) {
368 strLibClass
= jComboBoxSelect
.getSelectedItem().toString();
370 //ToDo: check before add
371 String
[] row
= {"", ""};
372 row
[0] = strLibClass
;
373 row
[1] = jTextField
.getText().replace('\\', '/');
374 if (!dataValidation(row
)) {
378 sfc
.genSpdModuleHeaders(row
[0], row
[1], null, null, null, null, null, null);
381 // remove selected line
383 if (arg0
.getSource() == jButtonRemove
) {
384 if (jTable
.isEditing()){
385 jTable
.getCellEditor().stopCellEditing();
387 int rowSelected
= selectedRow
;
388 if (rowSelected
>= 0) {
389 model
.removeRow(rowSelected
);
390 sfc
.removeSpdPkgHeader(rowSelected
);
394 if (arg0
.getSource() == jButtonClearAll
) {
395 if (model
.getRowCount() == 0) {
398 model
.setRowCount(0);
399 sfc
.removeSpdPkgHeader();
404 private boolean dataValidation(String
[] row
) {
405 if (!DataValidation
.isPathAndFilename(row
[1])) {
406 JOptionPane
.showMessageDialog(this, "Include header path is NOT PathAndFilename type.");
414 Add contents in list to sfc
416 protected void save() {
421 This method initializes jTextField
423 @return javax.swing.JTextField
425 private JTextField
getJTextField() {
426 if (jTextField
== null) {
427 jTextField
= new JTextField();
428 jTextField
.setBounds(new java
.awt
.Rectangle(13,90,346,21));
429 jTextField
.setPreferredSize(new java
.awt
.Dimension(345,20));
435 This method initializes jButtonBrowse
437 @return javax.swing.JButton
439 private JButton
getJButtonBrowse() {
440 if (jButtonBrowse
== null) {
441 jButtonBrowse
= new JButton();
442 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(374,89,92,21));
443 jButtonBrowse
.setText("Browse");
444 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(92,20));
445 jButtonBrowse
.addActionListener(new javax
.swing
.AbstractAction() {
449 private static final long serialVersionUID
= 1L;
451 public void actionPerformed(ActionEvent e
) {
453 // Select files from current workspace
455 String dirPrefix
= Tools
.dirForNewSpd
.substring(0, Tools
.dirForNewSpd
.lastIndexOf(File
.separator
));
456 JFileChooser chooser
= new JFileChooser(dirPrefix
);
458 String headerDest
= null;
460 chooser
.setMultiSelectionEnabled(false);
461 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
462 int retval
= chooser
.showOpenDialog(frame
);
463 if (retval
== JFileChooser
.APPROVE_OPTION
) {
465 theFile
= chooser
.getSelectedFile();
466 String file
= theFile
.getPath();
467 if (!file
.startsWith(dirPrefix
)) {
468 JOptionPane
.showMessageDialog(frame
, "You can only select files in current package!");
478 headerDest
= theFile
.getPath();
479 int fileIndex
= headerDest
.indexOf(System
.getProperty("file.separator"), dirPrefix
.length());
481 jTextField
.setText(headerDest
.substring(fileIndex
+ 1).replace('\\', '/'));
486 return jButtonBrowse
;
490 * This method initializes jScrollPane
492 * @return javax.swing.JScrollPane
494 private JScrollPane
getJScrollPane1() {
495 if (jScrollPane1
== null) {
496 jScrollPane1
= new JScrollPane();
497 jScrollPane1
.setBounds(new java
.awt
.Rectangle(13,149,453,165));
498 jScrollPane1
.setViewportView(getJTable());
504 * This method initializes jTable
506 * @return javax.swing.JTable
508 private JTable
getJTable() {
509 if (jTable
== null) {
510 model
= new DefaultTableModel();
511 jTable
= new JTable(model
);
512 jTable
.setRowHeight(20);
513 model
.addColumn("ModuleType");
514 model
.addColumn("IncludeHeader");
515 TableColumn typeColumn
= jTable
.getColumnModel().getColumn(0);
516 JComboBox jComboBoxSelect
= new JComboBox();
517 jComboBoxSelect
.addItem("BASE");
518 jComboBoxSelect
.addItem("SEC");
519 jComboBoxSelect
.addItem("PEI_CORE");
520 jComboBoxSelect
.addItem("PEIM");
521 jComboBoxSelect
.addItem("DXE_CORE");
522 jComboBoxSelect
.addItem("DXE_DRIVER");
523 jComboBoxSelect
.addItem("DXE_RUNTIME_DRIVER");
524 jComboBoxSelect
.addItem("DXE_SAL_DRIVER");
525 jComboBoxSelect
.addItem("DXE_SMM_DRIVER");
526 jComboBoxSelect
.addItem("TOOLS");
527 jComboBoxSelect
.addItem("UEFI_DRIVER");
528 jComboBoxSelect
.addItem("UEFI_APPLICATION");
529 jComboBoxSelect
.addItem("USER_DEFINED");
530 typeColumn
.setCellEditor(new DefaultCellEditor(jComboBoxSelect
));
532 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
533 jTable
.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
534 public void valueChanged(ListSelectionEvent e
) {
535 if (e
.getValueIsAdjusting()){
538 ListSelectionModel lsm
= (ListSelectionModel
)e
.getSource();
539 if (lsm
.isSelectionEmpty()) {
543 selectedRow
= lsm
.getMinSelectionIndex();
548 jTable
.getModel().addTableModelListener(this);
553 public void tableChanged(TableModelEvent arg0
) {
554 // TODO Auto-generated method stub
555 int row
= arg0
.getFirstRow();
556 TableModel m
= (TableModel
)arg0
.getSource();
557 if (arg0
.getType() == TableModelEvent
.UPDATE
){
558 String pkg
= m
.getValueAt(row
, 0) + "";
559 String hdr
= m
.getValueAt(row
, 1) + "";
560 String
[] rowData
= {pkg
, hdr
};
561 if (!dataValidation(rowData
)) {
564 sfc
.updateSpdPkgHdr(row
, pkg
, hdr
);
568 public void componentResized(ComponentEvent arg0
) {
569 int intPreferredWidth
= 500;
571 resizeComponentWidth(this.jComboBoxSelect
, this.getWidth(), intPreferredWidth
);
572 resizeComponentWidth(this.jTextField
, this.getWidth(), intPreferredWidth
);
573 resizeComponentWidth(this.jScrollPane
, this.getWidth(), intPreferredWidth
);
574 relocateComponentX(this.jButtonBrowse
, this.getWidth(), this.getPreferredSize().width
, 30);
577 public static void main(String
[] args
){
578 new SpdPackageHeaders().setVisible(true);