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