2 Java class SpdMsaFiles 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
.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
.awt
.event
.ComponentEvent
;
22 import java
.util
.Vector
;
24 import javax
.swing
.AbstractAction
;
25 import javax
.swing
.DefaultListModel
;
26 import javax
.swing
.JFileChooser
;
27 import javax
.swing
.JOptionPane
;
28 import javax
.swing
.JPanel
;
29 import javax
.swing
.JRadioButton
;
30 import javax
.swing
.JTable
;
31 import javax
.swing
.JTextField
;
32 import javax
.swing
.JComboBox
;
33 import javax
.swing
.JLabel
;
34 import javax
.swing
.JList
;
35 import javax
.swing
.JScrollPane
;
36 import javax
.swing
.JButton
;
37 import javax
.swing
.JFrame
;
38 import javax
.swing
.ListSelectionModel
;
39 import javax
.swing
.event
.InternalFrameAdapter
;
40 import javax
.swing
.event
.InternalFrameEvent
;
41 import javax
.swing
.event
.ListSelectionEvent
;
42 import javax
.swing
.event
.ListSelectionListener
;
43 import javax
.swing
.event
.TableModelEvent
;
44 import javax
.swing
.event
.TableModelListener
;
45 import javax
.swing
.table
.DefaultTableModel
;
46 import javax
.swing
.table
.TableModel
;
48 import org
.tianocore
.PackageSurfaceAreaDocument
;
49 import org
.tianocore
.frameworkwizard
.common
.DataType
;
50 import org
.tianocore
.frameworkwizard
.common
.Tools
;
51 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
52 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
55 GUI for create library definition elements of spd file.
57 @since PackageEditor 1.0
59 public class SpdMsaFiles
extends IInternalFrame
implements TableModelListener
{
62 private JScrollPane jScrollPane
= null; // @jve:decl-index=0:visual-constraint="10,95"
64 private JTable jTable
= null;
66 private DefaultTableModel model
= null;
68 private JPanel jContentPane
= null;
70 private JScrollPane jScrollPane1
= 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 jStarLabel2
= null;
90 private SpdFileContents sfc
= null;
92 private int selectedRow
= -1;
95 This method initializes this
98 private void initialize() {
100 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
105 This method initializes jScrollPane
107 @return javax.swing.JScrollPane
109 private JScrollPane
getJScrollPane1() {
110 if (jScrollPane1
== null) {
111 jScrollPane1
= new JScrollPane();
112 jScrollPane1
.setBounds(new java
.awt
.Rectangle(13,177,461,139));
113 jScrollPane1
.setViewportView(getJTable());
119 This method initializes jTable
121 @return javax.swing.JTable
123 private JTable
getJTable() {
124 if (jTable
== null) {
125 model
= new DefaultTableModel();
126 jTable
= new JTable(model
);
127 jTable
.setRowHeight(20);
128 model
.addColumn("MsaFile");
130 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
131 jTable
.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
132 public void valueChanged(ListSelectionEvent e
) {
133 if (e
.getValueIsAdjusting()){
136 ListSelectionModel lsm
= (ListSelectionModel
)e
.getSource();
137 if (lsm
.isSelectionEmpty()) {
141 selectedRow
= lsm
.getMinSelectionIndex();
146 jTable
.getModel().addTableModelListener(this);
151 This method initializes jButtonAdd
153 @return javax.swing.JButton
155 private JButton
getJButtonAdd() {
156 if (jButtonAdd
== null) {
157 jButtonAdd
= new JButton();
158 jButtonAdd
.setBounds(new java
.awt
.Rectangle(163,148,90,20));
159 jButtonAdd
.setText("Add");
160 jButtonAdd
.addActionListener(this);
166 This method initializes jButtonRemove
168 @return javax.swing.JButton
170 private JButton
getJButtonRemove() {
171 if (jButtonRemove
== null) {
172 jButtonRemove
= new JButton();
173 jButtonRemove
.setBounds(new java
.awt
.Rectangle(266,148,90,20));
174 jButtonRemove
.setText("Remove");
175 jButtonRemove
.addActionListener(this);
177 return jButtonRemove
;
181 This method initializes jButtonRemoveAll
183 @return javax.swing.JButton
185 private JButton
getJButtonClearAll() {
186 if (jButtonClearAll
== null) {
187 jButtonClearAll
= new JButton();
188 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(374,148,90,20));
189 jButtonClearAll
.setText("Clear All");
190 jButtonClearAll
.addActionListener(this);
192 return jButtonClearAll
;
196 This method initializes jButtonCancel
198 @return javax.swing.JButton
200 private JButton
getJButtonCancel() {
201 if (jButtonCancel
== null) {
202 jButtonCancel
= new JButton();
203 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
204 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
205 jButtonCancel
.setText("Cancel");
206 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
207 jButtonCancel
.setVisible(false);
208 jButtonCancel
.addActionListener(this);
210 return jButtonCancel
;
214 This method initializes jButton
216 @return javax.swing.JButton
218 private JButton
getJButtonOk() {
219 if (jButtonOk
== null) {
220 jButtonOk
= new JButton();
221 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
222 jButtonOk
.setText("OK");
223 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
224 jButtonOk
.setVisible(false);
225 jButtonOk
.addActionListener(this);
231 This is the default constructor
233 public SpdMsaFiles() {
240 public SpdMsaFiles(PackageSurfaceAreaDocument
.PackageSurfaceArea inPsa
){
242 sfc
= new SpdFileContents(inPsa
);
246 This method initializes this
250 private void init() {
251 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
252 this.setPreferredSize(new Dimension(490, 400));
253 this.setContentPane(getJScrollPane());
254 this.setTitle("Msa Files");
255 this.addInternalFrameListener(new InternalFrameAdapter(){
256 public void internalFrameDeactivated(InternalFrameEvent e
){
257 if (jTable
.isEditing()) {
258 jTable
.getCellEditor().stopCellEditing();
262 this.setVisible(true);
266 private void init(SpdFileContents sfc
){
267 if (sfc
.getSpdMsaFileCount() == 0) {
271 // initialize table using SpdFileContents object
273 String
[][] saa
= new String
[sfc
.getSpdMsaFileCount()][4];
274 sfc
.getSpdMsaFiles(saa
);
276 while (i
< saa
.length
) {
277 model
.addRow(saa
[i
]);
282 private JScrollPane
getJScrollPane(){
283 if (jScrollPane
== null){
284 jScrollPane
= new JScrollPane();
285 jScrollPane
.setViewportView(getJContentPane());
290 This method initializes jContentPane
292 @return javax.swing.JPanel
294 private JPanel
getJContentPane() {
295 if (jContentPane
== null) {
296 jStarLabel2
= new StarLabel();
297 jStarLabel2
.setLocation(new java
.awt
.Point(2,24));
298 jLabel
= new JLabel();
299 jLabel
.setBounds(new java
.awt
.Rectangle(17,24,111,22));
300 jLabel
.setText("Msa File ");
302 jContentPane
= new JPanel();
303 jContentPane
.setPreferredSize(new Dimension(480, 325));
304 jContentPane
.setLayout(null);
305 jContentPane
.add(jLabel
, null);
306 jContentPane
.add(jStarLabel2
, null);
307 jContentPane
.add(getJScrollPane1(), null);
308 jContentPane
.add(getJButtonAdd(), null);
309 jContentPane
.add(getJButtonRemove(), null);
310 jContentPane
.add(getJButtonClearAll(), null);
311 jContentPane
.add(getJButtonCancel(), null);
312 jContentPane
.add(getJButtonOk(), null);
314 jContentPane
.add(getJTextField(), null);
315 jContentPane
.add(getJButtonBrowse(), null);
321 fill ComboBoxes with pre-defined contents
323 private void initFrame() {
328 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
330 public void actionPerformed(ActionEvent arg0
) {
331 if (arg0
.getSource() == jButtonOk
) {
336 if (arg0
.getSource() == jButtonCancel
) {
340 if (arg0
.getSource() == jButtonAdd
) {
341 //ToDo: check before add
342 String
[] row
= {jTextField
.getText().replace('\\', '/')};
345 sfc
.genSpdMsaFiles(row
[0], null, null, null);
348 // remove selected line
350 if (arg0
.getSource() == jButtonRemove
) {
351 if (jTable
.isEditing()){
352 jTable
.getCellEditor().stopCellEditing();
354 int rowSelected
= selectedRow
;
355 if (rowSelected
>= 0) {
356 model
.removeRow(rowSelected
);
357 sfc
.removeSpdMsaFile(rowSelected
);
361 if (arg0
.getSource() == jButtonClearAll
) {
362 if (model
.getRowCount() == 0) {
365 model
.setRowCount(0);
366 sfc
.removeSpdMsaFile();
371 public void tableChanged(TableModelEvent arg0
) {
372 // TODO Auto-generated method stub
373 int row
= arg0
.getFirstRow();
374 TableModel m
= (TableModel
)arg0
.getSource();
375 if (arg0
.getType() == TableModelEvent
.UPDATE
){
376 String file
= m
.getValueAt(row
, 0) + "";
378 sfc
.updateSpdMsaFile(row
, file
, null, null, null);
383 Add contents in list to sfc
385 protected void save() {
390 This method initializes jTextField
392 @return javax.swing.JTextField
394 private JTextField
getJTextField() {
395 if (jTextField
== null) {
396 jTextField
= new JTextField();
397 jTextField
.setBounds(new java
.awt
.Rectangle(14,51,346,21));
398 jTextField
.setPreferredSize(new java
.awt
.Dimension(345,20));
404 This method initializes jButtonBrowse
406 @return javax.swing.JButton
408 private JButton
getJButtonBrowse() {
409 if (jButtonBrowse
== null) {
410 jButtonBrowse
= new JButton();
411 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(376,50,92,21));
412 jButtonBrowse
.setText("Browse");
413 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(90,20));
414 jButtonBrowse
.addActionListener(new AbstractAction() {
415 public void actionPerformed(ActionEvent e
) {
417 // Select files from current workspace
419 String dirPrefix
= Tools
.dirForNewSpd
.substring(0, Tools
.dirForNewSpd
.lastIndexOf(File
.separator
));
420 JFileChooser chooser
= new JFileChooser(dirPrefix
);
422 String headerDest
= null;
424 chooser
.setMultiSelectionEnabled(false);
425 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
426 int retval
= chooser
.showOpenDialog(frame
);
427 if (retval
== JFileChooser
.APPROVE_OPTION
) {
429 theFile
= chooser
.getSelectedFile();
430 String file
= theFile
.getPath();
431 if (!file
.startsWith(dirPrefix
)) {
432 JOptionPane
.showMessageDialog(frame
, "You can only select files in current package!");
442 headerDest
= theFile
.getPath();
443 int fileIndex
= headerDest
.indexOf(System
.getProperty("file.separator"), dirPrefix
.length());
445 jTextField
.setText(headerDest
.substring(fileIndex
+ 1).replace('\\', '/'));
450 return jButtonBrowse
;
453 public void componentResized(ComponentEvent arg0
) {
454 int intPreferredWidth
= 500;
456 resizeComponentWidth(this.jScrollPane1
, this.getWidth(), intPreferredWidth
);
457 resizeComponentWidth(this.jTextField
, this.getWidth(), intPreferredWidth
);
458 relocateComponentX(this.jButtonBrowse
, this.getWidth(), this.getPreferredSize().width
, 25);
461 public static void main(String
[] args
){
462 new SpdMsaFiles().setVisible(true);