]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/ModuleDefinitions.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / ModuleDefinitions.java
CommitLineData
a13899c5 1/** @file\r
2 \r
3 The file is used to create, update Module Definitions of MSA file\r
4 \r
5 Copyright (c) 2006, Intel Corporation\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10 \r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13 \r
14 **/\r
15package org.tianocore.frameworkwizard.module.ui;\r
16\r
17import java.awt.event.ComponentEvent;\r
18import java.awt.event.FocusEvent;\r
19\r
20import javax.swing.JPanel;\r
21import javax.swing.JScrollPane;\r
22import javax.swing.JLabel;\r
23import javax.swing.JTextField;\r
24import javax.swing.JComboBox;\r
25\r
26import org.tianocore.ModuleDefinitionsDocument;\r
27import org.tianocore.ModuleSurfaceAreaDocument;\r
28import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions.ClonedFrom;\r
29import org.tianocore.frameworkwizard.common.DataValidation;\r
30import org.tianocore.frameworkwizard.common.EnumerationData;\r
31import org.tianocore.frameworkwizard.common.Log;\r
a13899c5 32import org.tianocore.frameworkwizard.common.Tools;\r
79cb6fdb 33import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r
a13899c5 34import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r
35import org.tianocore.frameworkwizard.common.ui.StarLabel;\r
36import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r
37\r
38public class ModuleDefinitions extends IInternalFrame {\r
39\r
40 ///\r
41 /// Define class Serial Version UID\r
42 ///\r
43 private static final long serialVersionUID = 5860378543553036323L;\r
44\r
45 private JScrollPane jScrollPane = null;\r
46\r
47 private JPanel jContentPane = null;\r
48\r
49 private JLabel jLabelArch = null;\r
50\r
51 private ICheckBoxList iCheckBoxListArch = null;\r
52\r
53 private JLabel jLabelBinaryModule = null;\r
54\r
55 private JComboBox jComboBoxBinaryModule = null;\r
56\r
57 private JLabel jLabelOutputFileBasename = null;\r
58\r
59 private JTextField jTextFieldOutputFileBasename = null;\r
60\r
61 private JScrollPane jScrollPaneArch = null;\r
62\r
63 private StarLabel jStarLabel1 = null;\r
64\r
65 private StarLabel jStarLabel2 = null;\r
66\r
67 private StarLabel jStarLabel3 = null;\r
68 \r
69 private OpeningModuleType omt = null;\r
70 \r
71 private ClonedFrom cf = null;\r
72\r
73 private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;\r
74\r
75 private ModuleDefinitionsDocument.ModuleDefinitions md = null;\r
76\r
77 /**\r
78 * This method initializes jScrollPane \r
79 * \r
80 * @return javax.swing.JScrollPane \r
81 */\r
82 private JScrollPane getJScrollPane() {\r
83 if (jScrollPane == null) {\r
84 jScrollPane = new JScrollPane();\r
85 jScrollPane.setViewportView(getJContentPane());\r
86 }\r
87 return jScrollPane;\r
88 }\r
89\r
90 /**\r
91 * This method initializes jPanel \r
92 * \r
93 * @return javax.swing.JPanel \r
94 */\r
95 private JPanel getJContentPane() {\r
96 if (jContentPane == null) {\r
97 jLabelOutputFileBasename = new JLabel();\r
98 jLabelOutputFileBasename.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r
99 jLabelOutputFileBasename.setText("Output File Basename");\r
100 jLabelBinaryModule = new JLabel();\r
101 jLabelBinaryModule.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r
102 jLabelBinaryModule.setText("Binary Module");\r
103 jLabelArch = new JLabel();\r
104 jLabelArch.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r
105 jLabelArch.setText("Supported Architectures");\r
106 jStarLabel1 = new StarLabel();\r
107 jStarLabel1.setLocation(new java.awt.Point(0, 10));\r
108 jStarLabel2 = new StarLabel();\r
109 jStarLabel2.setLocation(new java.awt.Point(0, 35));\r
110 jStarLabel3 = new StarLabel();\r
111 jStarLabel3.setLocation(new java.awt.Point(0, 60));\r
112\r
113 jContentPane = new JPanel();\r
114 jContentPane.setLayout(null);\r
115 jContentPane.setPreferredSize(new java.awt.Dimension(490, 150));\r
116\r
117 jContentPane.add(jLabelArch, null);\r
118 jContentPane.add(getJScrollPaneArch(), null);\r
119 jContentPane.add(jLabelBinaryModule, null);\r
120 jContentPane.add(getJComboBoxBinaryModule(), null);\r
121 jContentPane.add(jLabelOutputFileBasename, null);\r
122 jContentPane.add(getJTextFieldOutputFileBasename(), null);\r
123 jContentPane.add(jStarLabel1, null);\r
124 jContentPane.add(jStarLabel2, null);\r
125 jContentPane.add(jStarLabel3, null);\r
126 }\r
127 return jContentPane;\r
128 }\r
129\r
130 /**\r
131 This method initializes iCheckBoxListArch \r
132 \r
133 @return ICheckBoxList \r
134 **/\r
135 private ICheckBoxList getICheckBoxListSupportedArchitectures() {\r
136 if (iCheckBoxListArch == null) {\r
137 iCheckBoxListArch = new ICheckBoxList();\r
138 iCheckBoxListArch.addFocusListener(this);\r
9a8d6d9f 139 iCheckBoxListArch.setToolTipText("<html>Deselecting a checkbox will restrict this module<br>" +\r
140 "for use with the selected architectures, <br>" +\r
141 "based on the list of items that are checked. <br>" +\r
142 "If all boxes are checked, <br>" +\r
143 "then the module will support all <br>" +\r
144 "current AND FUTURE architectures</html>");\r
a13899c5 145 }\r
146 return iCheckBoxListArch;\r
147 }\r
148\r
149 /**\r
150 * This method initializes jComboBoxBinaryModule \r
151 * \r
152 * @return javax.swing.JComboBox \r
153 */\r
154 private JComboBox getJComboBoxBinaryModule() {\r
155 if (jComboBoxBinaryModule == null) {\r
156 jComboBoxBinaryModule = new JComboBox();\r
157 jComboBoxBinaryModule.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r
158 jComboBoxBinaryModule.setPreferredSize(new java.awt.Dimension(320, 20));\r
159 jComboBoxBinaryModule.addFocusListener(this);\r
9a8d6d9f 160 jComboBoxBinaryModule.setToolTipText("<html>Modules are either source modules <br>" +\r
161 "which can be compiled or binary <br>" +\r
162 "modules which are linked. <br>" +\r
163 "A module cannot contain both. <br>" +\r
164 "The GUID numbers should be identical <br>" +\r
165 "for a binary and source MSA, <br>" +\r
166 "but the BINARY MSA should have <br>" +\r
167 "a higher version number.</html>");\r
a13899c5 168 }\r
169 return jComboBoxBinaryModule;\r
170 }\r
171\r
172 /**\r
173 * This method initializes jTextFieldOutputFileBasename \r
174 * \r
175 * @return javax.swing.JTextField \r
176 */\r
177 private JTextField getJTextFieldOutputFileBasename() {\r
178 if (jTextFieldOutputFileBasename == null) {\r
179 jTextFieldOutputFileBasename = new JTextField();\r
180 jTextFieldOutputFileBasename.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r
181 jTextFieldOutputFileBasename.setPreferredSize(new java.awt.Dimension(320, 20));\r
182 jTextFieldOutputFileBasename.addFocusListener(this);\r
183 jTextFieldOutputFileBasename.setToolTipText("Enter a single word for generated output file names");\r
184 }\r
185 return jTextFieldOutputFileBasename;\r
186 }\r
187\r
188 /**\r
189 This method initializes jScrollPaneArch \r
190 \r
191 @return javax.swing.JScrollPane \r
192 \r
193 **/\r
194 private JScrollPane getJScrollPaneArch() {\r
195 if (jScrollPaneArch == null) {\r
196 jScrollPaneArch = new JScrollPane();\r
197 jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 60, 320, 80));\r
198 jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 60));\r
199 jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());\r
200 }\r
201 return jScrollPaneArch;\r
202 }\r
203\r
204 /**\r
205 \r
206 @param args\r
207 \r
208 **/\r
209 public static void main(String[] args) {\r
210 // TODO Auto-generated method stub\r
211\r
212 }\r
213\r
214 /**\r
215 * This is the default constructor\r
216 */\r
217 public ModuleDefinitions() {\r
218 super();\r
219 init();\r
220 this.setVisible(true);\r
221 }\r
222\r
223 /**\r
224 This is the override edit constructor\r
225 \r
226 @param inMsa\r
227 \r
228 **/\r
229 public ModuleDefinitions(OpeningModuleType inOmt) {\r
230 super();\r
231 this.omt = inOmt;\r
232 this.msa = omt.getXmlMsa();\r
233 if (msa.getModuleDefinitions() != null) {\r
234 this.cf = msa.getModuleDefinitions().getClonedFrom(); \r
235 }\r
236 init(msa.getModuleDefinitions());\r
237 this.setVisible(true);\r
238 }\r
239\r
240 /**\r
241 * This method initializes this\r
242 * \r
243 * @return void\r
244 */\r
245 private void init() {\r
246 this.setContentPane(getJScrollPane());\r
247 this.setTitle("Module Definitions");\r
248 initFrame();\r
249 this.setPreferredSize(new java.awt.Dimension(490, 520));\r
250 }\r
251\r
252 /**\r
253 This method initializes this\r
254 Fill values to all fields if these values are not empty\r
255 \r
256 @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader\r
257 \r
258 **/\r
259 private void init(ModuleDefinitionsDocument.ModuleDefinitions inMd) {\r
260 init();\r
261 if (inMd != null) {\r
262 this.md = inMd;\r
263 if (md.getSupportedArchitectures() != null) {\r
264 this.iCheckBoxListArch.initCheckedItem(true, Tools.convertListToVector(md.getSupportedArchitectures()));\r
265 }\r
266 if (md.getBinaryModule()) {\r
267 this.jComboBoxBinaryModule.setSelectedIndex(1);\r
268 } else {\r
269 this.jComboBoxBinaryModule.setSelectedIndex(0);\r
270 }\r
271 if (md.getOutputFileBasename() != null) {\r
272 this.jTextFieldOutputFileBasename.setText(md.getOutputFileBasename());\r
273 }\r
274 }\r
275 }\r
276\r
277 /**\r
278 This method initializes Module type and Compontent type\r
279 \r
280 **/\r
281 private void initFrame() {\r
282 EnumerationData ed = new EnumerationData();\r
283 this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());\r
284 Tools.generateComboBoxByVector(jComboBoxBinaryModule, ed.getVBoolean());\r
285 }\r
286 \r
287 private boolean check() {\r
288 if (isEmpty(this.jTextFieldOutputFileBasename.getText())) {\r
ed1665f2 289 Log.wrn("Update Definitions", "Output File Basename couldn't be empty!");\r
a13899c5 290 return false;\r
291 }\r
292 if (!DataValidation.isOutputFileBasename(this.jTextFieldOutputFileBasename.getText())) {\r
ed1665f2 293 Log.wrn("Update Definitions", "Incorrect data type for Output File Basename");\r
a13899c5 294 return false;\r
295 }\r
296 return true;\r
297 }\r
298\r
299 /* (non-Javadoc)\r
300 * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r
301 * \r
302 * Override componentResized to resize all components when frame's size is changed\r
303 */\r
304 public void componentResized(ComponentEvent arg0) {\r
305 int intCurrentWidth = this.getJContentPane().getWidth();\r
306 int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r
307\r
308 resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth);\r
309 resizeComponentWidth(this.jComboBoxBinaryModule, intCurrentWidth, intPreferredWidth);\r
310 resizeComponentWidth(this.jTextFieldOutputFileBasename, intCurrentWidth, intPreferredWidth);\r
311 }\r
312\r
313 /**\r
314 Save all components of Module Definitions\r
315 if exists Module Definitions, set the value directly\r
316 if not exists Module Definitions, new an instance first\r
317 \r
318 **/\r
319 public void save() {\r
320 check();\r
321 try {\r
322 if (this.md == null) {\r
323 md = ModuleDefinitionsDocument.ModuleDefinitions.Factory.newInstance();\r
324 }\r
325\r
326 if (!isEmpty(this.jTextFieldOutputFileBasename.getText())) {\r
327 md.setOutputFileBasename(this.jTextFieldOutputFileBasename.getText());\r
328 }\r
329\r
330 if (this.jComboBoxBinaryModule.getSelectedIndex() == 0) {\r
331 md.setBinaryModule(false);\r
332 } else {\r
333 md.setBinaryModule(true);\r
334 }\r
335 \r
336 //\r
337 // Set ClonedFrom field\r
338 //\r
339 if (this.cf != null) {\r
340 md.setClonedFrom(this.cf);\r
341 }\r
342\r
343 //\r
344 // Save Arch list\r
345 //\r
346 md.setSupportedArchitectures(this.iCheckBoxListArch.getAllCheckedItemsString());\r
347 \r
348 msa.setModuleDefinitions(md);\r
349 \r
350 this.omt.setSaved(false);\r
351\r
352 } catch (Exception e) {\r
353 Log.err("Save Module Definitions", e.getMessage());\r
354 }\r
355 }\r
356\r
357 public void focusLost(FocusEvent arg0) {\r
358 this.save();\r
79cb6fdb 359 if (arg0.getSource() == this.jTextFieldOutputFileBasename) {\r
360 }\r
a13899c5 361 }\r
362}\r