/** @file | |
Java class UpdateGuids is GUI for update GUID declarations in spd file. | |
Copyright (c) 2006, Intel Corporation | |
All rights reserved. This program and the accompanying materials | |
are licensed and made available under the terms and conditions of the BSD License | |
which accompanies this distribution. The full text of the license may be found at | |
http://opensource.org/licenses/bsd-license.php | |
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
**/ | |
package org.tianocore.packaging; | |
import javax.swing.JPanel; | |
import javax.swing.JFrame; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
import javax.swing.JButton; | |
import javax.swing.JScrollPane; | |
import javax.swing.JTable; | |
import javax.swing.table.*; | |
import org.tianocore.common.Tools; | |
import java.awt.Dimension; | |
import java.awt.Toolkit; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.io.*; | |
/** | |
GUI for update GUID declarations in spd file | |
@since PackageEditor 1.0 | |
**/ | |
public class UpdateGuids extends JFrame implements ActionListener { | |
private JPanel jContentPane = null; | |
private JScrollPane jScrollPane = null; | |
private JTable jTable = null; | |
private SpdFileContents sfc = null; | |
private JButton jButtonOk = null; | |
private JButton jButtonCancel = null; | |
private DefaultTableModel model = null; | |
private JButton jButton = null; | |
/** | |
This is the default constructor | |
**/ | |
public UpdateGuids(SpdFileContents sfc) { | |
super(); | |
this.sfc = sfc; | |
initialize(); | |
} | |
public void actionPerformed(ActionEvent arg0) { | |
if (arg0.getSource() == jButtonOk) { | |
this.save(); | |
this.dispose(); | |
} | |
if (arg0.getSource() == jButtonCancel) { | |
this.dispose(); | |
} | |
if (arg0.getSource() == jButton) { | |
String[] o = { "", "", "" }; | |
model.addRow(o); | |
} | |
} | |
/** | |
This method initializes this | |
@return void | |
**/ | |
private void initialize() { | |
this.setSize(669, 568); | |
this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); | |
this.setTitle("Update GUID Declarations"); | |
this.setContentPane(getJContentPane()); | |
this.centerWindow(); | |
} | |
/** | |
This method initializes jContentPane | |
@return javax.swing.JPanel | |
**/ | |
private JPanel getJContentPane() { | |
if (jContentPane == null) { | |
jContentPane = new JPanel(); | |
jContentPane.setLayout(null); | |
jContentPane.add(getJScrollPane(), null); | |
jContentPane.add(getJButtonOk(), null); | |
jContentPane.add(getJButtonCancel(), null); | |
jContentPane.add(getJButton(), null); | |
} | |
return jContentPane; | |
} | |
/** | |
This method initializes jScrollPane | |
@return javax.swing.JScrollPane | |
**/ | |
private JScrollPane getJScrollPane() { | |
if (jScrollPane == null) { | |
jScrollPane = new JScrollPane(); | |
jScrollPane.setBounds(new java.awt.Rectangle(38,45,586,315)); | |
jScrollPane.setViewportView(getJTable()); | |
} | |
return jScrollPane; | |
} | |
/** | |
This method initializes jTable | |
@return javax.swing.JTable | |
**/ | |
private JTable getJTable() { | |
if (jTable == null) { | |
model = new DefaultTableModel(); | |
jTable = new JTable(model); | |
jTable.setRowHeight(20); | |
model.addColumn("Name"); | |
model.addColumn("C_Name"); | |
model.addColumn("GUID"); | |
if (sfc.getSpdGuidDeclarationCount() == 0) { | |
return jTable; | |
} | |
// | |
// initialize table using SpdFileContents object | |
// | |
String[][] saa = new String[sfc.getSpdGuidDeclarationCount()][3]; | |
sfc.getSpdGuidDeclarations(saa); | |
int i = 0; | |
while (i < saa.length) { | |
model.addRow(saa[i]); | |
i++; | |
} | |
jTable.getColumnModel().getColumn(2).setCellEditor(new GuidEditor()); | |
} | |
return jTable; | |
} | |
/** | |
Remove original GUID declarations before saving updated ones | |
**/ | |
protected void save() { | |
if (jTable.isEditing()) { | |
jTable.getCellEditor().stopCellEditing(); | |
} | |
sfc.removeSpdGuidDeclaration(); | |
int rowCount = model.getRowCount(); | |
int i = 0; | |
while (i < rowCount) { | |
String name = null; | |
if (model.getValueAt(i, 0) != null) { | |
name = model.getValueAt(i, 0).toString(); | |
} | |
String cName = null; | |
if (model.getValueAt(i, 1) != null) { | |
cName = model.getValueAt(i, 1).toString(); | |
} | |
String guid = null; | |
if (model.getValueAt(i, 2) != null) { | |
guid = model.getValueAt(i, 2).toString(); | |
} | |
sfc.genSpdGuidDeclarations(name, cName, guid, null); | |
i++; | |
} | |
} | |
/** | |
This method initializes jButtonOk | |
@return javax.swing.JButton | |
**/ | |
private JButton getJButtonOk() { | |
if (jButtonOk == null) { | |
jButtonOk = new JButton(); | |
jButtonOk.setText("Ok"); | |
jButtonOk.setSize(new java.awt.Dimension(84, 20)); | |
jButtonOk.setLocation(new java.awt.Point(316, 486)); | |
jButtonOk.addActionListener(this); | |
} | |
return jButtonOk; | |
} | |
/** | |
This method initializes jButtonCancel | |
@return javax.swing.JButton | |
**/ | |
private JButton getJButtonCancel() { | |
if (jButtonCancel == null) { | |
jButtonCancel = new JButton(); | |
jButtonCancel.setText("Cancel"); | |
jButtonCancel.setSize(new java.awt.Dimension(82, 20)); | |
jButtonCancel.setLocation(new java.awt.Point(411, 486)); | |
jButtonCancel.addActionListener(this); | |
} | |
return jButtonCancel; | |
} | |
/** | |
This method initializes jButton | |
@return javax.swing.JButton | |
**/ | |
private JButton getJButton() { | |
if (jButton == null) { | |
jButton = new JButton(); | |
jButton.setBounds(new java.awt.Rectangle(219, 487, 78, 18)); | |
jButton.setText("Insert"); | |
jButton.addActionListener(this); | |
} | |
return jButton; | |
} | |
/** | |
Start the window at the center of screen | |
**/ | |
protected void centerWindow(int intWidth, int intHeight) { | |
Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); | |
this.setLocation((d.width - intWidth) / 2, (d.height - intHeight) / 2); | |
} | |
/** | |
Start the window at the center of screen | |
**/ | |
protected void centerWindow() { | |
centerWindow(this.getSize().width, this.getSize().height); | |
} | |
} // @jve:decl-index=0:visual-constraint="11,7" |