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
.Dimension
;
16 import java
.awt
.event
.ActionEvent
;
17 import java
.awt
.event
.ComponentEvent
;
20 import javax
.swing
.AbstractAction
;
21 import javax
.swing
.JFileChooser
;
22 import javax
.swing
.JOptionPane
;
23 import javax
.swing
.JPanel
;
24 import javax
.swing
.JTable
;
25 import javax
.swing
.JTextField
;
26 import javax
.swing
.JLabel
;
27 import javax
.swing
.JScrollPane
;
28 import javax
.swing
.JButton
;
29 import javax
.swing
.JFrame
;
30 import javax
.swing
.ListSelectionModel
;
31 import javax
.swing
.event
.InternalFrameAdapter
;
32 import javax
.swing
.event
.InternalFrameEvent
;
33 import javax
.swing
.event
.ListSelectionEvent
;
34 import javax
.swing
.event
.ListSelectionListener
;
35 import javax
.swing
.event
.TableModelEvent
;
36 import javax
.swing
.event
.TableModelListener
;
37 import javax
.swing
.table
.DefaultTableModel
;
38 import javax
.swing
.table
.TableModel
;
40 import org
.tianocore
.PackageSurfaceAreaDocument
;
41 import org
.tianocore
.frameworkwizard
.common
.Tools
;
42 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningPackageType
;
43 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
44 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
47 GUI for create library definition elements of spd file.
49 @since PackageEditor 1.0
51 public class SpdMsaFiles
extends IInternalFrame
implements TableModelListener
{
55 private static final long serialVersionUID
= 1L;
59 private JScrollPane jScrollPane
= null; // @jve:decl-index=0:visual-constraint="10,95"
61 private JTable jTable
= null;
63 private DefaultTableModel model
= null;
65 private JPanel jContentPane
= null;
67 private JScrollPane jScrollPaneMsa
= null;
69 private JButton jButtonAdd
= null;
71 private JButton jButtonRemove
= null;
73 private JButton jButtonClearAll
= null;
75 private JButton jButtonCancel
= null;
77 private JButton jButtonOk
= null;
79 private JLabel jLabel
= null;
81 private JTextField jTextField
= null;
83 private JButton jButtonBrowse
= null;
85 private StarLabel jStarLabel2
= null;
87 private SpdFileContents sfc
= null;
89 private OpeningPackageType docConsole
= null;
91 private int selectedRow
= -1;
94 This method initializes this
97 private void initialize() {
99 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
104 This method initializes jScrollPane
106 @return javax.swing.JScrollPane
108 private JScrollPane
getJScrollPaneMsa() {
109 if (jScrollPaneMsa
== null) {
110 jScrollPaneMsa
= new JScrollPane();
111 jScrollPaneMsa
.setBounds(new java
.awt
.Rectangle(13,177,461,421));
112 jScrollPaneMsa
.setViewportView(getJTable());
114 return jScrollPaneMsa
;
118 This method initializes jTable
120 @return javax.swing.JTable
122 private JTable
getJTable() {
123 if (jTable
== null) {
124 model
= new DefaultTableModel();
125 jTable
= new JTable(model
);
126 jTable
.setRowHeight(20);
127 model
.addColumn("MsaFile");
129 jTable
.setSelectionMode(ListSelectionModel
.SINGLE_SELECTION
);
130 jTable
.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
131 public void valueChanged(ListSelectionEvent e
) {
132 if (e
.getValueIsAdjusting()){
135 ListSelectionModel lsm
= (ListSelectionModel
)e
.getSource();
136 if (lsm
.isSelectionEmpty()) {
140 selectedRow
= lsm
.getMinSelectionIndex();
145 jTable
.getModel().addTableModelListener(this);
150 This method initializes jButtonAdd
152 @return javax.swing.JButton
154 private JButton
getJButtonAdd() {
155 if (jButtonAdd
== null) {
156 jButtonAdd
= new JButton();
157 jButtonAdd
.setBounds(new java
.awt
.Rectangle(163,148,90,20));
158 jButtonAdd
.setText("Add");
159 jButtonAdd
.addActionListener(this);
165 This method initializes jButtonRemove
167 @return javax.swing.JButton
169 private JButton
getJButtonRemove() {
170 if (jButtonRemove
== null) {
171 jButtonRemove
= new JButton();
172 jButtonRemove
.setBounds(new java
.awt
.Rectangle(266,148,90,20));
173 jButtonRemove
.setText("Remove");
174 jButtonRemove
.addActionListener(this);
176 return jButtonRemove
;
180 This method initializes jButtonRemoveAll
182 @return javax.swing.JButton
184 private JButton
getJButtonClearAll() {
185 if (jButtonClearAll
== null) {
186 jButtonClearAll
= new JButton();
187 jButtonClearAll
.setBounds(new java
.awt
.Rectangle(374,148,90,20));
188 jButtonClearAll
.setText("Clear All");
189 jButtonClearAll
.addActionListener(this);
191 return jButtonClearAll
;
195 This method initializes jButtonCancel
197 @return javax.swing.JButton
199 private JButton
getJButtonCancel() {
200 if (jButtonCancel
== null) {
201 jButtonCancel
= new JButton();
202 jButtonCancel
.setPreferredSize(new java
.awt
.Dimension(90, 20));
203 jButtonCancel
.setLocation(new java
.awt
.Point(390, 305));
204 jButtonCancel
.setText("Cancel");
205 jButtonCancel
.setSize(new java
.awt
.Dimension(90, 20));
206 jButtonCancel
.setVisible(false);
207 jButtonCancel
.addActionListener(this);
209 return jButtonCancel
;
213 This method initializes jButton
215 @return javax.swing.JButton
217 private JButton
getJButtonOk() {
218 if (jButtonOk
== null) {
219 jButtonOk
= new JButton();
220 jButtonOk
.setSize(new java
.awt
.Dimension(90, 20));
221 jButtonOk
.setText("OK");
222 jButtonOk
.setLocation(new java
.awt
.Point(290, 305));
223 jButtonOk
.setVisible(false);
224 jButtonOk
.addActionListener(this);
230 This is the default constructor
232 public SpdMsaFiles() {
239 public SpdMsaFiles(PackageSurfaceAreaDocument
.PackageSurfaceArea inPsa
){
241 sfc
= new SpdFileContents(inPsa
);
245 public SpdMsaFiles(OpeningPackageType opt
){
246 this(opt
.getXmlSpd());
250 This method initializes this
254 private void init() {
255 this.setBounds(new java
.awt
.Rectangle(0, 0, 500, 370));
256 this.setPreferredSize(new Dimension(490, 400));
257 this.setContentPane(getJScrollPane());
258 this.setTitle("Msa Files");
259 this.addInternalFrameListener(new InternalFrameAdapter(){
260 public void internalFrameDeactivated(InternalFrameEvent e
){
261 if (jTable
.isEditing()) {
262 jTable
.getCellEditor().stopCellEditing();
266 this.setVisible(true);
270 private void init(SpdFileContents sfc
){
271 if (sfc
.getSpdMsaFileCount() == 0) {
275 // initialize table using SpdFileContents object
277 String
[][] saa
= new String
[sfc
.getSpdMsaFileCount()][4];
278 sfc
.getSpdMsaFiles(saa
);
280 while (i
< saa
.length
) {
281 model
.addRow(saa
[i
]);
286 private JScrollPane
getJScrollPane(){
287 if (jScrollPane
== null){
288 jScrollPane
= new JScrollPane();
289 jScrollPane
.setViewportView(getJContentPane());
294 This method initializes jContentPane
296 @return javax.swing.JPanel
298 private JPanel
getJContentPane() {
299 if (jContentPane
== null) {
300 jStarLabel2
= new StarLabel();
301 jStarLabel2
.setLocation(new java
.awt
.Point(2,24));
302 jLabel
= new JLabel();
303 jLabel
.setBounds(new java
.awt
.Rectangle(17,24,111,22));
304 jLabel
.setText("Msa File ");
306 jContentPane
= new JPanel();
307 jContentPane
.setPreferredSize(new Dimension(480, 325));
308 jContentPane
.setLayout(null);
309 jContentPane
.add(jLabel
, null);
310 jContentPane
.add(jStarLabel2
, null);
311 jContentPane
.add(getJScrollPaneMsa(), null);
312 jContentPane
.add(getJButtonAdd(), null);
313 jContentPane
.add(getJButtonRemove(), null);
314 jContentPane
.add(getJButtonClearAll(), null);
315 jContentPane
.add(getJButtonCancel(), null);
316 jContentPane
.add(getJButtonOk(), null);
318 jContentPane
.add(getJTextField(), null);
319 jContentPane
.add(getJButtonBrowse(), null);
325 fill ComboBoxes with pre-defined contents
327 private void initFrame() {
332 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
334 public void actionPerformed(ActionEvent arg0
) {
336 docConsole
.setSaved(false);
337 if (arg0
.getSource() == jButtonOk
) {
342 if (arg0
.getSource() == jButtonCancel
) {
346 if (arg0
.getSource() == jButtonAdd
) {
347 //ToDo: check before add
348 String
[] row
= {jTextField
.getText().replace('\\', '/')};
349 if (jTextField
.getText().length() == 0) {
350 JOptionPane
.showMessageDialog(this, "Msa File is NOT PathAndFilename type.");
354 jTable
.changeSelection(model
.getRowCount()-1, 0, false, false);
355 sfc
.genSpdMsaFiles(row
[0], null, null, null);
358 // remove selected line
360 if (arg0
.getSource() == jButtonRemove
) {
361 if (jTable
.isEditing()){
362 jTable
.getCellEditor().stopCellEditing();
364 int rowSelected
= selectedRow
;
365 if (rowSelected
>= 0) {
366 model
.removeRow(rowSelected
);
367 sfc
.removeSpdMsaFile(rowSelected
);
371 if (arg0
.getSource() == jButtonClearAll
) {
372 if (model
.getRowCount() == 0) {
375 model
.setRowCount(0);
376 sfc
.removeSpdMsaFile();
381 public void tableChanged(TableModelEvent arg0
) {
382 // TODO Auto-generated method stub
383 int row
= arg0
.getFirstRow();
384 int column
= arg0
.getColumn();
385 TableModel m
= (TableModel
)arg0
.getSource();
386 if (arg0
.getType() == TableModelEvent
.UPDATE
){
387 String
[] sa
= new String
[1];
388 sfc
.getSpdMsaFile(sa
, row
);
389 Object cellData
= m
.getValueAt(row
, column
);
390 if (cellData
== null) {
393 if (cellData
.equals(sa
[column
])) {
396 if (cellData
.toString().length() == 0 && sa
[column
] == null) {
399 String file
= m
.getValueAt(row
, 0) + "";
400 if (file
.length() == 0) {
401 JOptionPane
.showMessageDialog(this, "Msa File is NOT PathAndFilename type.");
404 docConsole
.setSaved(false);
405 sfc
.updateSpdMsaFile(row
, file
, null, null, null);
410 Add contents in list to sfc
412 protected void save() {
417 This method initializes jTextField
419 @return javax.swing.JTextField
421 private JTextField
getJTextField() {
422 if (jTextField
== null) {
423 jTextField
= new JTextField();
424 jTextField
.setBounds(new java
.awt
.Rectangle(14,51,346,21));
425 jTextField
.setPreferredSize(new java
.awt
.Dimension(345,20));
431 This method initializes jButtonBrowse
433 @return javax.swing.JButton
435 private JButton
getJButtonBrowse() {
436 if (jButtonBrowse
== null) {
437 jButtonBrowse
= new JButton();
438 jButtonBrowse
.setBounds(new java
.awt
.Rectangle(376,50,92,21));
439 jButtonBrowse
.setText("Browse");
440 jButtonBrowse
.setPreferredSize(new java
.awt
.Dimension(90,20));
441 jButtonBrowse
.addActionListener(new AbstractAction() {
445 private static final long serialVersionUID
= 1L;
447 public void actionPerformed(ActionEvent e
) {
449 // Select files from current workspace
451 String dirPrefix
= Tools
.dirForNewSpd
.substring(0, Tools
.dirForNewSpd
.lastIndexOf(File
.separator
));
452 JFileChooser chooser
= new JFileChooser(dirPrefix
);
454 String headerDest
= null;
456 chooser
.setMultiSelectionEnabled(false);
457 chooser
.setFileSelectionMode(JFileChooser
.FILES_AND_DIRECTORIES
);
458 int retval
= chooser
.showOpenDialog(frame
);
459 if (retval
== JFileChooser
.APPROVE_OPTION
) {
461 theFile
= chooser
.getSelectedFile();
462 String file
= theFile
.getPath();
463 if (!file
.startsWith(dirPrefix
)) {
464 JOptionPane
.showMessageDialog(frame
, "You can only select files in current package!");
474 headerDest
= theFile
.getPath();
475 int fileIndex
= headerDest
.indexOf(System
.getProperty("file.separator"), dirPrefix
.length());
477 jTextField
.setText(headerDest
.substring(fileIndex
+ 1).replace('\\', '/'));
482 return jButtonBrowse
;
485 public void componentResized(ComponentEvent arg0
) {
486 int intPreferredWidth
= 500;
488 resizeComponentWidth(this.jScrollPaneMsa
, this.getWidth(), intPreferredWidth
);
489 resizeComponentWidth(this.jTextField
, this.getWidth(), intPreferredWidth
);
490 relocateComponentX(this.jButtonBrowse
, this.getWidth(), this.getPreferredSize().width
, 25);
493 public static void main(String
[] args
){
494 new SpdMsaFiles().setVisible(true);