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