2 Java class FpdFvOptions is GUI for FV options in FPD 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
.platform
.ui
;
15 import java
.awt
.BorderLayout
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
18 import java
.awt
.event
.MouseEvent
;
19 import java
.awt
.event
.WindowEvent
;
20 import java
.util
.Iterator
;
21 import java
.util
.LinkedHashMap
;
24 import javax
.swing
.JFrame
;
25 import javax
.swing
.JOptionPane
;
26 import javax
.swing
.JPanel
;
27 import javax
.swing
.JDialog
;
28 import javax
.swing
.JScrollPane
;
29 import javax
.swing
.JTable
;
30 import javax
.swing
.ListSelectionModel
;
31 import javax
.swing
.event
.ListSelectionEvent
;
32 import javax
.swing
.event
.ListSelectionListener
;
33 import javax
.swing
.event
.TableModelEvent
;
34 import javax
.swing
.event
.TableModelListener
;
35 import javax
.swing
.table
.DefaultTableModel
;
36 import javax
.swing
.table
.TableModel
;
37 import javax
.swing
.JButton
;
39 import org
.tianocore
.frameworkwizard
.FrameworkWizardUI
;
40 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningPlatformType
;
46 public class FpdFvOptions
extends JDialog
{
51 private static final long serialVersionUID
= 1L;
52 private static JFrame frame
;
53 private JPanel jContentPane
= null;
54 private JPanel jPanelN
= null;
55 private JPanel jPanelS
= null;
56 private JPanel jPanelC
= null;
57 private JScrollPane jScrollPaneFvOptions
= null;
58 private JTable jTableFvOptions
= null;
59 private DefaultTableModel tableModel
= null;
60 private String fvName
= null;
61 private FpdFileContents ffc
= null;
62 private OpeningPlatformType docConsole
= null;
63 private JButton jButtonNew
= null;
64 private JButton jButtonDelete
= null;
65 private String oldOptionName
= "";
66 private int selectedRow
= -1;
67 private TableModelListener tableModelListener
= null;
70 * This is the default constructor
72 public FpdFvOptions(String name
, DefaultTableModel tm
, FpdFileContents ffc
, OpeningPlatformType dc
) {
73 super(FrameworkWizardUI
.getInstance());
83 protected void processWindowEvent (WindowEvent e
) {
84 if (e
.getID() == WindowEvent
.WINDOW_CLOSING
) {
85 if (jTableFvOptions
.isEditing()) {
86 jTableFvOptions
.getCellEditor().stopCellEditing();
88 tableModel
.removeTableModelListener(tableModelListener
);
93 private void initOptions() {
94 tableModel
.setRowCount(0);
95 LinkedHashMap
<String
, String
> mOpts
= new LinkedHashMap
<String
, String
>();
96 ffc
.getFvImagesFvImageOptions(fvName
, mOpts
);
97 Set
<String
> sKey
= mOpts
.keySet();
98 Iterator
<String
> iter
= sKey
.iterator();
99 while (iter
.hasNext()) {
100 String name
= iter
.next();
101 String value
= mOpts
.get(name
);
102 tableModel
.addRow(new String
[]{name
, value
});
106 private boolean fvOptionNameExists (String name
) {
108 for (int i
= 0; i
< jTableFvOptions
.getRowCount(); ++i
) {
109 if (getTableModel().getValueAt(i
, 0).equals(name
)) {
119 * This method initializes this
123 private void initialize() {
124 this.setSize(650, 400);
126 this.setTitle("FV Options");
127 this.setDefaultCloseOperation(JDialog
.DO_NOTHING_ON_CLOSE
);
128 this.setContentPane(getJContentPane());
130 this.setVisible(true);
135 * This method initializes jContentPane
137 * @return javax.swing.JPanel
139 private JPanel
getJContentPane() {
140 if (jContentPane
== null) {
141 jContentPane
= new JPanel();
142 jContentPane
.setLayout(new BorderLayout());
143 jContentPane
.add(getJPanelN(), java
.awt
.BorderLayout
.NORTH
);
144 jContentPane
.add(getJPanelS(), java
.awt
.BorderLayout
.SOUTH
);
145 jContentPane
.add(getJPanelC(), java
.awt
.BorderLayout
.CENTER
);
151 * This method initializes jPanelN
153 * @return javax.swing.JPanel
155 private JPanel
getJPanelN() {
156 if (jPanelN
== null) {
157 jPanelN
= new JPanel();
163 * This method initializes jPanelS
165 * @return javax.swing.JPanel
167 private JPanel
getJPanelS() {
168 if (jPanelS
== null) {
169 jPanelS
= new JPanel();
170 jPanelS
.add(getJButtonNew(), null);
171 jPanelS
.add(getJButtonDelete(), null);
177 * This method initializes jPanelC
179 * @return javax.swing.JPanel
181 private JPanel
getJPanelC() {
182 if (jPanelC
== null) {
183 jPanelC
= new JPanel();
184 jPanelC
.add(getJScrollPaneFvOptions(), null);
190 * This method initializes jScrollPaneFvOptions
192 * @return javax.swing.JScrollPane
194 private JScrollPane
getJScrollPaneFvOptions() {
195 if (jScrollPaneFvOptions
== null) {
196 jScrollPaneFvOptions
= new JScrollPane();
197 jScrollPaneFvOptions
.setPreferredSize(new java
.awt
.Dimension(600,320));
198 jScrollPaneFvOptions
.setViewportView(getJTableFvOptions());
200 return jScrollPaneFvOptions
;
204 * This method initializes jTableFvOptions
206 * @return javax.swing.JTable
208 private JTable
getJTableFvOptions() {
209 if (jTableFvOptions
== null) {
210 jTableFvOptions
= new JTable(getTableModel()) {
214 private static final long serialVersionUID
= -1941328952828651192L;
216 public String
getToolTipText(MouseEvent e
) {
218 java
.awt
.Point p
= e
.getPoint();
219 int rowIndex
= rowAtPoint(p
);
220 // int colIndex = columnAtPoint(p);
221 // int realColumnIndex = convertColumnIndexToModel(colIndex);
223 TableModel model
= getModel();
224 String optName
= (String
) model
.getValueAt(rowIndex
, 0);
225 if (((FvOptsTableModel
)model
).getVKeyWords().contains(optName
)){
226 tip
= optName
+ " is from Flash Definition File and it is NOT editable.";
234 jTableFvOptions
.setRowHeight(20);
236 jTableFvOptions
.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
237 public void valueChanged(ListSelectionEvent e
) {
238 if (e
.getValueIsAdjusting()) {
241 ListSelectionModel lsm
= (ListSelectionModel
) e
.getSource();
242 if (lsm
.isSelectionEmpty()) {
245 selectedRow
= lsm
.getMinSelectionIndex();
246 oldOptionName
= getTableModel().getValueAt(selectedRow
, 0)+"";
251 tableModelListener
= new TableModelListener() {
252 public void tableChanged(TableModelEvent arg0
) {
253 // TODO Auto-generated method stub
254 int row
= arg0
.getFirstRow();
255 int col
= arg0
.getColumn();
256 TableModel m
= (TableModel
) arg0
.getSource();
258 if (arg0
.getType() == TableModelEvent
.UPDATE
) {
259 String newOptionName
= m
.getValueAt(row
, 0) + "";
261 if (newOptionName
.equals(oldOptionName
)) {
264 if (fvOptionNameExists(newOptionName
)) {
265 JOptionPane
.showMessageDialog(frame
, "This Option already exists. Please choose another Option name.");
266 m
.setValueAt(oldOptionName
, row
, 0);
270 ffc
.setTypedNamedFvImageNameValue(fvName
, "Options", oldOptionName
, m
.getValueAt(row
, 1)+"", newOptionName
);
271 docConsole
.setSaved(false);
272 oldOptionName
= newOptionName
;
276 ffc
.setTypedNamedFvImageNameValue(fvName
, "Options", oldOptionName
, m
.getValueAt(row
, 1)+"", newOptionName
);
277 docConsole
.setSaved(false);
284 jTableFvOptions
.getModel().addTableModelListener(tableModelListener
);
286 return jTableFvOptions
;
289 protected DefaultTableModel
getTableModel() {
293 protected void setTableModel(DefaultTableModel tableModel
) {
295 this.tableModel
= tableModel
;
300 Start the window at the center of screen
303 protected void centerWindow(int intWidth
, int intHeight
) {
304 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
305 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
309 Start the window at the center of screen
312 protected void centerWindow() {
313 centerWindow(this.getSize().width
, this.getSize().height
);
317 * This method initializes jButtonNew
319 * @return javax.swing.JButton
321 private JButton
getJButtonNew() {
322 if (jButtonNew
== null) {
323 jButtonNew
= new JButton();
324 jButtonNew
.setPreferredSize(new java
.awt
.Dimension(80,20));
325 jButtonNew
.setText("New");
326 jButtonNew
.addActionListener(new java
.awt
.event
.ActionListener() {
327 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
328 tableModel
.addRow(new String
[]{"", ""});
337 * This method initializes jButtonDelete
339 * @return javax.swing.JButton
341 private JButton
getJButtonDelete() {
342 if (jButtonDelete
== null) {
343 jButtonDelete
= new JButton();
344 jButtonDelete
.setPreferredSize(new java
.awt
.Dimension(80,20));
345 jButtonDelete
.setText("Delete");
346 jButtonDelete
.addActionListener(new java
.awt
.event
.ActionListener() {
347 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
348 int selectedRow
= jTableFvOptions
.getSelectedRow();
349 if (selectedRow
< 0) {
352 String optName
= tableModel
.getValueAt(selectedRow
, 0)+"";
353 if (((FvOptsTableModel
)tableModel
).getVKeyWords().contains(optName
)){
356 if (((FvOptsTableModel
)tableModel
).getVNonEditableName().contains(optName
)){
360 ffc
.removeTypedNamedFvImageNameValue(fvName
, "Options", optName
);
361 tableModel
.removeRow(selectedRow
);
362 docConsole
.setSaved(false);
366 return jButtonDelete
;