3 The file is used to create, update Module Definitions of MSA file
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.frameworkwizard
.module
.ui
;
17 import java
.awt
.event
.ComponentEvent
;
18 import java
.awt
.event
.FocusEvent
;
20 import javax
.swing
.JPanel
;
21 import javax
.swing
.JScrollPane
;
22 import javax
.swing
.JLabel
;
23 import javax
.swing
.JTextField
;
24 import javax
.swing
.JComboBox
;
26 import org
.tianocore
.ModuleDefinitionsDocument
;
27 import org
.tianocore
.ModuleSurfaceAreaDocument
;
28 import org
.tianocore
.ModuleDefinitionsDocument
.ModuleDefinitions
.ClonedFrom
;
29 import org
.tianocore
.frameworkwizard
.common
.DataValidation
;
30 import org
.tianocore
.frameworkwizard
.common
.EnumerationData
;
31 import org
.tianocore
.frameworkwizard
.common
.Log
;
32 import org
.tianocore
.frameworkwizard
.common
.OpeningModuleType
;
33 import org
.tianocore
.frameworkwizard
.common
.Tools
;
34 import org
.tianocore
.frameworkwizard
.common
.ui
.IInternalFrame
;
35 import org
.tianocore
.frameworkwizard
.common
.ui
.StarLabel
;
36 import org
.tianocore
.frameworkwizard
.common
.ui
.iCheckBoxList
.ICheckBoxList
;
38 public class ModuleDefinitions
extends IInternalFrame
{
41 /// Define class Serial Version UID
43 private static final long serialVersionUID
= 5860378543553036323L;
45 private JScrollPane jScrollPane
= null;
47 private JPanel jContentPane
= null;
49 private JLabel jLabelArch
= null;
51 private ICheckBoxList iCheckBoxListArch
= null;
53 private JLabel jLabelBinaryModule
= null;
55 private JComboBox jComboBoxBinaryModule
= null;
57 private JLabel jLabelOutputFileBasename
= null;
59 private JTextField jTextFieldOutputFileBasename
= null;
61 private JScrollPane jScrollPaneArch
= null;
63 private StarLabel jStarLabel1
= null;
65 private StarLabel jStarLabel2
= null;
67 private StarLabel jStarLabel3
= null;
69 private OpeningModuleType omt
= null;
71 private ClonedFrom cf
= null;
73 private ModuleSurfaceAreaDocument
.ModuleSurfaceArea msa
= null;
75 private ModuleDefinitionsDocument
.ModuleDefinitions md
= null;
78 * This method initializes jScrollPane
80 * @return javax.swing.JScrollPane
82 private JScrollPane
getJScrollPane() {
83 if (jScrollPane
== null) {
84 jScrollPane
= new JScrollPane();
85 jScrollPane
.setViewportView(getJContentPane());
91 * This method initializes jPanel
93 * @return javax.swing.JPanel
95 private JPanel
getJContentPane() {
96 if (jContentPane
== null) {
97 jLabelOutputFileBasename
= new JLabel();
98 jLabelOutputFileBasename
.setBounds(new java
.awt
.Rectangle(15, 10, 140, 20));
99 jLabelOutputFileBasename
.setText("Output File Basename");
100 jLabelBinaryModule
= new JLabel();
101 jLabelBinaryModule
.setBounds(new java
.awt
.Rectangle(15, 35, 140, 20));
102 jLabelBinaryModule
.setText("Binary Module");
103 jLabelArch
= new JLabel();
104 jLabelArch
.setBounds(new java
.awt
.Rectangle(15, 60, 140, 20));
105 jLabelArch
.setText("Supported Architectures");
106 jStarLabel1
= new StarLabel();
107 jStarLabel1
.setLocation(new java
.awt
.Point(0, 10));
108 jStarLabel2
= new StarLabel();
109 jStarLabel2
.setLocation(new java
.awt
.Point(0, 35));
110 jStarLabel3
= new StarLabel();
111 jStarLabel3
.setLocation(new java
.awt
.Point(0, 60));
113 jContentPane
= new JPanel();
114 jContentPane
.setLayout(null);
115 jContentPane
.setPreferredSize(new java
.awt
.Dimension(490, 150));
117 jContentPane
.add(jLabelArch
, null);
118 jContentPane
.add(getJScrollPaneArch(), null);
119 jContentPane
.add(jLabelBinaryModule
, null);
120 jContentPane
.add(getJComboBoxBinaryModule(), null);
121 jContentPane
.add(jLabelOutputFileBasename
, null);
122 jContentPane
.add(getJTextFieldOutputFileBasename(), null);
123 jContentPane
.add(jStarLabel1
, null);
124 jContentPane
.add(jStarLabel2
, null);
125 jContentPane
.add(jStarLabel3
, null);
131 This method initializes iCheckBoxListArch
133 @return ICheckBoxList
135 private ICheckBoxList
getICheckBoxListSupportedArchitectures() {
136 if (iCheckBoxListArch
== null) {
137 iCheckBoxListArch
= new ICheckBoxList();
138 iCheckBoxListArch
.addFocusListener(this);
140 return iCheckBoxListArch
;
144 * This method initializes jComboBoxBinaryModule
146 * @return javax.swing.JComboBox
148 private JComboBox
getJComboBoxBinaryModule() {
149 if (jComboBoxBinaryModule
== null) {
150 jComboBoxBinaryModule
= new JComboBox();
151 jComboBoxBinaryModule
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
152 jComboBoxBinaryModule
.setPreferredSize(new java
.awt
.Dimension(320, 20));
153 jComboBoxBinaryModule
.addFocusListener(this);
154 jComboBoxBinaryModule
.setToolTipText("Modules are either source modules which can be compiled or binary modules which are linked. A module cannot contain both. The GUID numbers should be identical for a binary and source MSA, but the BINARY MSA should have a higher version number.");
156 return jComboBoxBinaryModule
;
160 * This method initializes jTextFieldOutputFileBasename
162 * @return javax.swing.JTextField
164 private JTextField
getJTextFieldOutputFileBasename() {
165 if (jTextFieldOutputFileBasename
== null) {
166 jTextFieldOutputFileBasename
= new JTextField();
167 jTextFieldOutputFileBasename
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
168 jTextFieldOutputFileBasename
.setPreferredSize(new java
.awt
.Dimension(320, 20));
169 jTextFieldOutputFileBasename
.addFocusListener(this);
170 jTextFieldOutputFileBasename
.setToolTipText("Enter a single word for generated output file names");
172 return jTextFieldOutputFileBasename
;
176 This method initializes jScrollPaneArch
178 @return javax.swing.JScrollPane
181 private JScrollPane
getJScrollPaneArch() {
182 if (jScrollPaneArch
== null) {
183 jScrollPaneArch
= new JScrollPane();
184 jScrollPaneArch
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 80));
185 jScrollPaneArch
.setPreferredSize(new java
.awt
.Dimension(320, 60));
186 jScrollPaneArch
.setViewportView(getICheckBoxListSupportedArchitectures());
188 return jScrollPaneArch
;
196 public static void main(String
[] args
) {
197 // TODO Auto-generated method stub
202 * This is the default constructor
204 public ModuleDefinitions() {
207 this.setVisible(true);
211 This is the override edit constructor
216 public ModuleDefinitions(OpeningModuleType inOmt
) {
219 this.msa
= omt
.getXmlMsa();
220 if (msa
.getModuleDefinitions() != null) {
221 this.cf
= msa
.getModuleDefinitions().getClonedFrom();
223 init(msa
.getModuleDefinitions());
224 this.setVisible(true);
228 * This method initializes this
232 private void init() {
233 this.setContentPane(getJScrollPane());
234 this.setTitle("Module Definitions");
236 this.setPreferredSize(new java
.awt
.Dimension(490, 520));
240 This method initializes this
241 Fill values to all fields if these values are not empty
243 @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader
246 private void init(ModuleDefinitionsDocument
.ModuleDefinitions inMd
) {
250 if (md
.getSupportedArchitectures() != null) {
251 this.iCheckBoxListArch
.initCheckedItem(true, Tools
.convertListToVector(md
.getSupportedArchitectures()));
253 if (md
.getBinaryModule()) {
254 this.jComboBoxBinaryModule
.setSelectedIndex(1);
256 this.jComboBoxBinaryModule
.setSelectedIndex(0);
258 if (md
.getOutputFileBasename() != null) {
259 this.jTextFieldOutputFileBasename
.setText(md
.getOutputFileBasename());
265 This method initializes Module type and Compontent type
268 private void initFrame() {
269 EnumerationData ed
= new EnumerationData();
270 this.iCheckBoxListArch
.setAllItems(ed
.getVSupportedArchitectures());
271 Tools
.generateComboBoxByVector(jComboBoxBinaryModule
, ed
.getVBoolean());
274 private boolean check() {
275 if (isEmpty(this.jTextFieldOutputFileBasename
.getText())) {
276 Log
.err("Output File Basename couldn't be empty!");
279 if (!DataValidation
.isOutputFileBasename(this.jTextFieldOutputFileBasename
.getText())) {
280 Log
.err("Incorrect data type for Output File Basename");
287 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
289 * Override componentResized to resize all components when frame's size is changed
291 public void componentResized(ComponentEvent arg0
) {
292 int intCurrentWidth
= this.getJContentPane().getWidth();
293 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
295 resizeComponentWidth(this.jScrollPaneArch
, intCurrentWidth
, intPreferredWidth
);
296 resizeComponentWidth(this.jComboBoxBinaryModule
, intCurrentWidth
, intPreferredWidth
);
297 resizeComponentWidth(this.jTextFieldOutputFileBasename
, intCurrentWidth
, intPreferredWidth
);
301 Save all components of Module Definitions
302 if exists Module Definitions, set the value directly
303 if not exists Module Definitions, new an instance first
309 if (this.md
== null) {
310 md
= ModuleDefinitionsDocument
.ModuleDefinitions
.Factory
.newInstance();
313 if (!isEmpty(this.jTextFieldOutputFileBasename
.getText())) {
314 md
.setOutputFileBasename(this.jTextFieldOutputFileBasename
.getText());
317 if (this.jComboBoxBinaryModule
.getSelectedIndex() == 0) {
318 md
.setBinaryModule(false);
320 md
.setBinaryModule(true);
324 // Set ClonedFrom field
326 if (this.cf
!= null) {
327 md
.setClonedFrom(this.cf
);
333 md
.setSupportedArchitectures(this.iCheckBoxListArch
.getAllCheckedItemsString());
335 msa
.setModuleDefinitions(md
);
337 this.omt
.setSaved(false);
339 } catch (Exception e
) {
340 Log
.err("Save Module Definitions", e
.getMessage());
344 public void focusLost(FocusEvent arg0
) {