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