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
.Tools
;
33 import org
.tianocore
.frameworkwizard
.common
.Identifications
.OpeningModuleType
;
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);
139 iCheckBoxListArch
.setToolTipText("<html>Deselecting a checkbox will restrict this module<br>" +
140 "for use with the selected architectures, <br>" +
141 "based on the list of items that are checked. <br>" +
142 "If all boxes are checked, <br>" +
143 "then the module will support all <br>" +
144 "current AND FUTURE architectures</html>");
146 return iCheckBoxListArch
;
150 * This method initializes jComboBoxBinaryModule
152 * @return javax.swing.JComboBox
154 private JComboBox
getJComboBoxBinaryModule() {
155 if (jComboBoxBinaryModule
== null) {
156 jComboBoxBinaryModule
= new JComboBox();
157 jComboBoxBinaryModule
.setBounds(new java
.awt
.Rectangle(160, 35, 320, 20));
158 jComboBoxBinaryModule
.setPreferredSize(new java
.awt
.Dimension(320, 20));
159 jComboBoxBinaryModule
.addFocusListener(this);
160 jComboBoxBinaryModule
.setToolTipText("<html>Modules are either source modules <br>" +
161 "which can be compiled or binary <br>" +
162 "modules which are linked. <br>" +
163 "A module cannot contain both. <br>" +
164 "The GUID numbers should be identical <br>" +
165 "for a binary and source MSA, <br>" +
166 "but the BINARY MSA should have <br>" +
167 "a higher version number.</html>");
169 return jComboBoxBinaryModule
;
173 * This method initializes jTextFieldOutputFileBasename
175 * @return javax.swing.JTextField
177 private JTextField
getJTextFieldOutputFileBasename() {
178 if (jTextFieldOutputFileBasename
== null) {
179 jTextFieldOutputFileBasename
= new JTextField();
180 jTextFieldOutputFileBasename
.setBounds(new java
.awt
.Rectangle(160, 10, 320, 20));
181 jTextFieldOutputFileBasename
.setPreferredSize(new java
.awt
.Dimension(320, 20));
182 jTextFieldOutputFileBasename
.addFocusListener(this);
183 jTextFieldOutputFileBasename
.setToolTipText("Enter a single word for generated output file names");
185 return jTextFieldOutputFileBasename
;
189 This method initializes jScrollPaneArch
191 @return javax.swing.JScrollPane
194 private JScrollPane
getJScrollPaneArch() {
195 if (jScrollPaneArch
== null) {
196 jScrollPaneArch
= new JScrollPane();
197 jScrollPaneArch
.setBounds(new java
.awt
.Rectangle(160, 60, 320, 80));
198 jScrollPaneArch
.setPreferredSize(new java
.awt
.Dimension(320, 60));
199 jScrollPaneArch
.setViewportView(getICheckBoxListSupportedArchitectures());
201 return jScrollPaneArch
;
209 public static void main(String
[] args
) {
210 // TODO Auto-generated method stub
215 * This is the default constructor
217 public ModuleDefinitions() {
220 this.setVisible(true);
224 This is the override edit constructor
229 public ModuleDefinitions(OpeningModuleType inOmt
) {
232 this.msa
= omt
.getXmlMsa();
233 if (msa
.getModuleDefinitions() != null) {
234 this.cf
= msa
.getModuleDefinitions().getClonedFrom();
236 init(msa
.getModuleDefinitions());
237 this.setVisible(true);
241 * This method initializes this
245 private void init() {
246 this.setContentPane(getJScrollPane());
247 this.setTitle("Module Definitions");
249 this.setPreferredSize(new java
.awt
.Dimension(490, 520));
253 This method initializes this
254 Fill values to all fields if these values are not empty
256 @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader
259 private void init(ModuleDefinitionsDocument
.ModuleDefinitions inMd
) {
263 if (md
.getSupportedArchitectures() != null) {
264 this.iCheckBoxListArch
.initCheckedItem(true, Tools
.convertListToVector(md
.getSupportedArchitectures()));
266 if (md
.getBinaryModule()) {
267 this.jComboBoxBinaryModule
.setSelectedIndex(1);
269 this.jComboBoxBinaryModule
.setSelectedIndex(0);
271 if (md
.getOutputFileBasename() != null) {
272 this.jTextFieldOutputFileBasename
.setText(md
.getOutputFileBasename());
278 This method initializes Module type and Compontent type
281 private void initFrame() {
282 EnumerationData ed
= new EnumerationData();
283 this.iCheckBoxListArch
.setAllItems(ed
.getVSupportedArchitectures());
284 Tools
.generateComboBoxByVector(jComboBoxBinaryModule
, ed
.getVBoolean());
287 private boolean check() {
288 if (isEmpty(this.jTextFieldOutputFileBasename
.getText())) {
289 Log
.err("Output File Basename couldn't be empty!");
292 if (!DataValidation
.isOutputFileBasename(this.jTextFieldOutputFileBasename
.getText())) {
293 Log
.err("Incorrect data type for Output File Basename");
300 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)
302 * Override componentResized to resize all components when frame's size is changed
304 public void componentResized(ComponentEvent arg0
) {
305 int intCurrentWidth
= this.getJContentPane().getWidth();
306 int intPreferredWidth
= this.getJContentPane().getPreferredSize().width
;
308 resizeComponentWidth(this.jScrollPaneArch
, intCurrentWidth
, intPreferredWidth
);
309 resizeComponentWidth(this.jComboBoxBinaryModule
, intCurrentWidth
, intPreferredWidth
);
310 resizeComponentWidth(this.jTextFieldOutputFileBasename
, intCurrentWidth
, intPreferredWidth
);
314 Save all components of Module Definitions
315 if exists Module Definitions, set the value directly
316 if not exists Module Definitions, new an instance first
322 if (this.md
== null) {
323 md
= ModuleDefinitionsDocument
.ModuleDefinitions
.Factory
.newInstance();
326 if (!isEmpty(this.jTextFieldOutputFileBasename
.getText())) {
327 md
.setOutputFileBasename(this.jTextFieldOutputFileBasename
.getText());
330 if (this.jComboBoxBinaryModule
.getSelectedIndex() == 0) {
331 md
.setBinaryModule(false);
333 md
.setBinaryModule(true);
337 // Set ClonedFrom field
339 if (this.cf
!= null) {
340 md
.setClonedFrom(this.cf
);
346 md
.setSupportedArchitectures(this.iCheckBoxListArch
.getAllCheckedItemsString());
348 msa
.setModuleDefinitions(md
);
350 this.omt
.setSaved(false);
352 } catch (Exception e
) {
353 Log
.err("Save Module Definitions", e
.getMessage());
357 public void focusLost(FocusEvent arg0
) {
359 if (arg0
.getSource() == this.jTextFieldOutputFileBasename
) {