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
.common
.Identifications
.OpeningPlatformType
;
45 public class FpdFvOptions
extends JDialog
{
50 private static final long serialVersionUID
= 1L;
51 private static JFrame frame
;
52 private JPanel jContentPane
= null;
53 private JPanel jPanelN
= null;
54 private JPanel jPanelS
= null;
55 private JPanel jPanelC
= null;
56 private JScrollPane jScrollPaneFvOptions
= null;
57 private JTable jTableFvOptions
= null;
58 private DefaultTableModel tableModel
= null;
59 private String fvName
= null;
60 private FpdFileContents ffc
= null;
61 private OpeningPlatformType docConsole
= null;
62 private JButton jButtonNew
= null;
63 private JButton jButtonDelete
= null;
64 private String oldOptionName
= "";
65 private int selectedRow
= -1;
66 private TableModelListener tableModelListener
= null;
69 * This is the default constructor
71 public FpdFvOptions(String name
, DefaultTableModel tm
, FpdFileContents ffc
, OpeningPlatformType dc
) {
82 protected void processWindowEvent (WindowEvent e
) {
83 if (e
.getID() == WindowEvent
.WINDOW_CLOSING
) {
84 if (jTableFvOptions
.isEditing()) {
85 jTableFvOptions
.getCellEditor().stopCellEditing();
87 tableModel
.removeTableModelListener(tableModelListener
);
92 private void initOptions() {
93 tableModel
.setRowCount(0);
94 LinkedHashMap
<String
, String
> mOpts
= new LinkedHashMap
<String
, String
>();
95 ffc
.getFvImagesFvImageOptions(fvName
, mOpts
);
96 Set
<String
> sKey
= mOpts
.keySet();
97 Iterator
<String
> iter
= sKey
.iterator();
98 while (iter
.hasNext()) {
99 String name
= iter
.next();
100 String value
= mOpts
.get(name
);
101 tableModel
.addRow(new String
[]{name
, value
});
105 private boolean fvOptionNameExists (String name
) {
107 for (int i
= 0; i
< jTableFvOptions
.getRowCount(); ++i
) {
108 if (getTableModel().getValueAt(i
, 0).equals(name
)) {
118 * This method initializes this
122 private void initialize() {
123 this.setSize(650, 400);
124 // this.setModal(true);
125 this.setTitle("FV Options");
126 this.setDefaultCloseOperation(JDialog
.DO_NOTHING_ON_CLOSE
);
127 this.setContentPane(getJContentPane());
129 this.setVisible(true);
134 * This method initializes jContentPane
136 * @return javax.swing.JPanel
138 private JPanel
getJContentPane() {
139 if (jContentPane
== null) {
140 jContentPane
= new JPanel();
141 jContentPane
.setLayout(new BorderLayout());
142 jContentPane
.add(getJPanelN(), java
.awt
.BorderLayout
.NORTH
);
143 jContentPane
.add(getJPanelS(), java
.awt
.BorderLayout
.SOUTH
);
144 jContentPane
.add(getJPanelC(), java
.awt
.BorderLayout
.CENTER
);
150 * This method initializes jPanelN
152 * @return javax.swing.JPanel
154 private JPanel
getJPanelN() {
155 if (jPanelN
== null) {
156 jPanelN
= new JPanel();
162 * This method initializes jPanelS
164 * @return javax.swing.JPanel
166 private JPanel
getJPanelS() {
167 if (jPanelS
== null) {
168 jPanelS
= new JPanel();
169 jPanelS
.add(getJButtonNew(), null);
170 jPanelS
.add(getJButtonDelete(), null);
176 * This method initializes jPanelC
178 * @return javax.swing.JPanel
180 private JPanel
getJPanelC() {
181 if (jPanelC
== null) {
182 jPanelC
= new JPanel();
183 jPanelC
.add(getJScrollPaneFvOptions(), null);
189 * This method initializes jScrollPaneFvOptions
191 * @return javax.swing.JScrollPane
193 private JScrollPane
getJScrollPaneFvOptions() {
194 if (jScrollPaneFvOptions
== null) {
195 jScrollPaneFvOptions
= new JScrollPane();
196 jScrollPaneFvOptions
.setPreferredSize(new java
.awt
.Dimension(600,320));
197 jScrollPaneFvOptions
.setViewportView(getJTableFvOptions());
199 return jScrollPaneFvOptions
;
203 * This method initializes jTableFvOptions
205 * @return javax.swing.JTable
207 private JTable
getJTableFvOptions() {
208 if (jTableFvOptions
== null) {
209 jTableFvOptions
= new JTable(getTableModel()) {
213 private static final long serialVersionUID
= -1941328952828651192L;
215 public String
getToolTipText(MouseEvent e
) {
217 java
.awt
.Point p
= e
.getPoint();
218 int rowIndex
= rowAtPoint(p
);
219 // int colIndex = columnAtPoint(p);
220 // int realColumnIndex = convertColumnIndexToModel(colIndex);
222 TableModel model
= getModel();
223 String optName
= (String
) model
.getValueAt(rowIndex
, 0);
224 if (((FvOptsTableModel
)model
).getVKeyWords().contains(optName
)){
225 tip
= optName
+ " is from Flash Definition File and it is NOT editable.";
233 jTableFvOptions
.setRowHeight(20);
235 jTableFvOptions
.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
236 public void valueChanged(ListSelectionEvent e
) {
237 if (e
.getValueIsAdjusting()) {
240 ListSelectionModel lsm
= (ListSelectionModel
) e
.getSource();
241 if (lsm
.isSelectionEmpty()) {
244 selectedRow
= lsm
.getMinSelectionIndex();
245 oldOptionName
= getTableModel().getValueAt(selectedRow
, 0)+"";
250 tableModelListener
= new TableModelListener() {
251 public void tableChanged(TableModelEvent arg0
) {
252 // TODO Auto-generated method stub
253 int row
= arg0
.getFirstRow();
254 int col
= arg0
.getColumn();
255 TableModel m
= (TableModel
) arg0
.getSource();
257 if (arg0
.getType() == TableModelEvent
.UPDATE
) {
258 String newOptionName
= m
.getValueAt(row
, 0) + "";
260 if (newOptionName
.equals(oldOptionName
)) {
263 if (fvOptionNameExists(newOptionName
)) {
264 JOptionPane
.showMessageDialog(frame
, "This Option already exists. Please choose another Option name.");
265 m
.setValueAt(oldOptionName
, row
, 0);
269 ffc
.setTypedNamedFvImageNameValue(fvName
, "Options", oldOptionName
, m
.getValueAt(row
, 1)+"", newOptionName
);
270 docConsole
.setSaved(false);
271 oldOptionName
= newOptionName
;
275 ffc
.setTypedNamedFvImageNameValue(fvName
, "Options", oldOptionName
, m
.getValueAt(row
, 1)+"", newOptionName
);
276 docConsole
.setSaved(false);
283 jTableFvOptions
.getModel().addTableModelListener(tableModelListener
);
285 return jTableFvOptions
;
288 protected DefaultTableModel
getTableModel() {
292 protected void setTableModel(DefaultTableModel tableModel
) {
294 this.tableModel
= tableModel
;
299 Start the window at the center of screen
302 protected void centerWindow(int intWidth
, int intHeight
) {
303 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
304 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
308 Start the window at the center of screen
311 protected void centerWindow() {
312 centerWindow(this.getSize().width
, this.getSize().height
);
316 * This method initializes jButtonNew
318 * @return javax.swing.JButton
320 private JButton
getJButtonNew() {
321 if (jButtonNew
== null) {
322 jButtonNew
= new JButton();
323 jButtonNew
.setPreferredSize(new java
.awt
.Dimension(80,20));
324 jButtonNew
.setText("New");
325 jButtonNew
.addActionListener(new java
.awt
.event
.ActionListener() {
326 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
327 tableModel
.addRow(new String
[]{"", ""});
336 * This method initializes jButtonDelete
338 * @return javax.swing.JButton
340 private JButton
getJButtonDelete() {
341 if (jButtonDelete
== null) {
342 jButtonDelete
= new JButton();
343 jButtonDelete
.setPreferredSize(new java
.awt
.Dimension(80,20));
344 jButtonDelete
.setText("Delete");
345 jButtonDelete
.addActionListener(new java
.awt
.event
.ActionListener() {
346 public void actionPerformed(java
.awt
.event
.ActionEvent e
) {
347 int selectedRow
= jTableFvOptions
.getSelectedRow();
348 if (selectedRow
< 0) {
351 String optName
= tableModel
.getValueAt(selectedRow
, 0)+"";
352 if (((FvOptsTableModel
)tableModel
).getVKeyWords().contains(optName
)){
355 if (((FvOptsTableModel
)tableModel
).getVNonEditableName().contains(optName
)){
359 ffc
.removeTypedNamedFvImageNameValue(fvName
, "Options", optName
);
360 tableModel
.removeRow(selectedRow
);
361 docConsole
.setSaved(false);
365 return jButtonDelete
;