Flash Setting Refinement
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / platform / ui / FpdFlash.java
1 /** @file
2 Java class FpdFlash is GUI for Flash element operation in SPD file.
3
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
9
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.
12 **/
13 package org.tianocore.frameworkwizard.platform.ui;
14
15 import java.awt.BorderLayout;
16 import javax.swing.JPanel;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.DefaultCellEditor;
20 import javax.swing.JFileChooser;
21 import javax.swing.JFrame;
22 import javax.swing.JTabbedPane;
23 import javax.swing.JButton;
24 import javax.swing.ListSelectionModel;
25
26 import org.tianocore.FvImagesDocument;
27 import org.tianocore.PlatformSurfaceAreaDocument;
28 import org.tianocore.frameworkwizard.common.ui.IInternalFrame;
29 import org.tianocore.frameworkwizard.common.ui.StarLabel;
30
31
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ComponentAdapter;
35 import java.awt.event.ComponentEvent;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.io.File;
39 import java.util.ArrayList;
40 import java.util.Iterator;
41 import java.util.LinkedHashMap;
42 import java.util.Map;
43 import java.util.Set;
44
45 import javax.swing.JCheckBox;
46 import javax.swing.JTextField;
47 import java.awt.GridLayout;
48 import javax.swing.JLabel;
49 import javax.swing.JScrollPane;
50 import javax.swing.JTable;
51 import javax.swing.event.InternalFrameAdapter;
52 import javax.swing.event.InternalFrameEvent;
53 import javax.swing.event.ListSelectionEvent;
54 import javax.swing.event.ListSelectionListener;
55 import javax.swing.event.TableModelEvent;
56 import javax.swing.event.TableModelListener;
57 import javax.swing.table.DefaultTableModel;
58 import javax.swing.table.TableColumn;
59 import javax.swing.table.TableModel;
60 import javax.swing.JComboBox;
61 import java.awt.Dimension;
62
63 public class FpdFlash extends IInternalFrame {
64
65 /**
66 *
67 */
68 private static final long serialVersionUID = 1L;
69 static JFrame frame;
70 private JPanel jContentPane = null;
71 private JPanel jPanel = null;
72 private JPanel jPanel1 = null;
73 private JPanel jPanel2 = null;
74 private JPanel jPanel3 = null;
75 private JTabbedPane jTabbedPane = null;
76 private JPanel jPanelFvImages = null;
77 private JButton jButtonOk = null;
78 private JButton jButtonCancel = null;
79 private JPanel jPanelFvImageN = null;
80 private JPanel jPanelFvImageS = null;
81 private JCheckBox jCheckBox1 = null;
82 private JLabel jLabel = null;
83 private JTextField jTextField = null;
84 private JLabel jLabel1 = null;
85 private JTextField jTextField1 = null;
86 private JButton jButton = null;
87 private JScrollPane jScrollPane1 = null;
88 private JTable jTable = null;
89 private JPanel jPanel4 = null;
90 private JButton jButton1 = null;
91 private DefaultTableModel fvPropertyTableModel = null;
92 private DefaultTableModel fvImageNameTableModel = null;
93 private ImageParaTableModel fvImageParaTableModel = null;
94 private DefaultTableModel fvOptionTableModel = null;
95 private JPanel jPanelFvImageC = null;
96 private JCheckBox jCheckBox2 = null;
97 private JLabel jLabel2 = null;
98 private JComboBox jComboBox = null;
99 private JLabel jLabel3 = null;
100 private JLabel jLabel4 = null;
101 private JTextField jTextField2 = null;
102 private JButton jButton2 = null;
103 private JScrollPane jScrollPane2 = null;
104 private JTable jTable1 = null;
105 private JButton jButton3 = null;
106 private JPanel jPanel5 = null;
107 private JButton jButton4 = null;
108 private JScrollPane jScrollPane3 = null;
109 private JTable jTable2 = null;
110 private JButton jButton6 = null;
111 private JCheckBox jCheckBox3 = null;
112 private JPanel jPanel6 = null;
113
114 private FpdFileContents ffc = null;
115 private JPanel jPanel7 = null;
116 private JCheckBox jCheckBox = null;
117 private JTextField jTextField3 = null;
118 private JButton jButton5 = null;
119 private JLabel jLabel5 = null;
120 private JTextField jTextField4 = null;
121 private JLabel jLabel6 = null;
122 private JTextField jTextField5 = null;
123 private JPanel jPanel8 = null;
124 private JButton jButton7 = null;
125 private JButton jButton8 = null;
126 private JScrollPane jScrollPane = null;
127 private JTable jTable3 = null;
128 private JButton jButton9 = null;
129 public FpdFlash() {
130 super();
131 // TODO Auto-generated constructor stub
132
133 initialize();
134 this.setBounds(new java.awt.Rectangle(0, 0, 500, 370));
135 this.setVisible(true);
136 }
137
138 public FpdFlash(PlatformSurfaceAreaDocument.PlatformSurfaceArea fpd){
139 this();
140 ffc = new FpdFileContents(fpd);
141 init(ffc);
142 }
143
144 /**
145 * This method initializes jPanel
146 *
147 * @return javax.swing.JPanel
148 */
149 private JPanel getJPanel() {
150 if (jPanel == null) {
151 jPanel = new JPanel();
152 }
153 return jPanel;
154 }
155
156 /**
157 * This method initializes jPanel1
158 *
159 * @return javax.swing.JPanel
160 */
161 private JPanel getJPanel1() {
162 if (jPanel1 == null) {
163 FlowLayout flowLayout = new FlowLayout();
164 flowLayout.setAlignment(java.awt.FlowLayout.RIGHT);
165 flowLayout.setHgap(15);
166 jPanel1 = new JPanel();
167 jPanel1.setLayout(flowLayout);
168 jPanel1.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT);
169 jPanel1.add(getJButtonCancel(), null);
170 jPanel1.add(getJButtonOk(), null);
171 }
172 return jPanel1;
173 }
174
175 /**
176 * This method initializes jPanel2
177 *
178 * @return javax.swing.JPanel
179 */
180 private JPanel getJPanel2() {
181 if (jPanel2 == null) {
182 jPanel2 = new JPanel();
183 }
184 return jPanel2;
185 }
186
187 /**
188 * This method initializes jPanel3
189 *
190 * @return javax.swing.JPanel
191 */
192 private JPanel getJPanel3() {
193 if (jPanel3 == null) {
194 jPanel3 = new JPanel();
195 }
196 return jPanel3;
197 }
198
199 /**
200 * This method initializes jTabbedPane
201 *
202 * @return javax.swing.JTabbedPane
203 */
204 private JTabbedPane getJTabbedPane() {
205 if (jTabbedPane == null) {
206 jTabbedPane = new JTabbedPane();
207 jTabbedPane.addTab("FV Images", null, getJPanelFvImages(), null);
208 jTabbedPane.addTab("Flash Definition File", null, getJPanel7(), null);
209
210 }
211 return jTabbedPane;
212 }
213
214 /**
215 * This method initializes jPanelFvImages
216 *
217 * @return javax.swing.JPanel
218 */
219 private JPanel getJPanelFvImages() {
220 if (jPanelFvImages == null) {
221 jPanelFvImages = new JPanel();
222 jPanelFvImages.setLayout(new BorderLayout());
223 jPanelFvImages.add(getJPanelFvImageN(), java.awt.BorderLayout.NORTH);
224 // jPanelFvImages.add(getJPanelFvImageW(), java.awt.BorderLayout.WEST);
225 jPanelFvImages.add(getJPanelFvImageS(), java.awt.BorderLayout.SOUTH);
226 jPanelFvImages.add(getJPanelFvImageC(), java.awt.BorderLayout.CENTER);
227
228 }
229 return jPanelFvImages;
230 }
231
232 /**
233 * This method initializes jButtonOk
234 *
235 * @return javax.swing.JButton
236 */
237 private JButton getJButtonOk() {
238 if (jButtonOk == null) {
239 jButtonOk = new JButton();
240 jButtonOk.setPreferredSize(new java.awt.Dimension(80,20));
241 jButtonOk.setText("Cancel");
242 jButtonOk.setVisible(false);
243 }
244 return jButtonOk;
245 }
246
247 /**
248 * This method initializes jButtonCancel
249 *
250 * @return javax.swing.JButton
251 */
252 private JButton getJButtonCancel() {
253 if (jButtonCancel == null) {
254 jButtonCancel = new JButton();
255 jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));
256 jButtonCancel.setText("Ok");
257 jButtonCancel.setVisible(false);
258 }
259 return jButtonCancel;
260 }
261
262 /**
263 * This method initializes jPanelFvImageN
264 *
265 * @return javax.swing.JPanel
266 */
267 private JPanel getJPanelFvImageN() {
268 if (jPanelFvImageN == null) {
269 jLabel1 = new JLabel();
270 jLabel1.setText("Value");
271 jLabel1.setEnabled(false);
272 jLabel1.setPreferredSize(new java.awt.Dimension(38,20));
273 jLabel = new JLabel();
274 jLabel.setText("Name");
275 jLabel.setEnabled(false);
276 jLabel.setPreferredSize(new java.awt.Dimension(38,20));
277 FlowLayout flowLayout2 = new FlowLayout();
278 flowLayout2.setAlignment(java.awt.FlowLayout.CENTER);
279 flowLayout2.setHgap(15);
280 jPanelFvImageN = new JPanel();
281 jPanelFvImageN.setPreferredSize(new java.awt.Dimension(576,100));
282 jPanelFvImageN.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
283 jPanelFvImageN.setLayout(flowLayout2);
284 jPanelFvImageN.add(getJCheckBox1(), null);
285 jPanelFvImageN.add(jLabel, null);
286 jPanelFvImageN.add(getJTextField(), null);
287 jPanelFvImageN.add(jLabel1, null);
288 jPanelFvImageN.add(getJTextField1(), null);
289 jPanelFvImageN.add(getJScrollPane1(), null);
290 jPanelFvImageN.add(getJPanel4(), null);
291 }
292 return jPanelFvImageN;
293 }
294
295 /**
296 * This method initializes jPanelFvImageS
297 *
298 * @return javax.swing.JPanel
299 */
300 private JPanel getJPanelFvImageS() {
301 if (jPanelFvImageS == null) {
302 GridLayout gridLayout2 = new GridLayout();
303 gridLayout2.setRows(1);
304 jPanelFvImageS = new JPanel();
305 jPanelFvImageS.setPreferredSize(new java.awt.Dimension(480,190));
306 jPanelFvImageS.setLayout(gridLayout2);
307 jPanelFvImageS.add(getJScrollPane3(), null);
308 }
309 return jPanelFvImageS;
310 }
311
312
313 /**
314 * This method initializes jCheckBox1
315 *
316 * @return javax.swing.JCheckBox
317 */
318 private JCheckBox getJCheckBox1() {
319 if (jCheckBox1 == null) {
320 jCheckBox1 = new JCheckBox();
321 jCheckBox1.setText("FV Properties");
322 jCheckBox1.addItemListener(new ItemListener(){
323
324 public void itemStateChanged(ItemEvent arg0) {
325 // TODO Auto-generated method stub
326 boolean seleted = jCheckBox1.isSelected();
327
328 jLabel.setEnabled(seleted);
329 jTextField.setEnabled(seleted);
330 jLabel1.setEnabled(seleted);
331 jTextField1.setEnabled(seleted);
332 jTable.setEnabled(seleted);
333 jButton.setEnabled(seleted);
334 jButton1.setEnabled(seleted);
335
336
337 }
338
339 });
340 }
341 return jCheckBox1;
342 }
343
344
345 /**
346 * This method initializes jTextField
347 *
348 * @return javax.swing.JTextField
349 */
350 private JTextField getJTextField() {
351 if (jTextField == null) {
352 jTextField = new JTextField();
353 jTextField.setPreferredSize(new java.awt.Dimension(100,20));
354 jTextField.setEnabled(false);
355 }
356 return jTextField;
357 }
358
359
360 /**
361 * This method initializes jTextField1
362 *
363 * @return javax.swing.JTextField
364 */
365 private JTextField getJTextField1() {
366 if (jTextField1 == null) {
367 jTextField1 = new JTextField();
368 jTextField1.setPreferredSize(new java.awt.Dimension(100,20));
369 jTextField1.setEnabled(false);
370 }
371 return jTextField1;
372 }
373
374
375 /**
376 * This method initializes jButton
377 *
378 * @return javax.swing.JButton
379 */
380 private JButton getJButton() {
381 if (jButton == null) {
382 jButton = new JButton();
383 jButton.setPreferredSize(new java.awt.Dimension(80,20));
384 jButton.setEnabled(false);
385 jButton.setText("Add");
386 jButton.addActionListener(new AbstractAction() {
387 /**
388 *
389 */
390 private static final long serialVersionUID = 1L;
391
392 public void actionPerformed(ActionEvent e) {
393 if (jTextField.getText().length() > 0 && jTextField1.getText().length() > 0){
394 String[] row = {jTextField.getText(), jTextField1.getText()};
395 fvPropertyTableModel.addRow(row);
396 ffc.genFvImagesNameValue(row[0], row[1]);
397 }
398 }
399 });
400 }
401 return jButton;
402 }
403
404
405 /**
406 * This method initializes jScrollPane1
407 *
408 * @return javax.swing.JScrollPane
409 */
410 private JScrollPane getJScrollPane1() {
411 if (jScrollPane1 == null) {
412 jScrollPane1 = new JScrollPane();
413 jScrollPane1.setPreferredSize(new java.awt.Dimension(350,55));
414 jScrollPane1.setViewportView(getJTable());
415 }
416 return jScrollPane1;
417 }
418
419
420 /**
421 * This method initializes jTable
422 *
423 * @return javax.swing.JTable
424 */
425 private JTable getJTable() {
426 if (jTable == null) {
427 fvPropertyTableModel = new DefaultTableModel();
428 jTable = new JTable(fvPropertyTableModel);
429 fvPropertyTableModel.addColumn("Name");
430 fvPropertyTableModel.addColumn("Value");
431 jTable.setRowHeight(20);
432 jTable.setEnabled(false);
433
434 jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
435 jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
436 public void valueChanged(ListSelectionEvent e) {
437 if (e.getValueIsAdjusting()){
438 return;
439 }
440 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
441 if (lsm.isSelectionEmpty()) {
442 return;
443 }
444 else{
445 // selectedRow = lsm.getMinSelectionIndex();
446 }
447 }
448 });
449
450 jTable.getModel().addTableModelListener(new TableModelListener(){
451 public void tableChanged(TableModelEvent arg0) {
452 // TODO Auto-generated method stub
453 int row = arg0.getFirstRow();
454 TableModel m = (TableModel)arg0.getSource();
455 if (arg0.getType() == TableModelEvent.UPDATE){
456
457 String name = m.getValueAt(row, 0) + "";
458 String value = m.getValueAt(row, 1) + "";
459
460 ffc.updateFvImagesNameValue(row, name, value);
461 }
462 }
463 });
464 }
465 return jTable;
466 }
467
468
469 /**
470 * This method initializes jPanel4
471 *
472 * @return javax.swing.JPanel
473 */
474 private JPanel getJPanel4() {
475 if (jPanel4 == null) {
476 jPanel4 = new JPanel();
477 jPanel4.setPreferredSize(new java.awt.Dimension(80,55));
478
479 jPanel4.add(getJButton(), null);
480 jPanel4.add(getJButton1(), null);
481 }
482 return jPanel4;
483 }
484
485
486 /**
487 * This method initializes jButton1
488 *
489 * @return javax.swing.JButton
490 */
491 private JButton getJButton1() {
492 if (jButton1 == null) {
493 jButton1 = new JButton();
494 jButton1.setPreferredSize(new java.awt.Dimension(80,20));
495 jButton1.setEnabled(false);
496 jButton1.setText("Delete");
497 jButton1.addActionListener(new AbstractAction() {
498 /**
499 *
500 */
501 private static final long serialVersionUID = 1L;
502
503 public void actionPerformed(ActionEvent e) {
504 if (jTable.getSelectedRow() >= 0){
505 fvPropertyTableModel.removeRow(jTable.getSelectedRow());
506 ffc.removeFvImagesNameValue(jTable.getSelectedRow());
507 }
508 }
509 });
510 }
511 return jButton1;
512 }
513
514
515 /**
516 * This method initializes jPanelFvImageC
517 *
518 * @return javax.swing.JPanel
519 */
520 private JPanel getJPanelFvImageC() {
521 if (jPanelFvImageC == null) {
522 jLabel4 = new JLabel();
523 jLabel4.setPreferredSize(new Dimension(38, 20));
524 jLabel4.setEnabled(false);
525 jLabel4.setText("Name");
526 jLabel3 = new JLabel();
527 jLabel3.setText("FV Image Names");
528 jLabel3.setEnabled(false);
529 jLabel3.setPreferredSize(new java.awt.Dimension(150,20));
530 jLabel2 = new JLabel();
531 jLabel2.setText("Type");
532 jLabel2.setEnabled(false);
533 jLabel2.setPreferredSize(new java.awt.Dimension(70,20));
534 FlowLayout flowLayout3 = new FlowLayout();
535 flowLayout3.setAlignment(java.awt.FlowLayout.LEFT);
536 flowLayout3.setHgap(5);
537 jPanelFvImageC = new JPanel();
538 jPanelFvImageC.setLayout(flowLayout3);
539 jPanelFvImageC.add(getJPanel6(), null);
540
541 jPanelFvImageC.add(getJPanel5(), null);
542
543 }
544 return jPanelFvImageC;
545 }
546
547
548 /**
549 * This method initializes jCheckBox2
550 *
551 * @return javax.swing.JCheckBox
552 */
553 private JCheckBox getJCheckBox2() {
554 if (jCheckBox2 == null) {
555 jCheckBox2 = new JCheckBox();
556 jCheckBox2.setText("FV Image Parameters");
557 jCheckBox2.setPreferredSize(new java.awt.Dimension(200,20));
558 jCheckBox2.addItemListener(new ItemListener(){
559
560 public void itemStateChanged(ItemEvent arg0) {
561 // TODO Auto-generated method stub
562 boolean seleted = jCheckBox2.isSelected();
563
564 jLabel2.setEnabled(seleted);
565 jLabel3.setEnabled(seleted);
566 jLabel4.setEnabled(seleted);
567 jComboBox.setEnabled(seleted);
568 jTextField2.setEnabled(seleted);
569
570 jTable1.setEnabled(seleted);
571 jButton2.setEnabled(seleted);
572 jButton3.setEnabled(seleted);
573
574
575 }
576
577 });
578 }
579 return jCheckBox2;
580 }
581
582
583 /**
584 * This method initializes jComboBox
585 *
586 * @return javax.swing.JComboBox
587 */
588 private JComboBox getJComboBox() {
589 if (jComboBox == null) {
590 jComboBox = new JComboBox();
591 jComboBox.addItem("ImageName");
592 jComboBox.addItem("Attributes");
593 jComboBox.addItem("Options");
594 jComboBox.addItem("Components");
595 jComboBox.setPreferredSize(new java.awt.Dimension(180,20));
596 jComboBox.setEnabled(false);
597 jComboBox.addItemListener(new ItemListener() {
598
599 public void itemStateChanged(ItemEvent arg0) {
600 // TODO disable attribute settings when ValidImageNames selected.
601
602 }
603
604 });
605 }
606 return jComboBox;
607 }
608
609
610 /**
611 * This method initializes jTextField2
612 *
613 * @return javax.swing.JTextField
614 */
615 private JTextField getJTextField2() {
616 if (jTextField2 == null) {
617 jTextField2 = new JTextField();
618 jTextField2.setPreferredSize(new java.awt.Dimension(140,20));
619 jTextField2.setEnabled(false);
620 }
621 return jTextField2;
622 }
623
624
625 /**
626 * This method initializes jButton2
627 *
628 * @return javax.swing.JButton
629 */
630 private JButton getJButton2() {
631 if (jButton2 == null) {
632 jButton2 = new JButton();
633 jButton2.setPreferredSize(new Dimension(80, 20));
634 jButton2.setEnabled(false);
635 jButton2.setText("Add");
636 jButton2.addActionListener(new AbstractAction() {
637 /**
638 *
639 */
640 private static final long serialVersionUID = 1L;
641
642 public void actionPerformed(java.awt.event.ActionEvent e) {
643 if (jTextField2.getText().length() > 0){
644 String[] row = {jTextField2.getText()};
645 fvImageNameTableModel.addRow(row);
646 }
647 }
648 });
649 }
650 return jButton2;
651 }
652
653
654 /**
655 * This method initializes jScrollPane2
656 *
657 * @return javax.swing.JScrollPane
658 */
659 private JScrollPane getJScrollPane2() {
660 if (jScrollPane2 == null) {
661 jScrollPane2 = new JScrollPane();
662 jScrollPane2.setPreferredSize(new java.awt.Dimension(350,50));
663 jScrollPane2.setViewportView(getJTable1());
664 }
665 return jScrollPane2;
666 }
667
668
669 /**
670 * This method initializes jTable1
671 *
672 * @return javax.swing.JTable
673 */
674 private JTable getJTable1() {
675 if (jTable1 == null) {
676 fvImageNameTableModel = new DefaultTableModel();
677 jTable1 = new JTable(fvImageNameTableModel);
678 jTable1.setEnabled(false);
679 fvImageNameTableModel.addColumn("FV Image Name");
680 }
681 return jTable1;
682 }
683
684
685 /**
686 * This method initializes jButton3
687 *
688 * @return javax.swing.JButton
689 */
690 private JButton getJButton3() {
691 if (jButton3 == null) {
692 jButton3 = new JButton();
693 jButton3.setPreferredSize(new Dimension(80, 20));
694 jButton3.setEnabled(false);
695 jButton3.setText("Delete");
696 jButton3.addActionListener(new AbstractAction() {
697 /**
698 *
699 */
700 private static final long serialVersionUID = 1L;
701
702 public void actionPerformed(java.awt.event.ActionEvent e) {
703 if (jTable1.getSelectedRow() >= 0){
704
705 fvImageNameTableModel.removeRow(jTable1.getSelectedRow());
706 }
707 }
708 });
709 }
710 return jButton3;
711 }
712
713
714
715
716 private JPanel getJPanel5() {
717
718
719 if (jPanel5 == null) {
720 //ToDo add ButtonGroup for RadioButtons
721 jLabel6 = new JLabel();
722 jLabel6.setEnabled(false);
723 jLabel6.setText("Value");
724 jLabel6.setPreferredSize(new Dimension(38, 20));
725 jLabel5 = new JLabel();
726 jLabel5.setEnabled(false);
727 jLabel5.setText("Name");
728 jLabel5.setPreferredSize(new Dimension(38, 20));
729 jPanel5 = new JPanel();
730 jPanel5.setPreferredSize(new java.awt.Dimension(480,150));
731
732 jPanel5.setLayout(new FlowLayout());
733
734 jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
735 jPanel5.add(getJCheckBox3(), null);
736 jPanel5.add(jLabel5, null);
737 jPanel5.add(getJTextField4(), null);
738 jPanel5.add(jLabel6, null);
739 jPanel5.add(getJTextField5(), null);
740 jPanel5.add(getJScrollPane(), null);
741 jPanel5.add(getJPanel8(), null);
742 jPanel5.add(getJButton4(), null);
743 jPanel5.add(getJButton6(), null);
744 jPanel5.add(getJButton9(), null);
745
746
747
748
749
750 }
751 return jPanel5;
752 }
753
754
755 /**
756 * This method initializes jButton4
757 *
758 * @return javax.swing.JButton
759 */
760 private JButton getJButton4() {
761 if (jButton4 == null) {
762 jButton4 = new JButton();
763 jButton4.setPreferredSize(new java.awt.Dimension(120,20));
764 // jButton4.setEnabled(false);
765 jButton4.setText("Add FV Image");
766 jButton4.addActionListener(new AbstractAction() {
767 /**
768 *
769 */
770 private static final long serialVersionUID = 1L;
771
772 public void actionPerformed(java.awt.event.ActionEvent e) {
773 if (jTable2.isEditing()) {
774 jTable2.getCellEditor().stopCellEditing();
775 }
776 if (jTable3.isEditing()) {
777 jTable3.getCellEditor().stopCellEditing();
778 }
779 if (jTable1.getRowCount()== 0){
780 return;
781 }
782 String imageName = " ";
783 for (int i = 0; i < jTable1.getRowCount(); ++i){
784 imageName += (String)jTable1.getValueAt(i, 0);
785 imageName += " ";
786 }
787 imageName = imageName.trim();
788
789 if (!jCheckBox3.isSelected() && jComboBox.getSelectedIndex() != 0){
790 return;
791
792 }
793
794 LinkedHashMap<String, String> m = null;
795 if (jCheckBox3.isSelected()) {
796 m = new LinkedHashMap<String, String>();
797 getOptionNameValue(m);
798 }
799 ffc.genFvImagesFvImage(imageName.split(" "), jComboBox.getSelectedItem()+"", m);
800
801 Object[] row = {imageName, jComboBox.getSelectedItem()};
802 fvImageParaTableModel.addRow(row);
803 }
804 });
805 }
806 return jButton4;
807 }
808
809
810 /**
811 * This method initializes jScrollPane3
812 *
813 * @return javax.swing.JScrollPane
814 */
815 private JScrollPane getJScrollPane3() {
816 if (jScrollPane3 == null) {
817 jScrollPane3 = new JScrollPane();
818 jScrollPane3.setPreferredSize(new java.awt.Dimension(480,150));
819 jScrollPane3.setViewportView(getJTable2());
820 }
821 return jScrollPane3;
822 }
823
824
825 /**
826 * This method initializes jTable2
827 *
828 * @return javax.swing.JTable
829 */
830 private JTable getJTable2() {
831 if (jTable2 == null) {
832 fvImageParaTableModel = new ImageParaTableModel();
833 jTable2 = new JTable(fvImageParaTableModel);
834 fvImageParaTableModel.addColumn("FvImageNames");
835 fvImageParaTableModel.addColumn("Type");
836
837
838 TableColumn typeCol = jTable2.getColumnModel().getColumn(1);
839 JComboBox cb = new JComboBox();
840 cb.addItem("ValidImageNames");
841 cb.addItem("Attributes");
842 cb.addItem("Options");
843 cb.addItem("Components");
844 typeCol.setCellEditor(new DefaultCellEditor(cb));
845
846 jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
847 jTable2.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
848 public void valueChanged(ListSelectionEvent e) {
849 if (e.getValueIsAdjusting()){
850 return;
851 }
852 ListSelectionModel lsm = (ListSelectionModel)e.getSource();
853 if (lsm.isSelectionEmpty()) {
854 return;
855 }
856 else{
857 int selectedRow = lsm.getMinSelectionIndex();
858 LinkedHashMap<String, String> optionMap = new LinkedHashMap<String, String>();
859 ffc.getFvImagesFvImageOptions(selectedRow, optionMap);
860 if (optionMap.size() > 0){
861 fvOptionTableModel.setRowCount(0);
862 Set<String> key = optionMap.keySet();
863 Iterator<String> i = key.iterator();
864 while (i.hasNext()) {
865
866 String k = (String)i.next();
867 String[] row = {k, optionMap.get(k)};
868
869 fvOptionTableModel.addRow(row);
870 }
871 }
872
873 }
874 }
875 });
876
877
878 }
879 return jTable2;
880 }
881
882
883 /**
884 * This method initializes jButton6
885 *
886 * @return javax.swing.JButton
887 */
888 private JButton getJButton6() {
889 if (jButton6 == null) {
890 jButton6 = new JButton();
891 jButton6.setPreferredSize(new java.awt.Dimension(120,20));
892 // jButton6.setEnabled(false);
893 jButton6.setText("Delete Row");
894 jButton6.addActionListener(new AbstractAction() {
895 /**
896 *
897 */
898 private static final long serialVersionUID = 1L;
899
900 public void actionPerformed(ActionEvent arg0) {
901 // TODO Auto-generated method stub
902 if (jTable2.getSelectedRow() >= 0 ) {
903 fvImageParaTableModel.removeRow(jTable2.getSelectedRow());
904 ffc.removeFvImagesFvImage(jTable2.getSelectedRow());
905 }
906 }
907
908 });
909 }
910 return jButton6;
911 }
912
913
914 /**
915 * This method initializes jCheckBox3
916 *
917 * @return javax.swing.JCheckBox
918 */
919 private JCheckBox getJCheckBox3() {
920 if (jCheckBox3 == null) {
921 jCheckBox3 = new JCheckBox();
922 jCheckBox3.setText("FV Image Options");
923 jCheckBox3.addItemListener(new ItemListener(){
924
925 public void itemStateChanged(ItemEvent arg0) {
926 // TODO Auto-generated method stub
927 boolean selected = jCheckBox3.isSelected();
928
929 if (!jCheckBox2.isSelected() || jComboBox.getSelectedIndex() == 0) {
930 return;
931 }
932
933 // jLabel5.setEnabled(selected);
934 // jTextField4.setEnabled(selected);
935 // jLabel6.setEnabled(selected);
936 // jTextField5.setEnabled(selected);
937 // jButton7.setEnabled(selected);
938 // jButton8.setEnabled(selected);
939
940 }
941
942 });
943 }
944 return jCheckBox3;
945 }
946
947
948 /**
949 * This method initializes jPanel6
950 *
951 * @return javax.swing.JPanel
952 */
953 private JPanel getJPanel6() {
954 if (jPanel6 == null) {
955 StarLabel starLabel = new StarLabel();
956 starLabel.setVisible(false);
957 jPanel6 = new JPanel();
958 jPanel6.setPreferredSize(new java.awt.Dimension(480,120));
959 jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
960 jPanel6.add(getJCheckBox2(), null);
961 jPanel6.add(jLabel2, null);
962 jPanel6.add(getJComboBox(), null);
963 jPanel6.add(new StarLabel(), null);
964 jPanel6.add(jLabel3, null);
965 jPanel6.add(jLabel4, null);
966 jPanel6.add(getJTextField2(), null);
967 jPanel6.add(getJButton2(), null);
968 jPanel6.add(getJScrollPane2(), null);
969 jPanel6.add(getJButton3(), null);
970 }
971 return jPanel6;
972 }
973
974 /**
975 * This method initializes jPanel7
976 *
977 * @return javax.swing.JPanel
978 */
979 private JPanel getJPanel7() {
980 if (jPanel7 == null) {
981 FlowLayout flowLayout1 = new FlowLayout();
982 flowLayout1.setAlignment(FlowLayout.LEFT);
983 jPanel7 = new JPanel();
984 jPanel7.setLayout(flowLayout1);
985 jPanel7.add(getJCheckBox(), null);
986 jPanel7.add(getJTextField3(), null);
987 jPanel7.add(getJButton5(), null);
988 jPanel7.addComponentListener(new ComponentAdapter(){
989 public void componentShown(ComponentEvent e) {
990 if (ffc.getFlashDefinitionFile() != null) {
991 jTextField3.setText(ffc.getFlashDefinitionFile());
992 }
993 }
994 public void componentHidden(ComponentEvent e) {
995 if (jCheckBox.isSelected()) {
996 ffc.genFlashDefinitionFile(jTextField3.getText());
997 }
998 }
999 });
1000 }
1001 return jPanel7;
1002 }
1003
1004 /**
1005 * This method initializes jCheckBox
1006 *
1007 * @return javax.swing.JCheckBox
1008 */
1009 private JCheckBox getJCheckBox() {
1010 if (jCheckBox == null) {
1011 jCheckBox = new JCheckBox();
1012 jCheckBox.setText("Flash Definition File");
1013 jCheckBox.addItemListener(new ItemListener() {
1014
1015 public void itemStateChanged(ItemEvent arg0) {
1016 // TODO Auto-generated method stub
1017 if (jCheckBox.isSelected()){
1018 jTextField3.setEnabled(true);
1019 jButton5.setEnabled(true);
1020 }
1021 else {
1022
1023 jTextField3.setEnabled(false);
1024 jButton5.setEnabled(false);
1025 }
1026 }
1027 });
1028 }
1029 return jCheckBox;
1030 }
1031
1032 /**
1033 * This method initializes jTextField3
1034 *
1035 * @return javax.swing.JTextField
1036 */
1037 private JTextField getJTextField3() {
1038 if (jTextField3 == null) {
1039 jTextField3 = new JTextField();
1040 jTextField3.setEnabled(false);
1041 jTextField3.setPreferredSize(new Dimension(300, 20));
1042 }
1043 return jTextField3;
1044 }
1045
1046 /**
1047 * This method initializes jButton5
1048 *
1049 * @return javax.swing.JButton
1050 */
1051 private JButton getJButton5() {
1052 if (jButton5 == null) {
1053 jButton5 = new JButton();
1054 jButton5.setEnabled(false);
1055 jButton5.setText("Browse");
1056 jButton5.setPreferredSize(new Dimension(78, 20));
1057 jButton5.addActionListener(new AbstractAction(){
1058 /**
1059 *
1060 */
1061 private static final long serialVersionUID = 1L;
1062
1063 public void actionPerformed(ActionEvent e) {
1064 // TODO Auto-generated method stub
1065 JFileChooser chooser = new JFileChooser();
1066 chooser.setMultiSelectionEnabled(false);
1067 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
1068 int retval = chooser.showOpenDialog(frame);
1069 if (retval == JFileChooser.APPROVE_OPTION) {
1070
1071 File theFile = chooser.getSelectedFile();
1072 jTextField3.setText(theFile.getPath());
1073 }
1074 }
1075
1076 });
1077 }
1078 return jButton5;
1079 }
1080
1081 /**
1082 * This method initializes jTextField4
1083 *
1084 * @return javax.swing.JTextField
1085 */
1086 private JTextField getJTextField4() {
1087 if (jTextField4 == null) {
1088 jTextField4 = new JTextField();
1089 jTextField4.setEnabled(false);
1090 jTextField4.setPreferredSize(new Dimension(100, 20));
1091 }
1092 return jTextField4;
1093 }
1094
1095 /**
1096 * This method initializes jTextField5
1097 *
1098 * @return javax.swing.JTextField
1099 */
1100 private JTextField getJTextField5() {
1101 if (jTextField5 == null) {
1102 jTextField5 = new JTextField();
1103 jTextField5.setEnabled(false);
1104 jTextField5.setPreferredSize(new Dimension(100, 20));
1105 }
1106 return jTextField5;
1107 }
1108
1109 /**
1110 * This method initializes jPanel8
1111 *
1112 * @return javax.swing.JPanel
1113 */
1114 private JPanel getJPanel8() {
1115 if (jPanel8 == null) {
1116 jPanel8 = new JPanel();
1117 jPanel8.setPreferredSize(new Dimension(80, 55));
1118 jPanel8.add(getJButton7(), null);
1119 jPanel8.add(getJButton8(), null);
1120 }
1121 return jPanel8;
1122 }
1123
1124 /**
1125 * This method initializes jButton7
1126 *
1127 * @return javax.swing.JButton
1128 */
1129 private JButton getJButton7() {
1130 if (jButton7 == null) {
1131 jButton7 = new JButton();
1132 jButton7.setEnabled(true);
1133 jButton7.setText("Add");
1134 jButton7.setPreferredSize(new Dimension(80, 20));
1135 jButton7.addActionListener(new AbstractAction() {
1136 /**
1137 *
1138 */
1139 private static final long serialVersionUID = 1L;
1140
1141 public void actionPerformed(ActionEvent e) {
1142 if (jTextField4.getText().length() > 0 && jTextField5.getText().length() > 0){
1143 String[] row = {jTextField4.getText(), jTextField5.getText()};
1144 fvOptionTableModel.addRow(row);
1145 }
1146 }
1147 });
1148 }
1149 return jButton7;
1150 }
1151
1152 /**
1153 * This method initializes jButton8
1154 *
1155 * @return javax.swing.JButton
1156 */
1157 private JButton getJButton8() {
1158 if (jButton8 == null) {
1159 jButton8 = new JButton();
1160 jButton8.setEnabled(true);
1161 jButton8.setText("Delete");
1162 jButton8.setPreferredSize(new Dimension(80, 20));
1163 jButton8.addActionListener(new AbstractAction() {
1164 /**
1165 *
1166 */
1167 private static final long serialVersionUID = 1L;
1168
1169 public void actionPerformed(ActionEvent e) {
1170 if (jTable3.getSelectedRow() >= 0){
1171 fvOptionTableModel.removeRow(jTable.getSelectedRow());
1172 }
1173 }
1174 });
1175 }
1176 return jButton8;
1177 }
1178
1179 /**
1180 * This method initializes jScrollPane
1181 *
1182 * @return javax.swing.JScrollPane
1183 */
1184 private JScrollPane getJScrollPane() {
1185 if (jScrollPane == null) {
1186 jScrollPane = new JScrollPane();
1187 jScrollPane.setPreferredSize(new java.awt.Dimension(350,80));
1188 jScrollPane.setViewportView(getJTable3());
1189 }
1190 return jScrollPane;
1191 }
1192
1193 /**
1194 * This method initializes jTable3
1195 *
1196 * @return javax.swing.JTable
1197 */
1198 private JTable getJTable3() {
1199 if (jTable3 == null) {
1200 fvOptionTableModel = new DefaultTableModel();
1201 fvOptionTableModel.addColumn("Name");
1202 fvOptionTableModel.addColumn("Value");
1203 jTable3 = new JTable(fvOptionTableModel);
1204
1205 jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1206 jTable3.setRowHeight(20);
1207
1208 }
1209 return jTable3;
1210 }
1211
1212 /**
1213 * This method initializes jButton9
1214 *
1215 * @return javax.swing.JButton
1216 */
1217 private JButton getJButton9() {
1218 if (jButton9 == null) {
1219 jButton9 = new JButton();
1220 jButton9.setPreferredSize(new Dimension(120, 20));
1221 jButton9.setActionCommand("Update");
1222 jButton9.setText("Update FV");
1223 jButton9.addActionListener(new java.awt.event.ActionListener() {
1224 public void actionPerformed(java.awt.event.ActionEvent e) {
1225 int row = jTable2.getSelectedRow();
1226 if (jTable2.isEditing()) {
1227 jTable2.getCellEditor().stopCellEditing();
1228 }
1229 if (jTable3.isEditing()) {
1230 jTable3.getCellEditor().stopCellEditing();
1231 }
1232
1233 //ToDo Check data validity before update
1234 String name = fvImageParaTableModel.getValueAt(row, 0) + "";
1235 String type = fvImageParaTableModel.getValueAt(row, 1) + "";
1236
1237 LinkedHashMap<String, String> lhm = new LinkedHashMap<String, String>();
1238 getOptionNameValue(lhm);
1239
1240
1241 ffc.updateFvImagesFvImage(row, name.split(" "), type, lhm);
1242
1243 }
1244 });
1245 }
1246 return jButton9;
1247 }
1248
1249 /**
1250 * @param args
1251 */
1252 public static void main(String[] args) {
1253 // TODO Auto-generated method stub
1254 new FpdFlash().setVisible(true);
1255 }
1256
1257 /**
1258 * This method initializes this
1259 *
1260 * @return void
1261 */
1262 private void initialize() {
1263 this.setSize(518, 650);
1264 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
1265 this.setContentPane(getJContentPane());
1266 this.setTitle("FPD Flash Definitions");
1267 this.addInternalFrameListener(new InternalFrameAdapter(){
1268 public void internalFrameDeactivated(InternalFrameEvent e){
1269 if (jTable.isEditing()) {
1270 jTable.getCellEditor().stopCellEditing();
1271 }
1272 if (jTable1.isEditing()) {
1273 jTable1.getCellEditor().stopCellEditing();
1274 }
1275 if (jTable2.isEditing()) {
1276 jTable2.getCellEditor().stopCellEditing();
1277 }
1278 }
1279 });
1280 }
1281
1282 private void init(FpdFileContents ffc) {
1283 if (ffc.getFvImagesFvImageCount() == 0) {
1284 return;
1285 }
1286 String[][] saa = new String[ffc.getFvImagesFvImageCount()][2];
1287 // ArrayList<LinkedHashMap<String, String>> options = new ArrayList<LinkedHashMap<String, String>>(ffc.getFvImagesFvImageCount());
1288 //
1289 // for (int j = 0; j < ffc.getFvImagesFvImageCount(); ++j){
1290 // options.add(new LinkedHashMap<String, String>());
1291 // }
1292 ffc.getFvImagesFvImages(saa);
1293
1294
1295 int i = 0;
1296 while (i < saa.length) {
1297
1298 fvImageParaTableModel.addRow(saa[i]);
1299 ++i;
1300 }
1301 }
1302
1303 private void getOptionNameValue(Map<String, String> m){
1304 for (int i = 0; i < jTable3.getRowCount(); ++i) {
1305 m.put(fvOptionTableModel.getValueAt(i, 0)+"", fvOptionTableModel.getValueAt(i, 1)+"");
1306 }
1307 }
1308 /**
1309 * This method initializes jContentPane
1310 *
1311 * @return javax.swing.JPanel
1312 */
1313 private JPanel getJContentPane() {
1314 if (jContentPane == null) {
1315 jContentPane = new JPanel();
1316 jContentPane.setLayout(new BorderLayout());
1317 jContentPane.add(getJPanel(), java.awt.BorderLayout.EAST);
1318 jContentPane.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
1319 jContentPane.add(getJPanel2(), java.awt.BorderLayout.WEST);
1320 jContentPane.add(getJPanel3(), java.awt.BorderLayout.NORTH);
1321 jContentPane.add(getJTabbedPane(), java.awt.BorderLayout.CENTER);
1322 }
1323 return jContentPane;
1324 }
1325
1326 } // @jve:decl-index=0:visual-constraint="10,10"
1327
1328 class ImageParaTableModel extends DefaultTableModel {
1329
1330 private static final long serialVersionUID = 1L;
1331
1332 public boolean isCellEditable(int row, int col) {
1333 if (getValueAt(row, 1).equals("ImageName") && col >=1) {
1334 return false;
1335 }
1336 return true;
1337 }
1338 }
1339