]>
Commit | Line | Data |
---|---|---|
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 | |
15 | package org.tianocore.frameworkwizard.module.ui;\r | |
16 | \r | |
17 | import java.awt.event.ComponentEvent;\r | |
18 | import java.awt.event.FocusEvent;\r | |
19 | \r | |
20 | import javax.swing.JPanel;\r | |
21 | import javax.swing.JScrollPane;\r | |
22 | import javax.swing.JLabel;\r | |
23 | import javax.swing.JTextField;\r | |
24 | import javax.swing.JComboBox;\r | |
25 | \r | |
26 | import org.tianocore.ModuleDefinitionsDocument;\r | |
27 | import org.tianocore.ModuleSurfaceAreaDocument;\r | |
28 | import org.tianocore.ModuleDefinitionsDocument.ModuleDefinitions.ClonedFrom;\r | |
79cb6fdb | 29 | import org.tianocore.frameworkwizard.common.DataType;\r |
a13899c5 | 30 | import org.tianocore.frameworkwizard.common.DataValidation;\r |
31 | import org.tianocore.frameworkwizard.common.EnumerationData;\r | |
32 | import org.tianocore.frameworkwizard.common.Log;\r | |
a13899c5 | 33 | import org.tianocore.frameworkwizard.common.Tools;\r |
79cb6fdb | 34 | import org.tianocore.frameworkwizard.common.Identifications.OpeningModuleType;\r |
a13899c5 | 35 | import org.tianocore.frameworkwizard.common.ui.IInternalFrame;\r |
36 | import org.tianocore.frameworkwizard.common.ui.StarLabel;\r | |
37 | import org.tianocore.frameworkwizard.common.ui.iCheckBoxList.ICheckBoxList;\r | |
38 | \r | |
39 | public class ModuleDefinitions extends IInternalFrame {\r | |
40 | \r | |
41 | ///\r | |
42 | /// Define class Serial Version UID\r | |
43 | ///\r | |
44 | private static final long serialVersionUID = 5860378543553036323L;\r | |
45 | \r | |
46 | private JScrollPane jScrollPane = null;\r | |
47 | \r | |
48 | private JPanel jContentPane = null;\r | |
49 | \r | |
50 | private JLabel jLabelArch = null;\r | |
51 | \r | |
52 | private ICheckBoxList iCheckBoxListArch = null;\r | |
53 | \r | |
54 | private JLabel jLabelBinaryModule = null;\r | |
55 | \r | |
56 | private JComboBox jComboBoxBinaryModule = null;\r | |
57 | \r | |
58 | private JLabel jLabelOutputFileBasename = null;\r | |
59 | \r | |
60 | private JTextField jTextFieldOutputFileBasename = null;\r | |
61 | \r | |
62 | private JScrollPane jScrollPaneArch = null;\r | |
63 | \r | |
64 | private StarLabel jStarLabel1 = null;\r | |
65 | \r | |
66 | private StarLabel jStarLabel2 = null;\r | |
67 | \r | |
68 | private StarLabel jStarLabel3 = null;\r | |
69 | \r | |
70 | private OpeningModuleType omt = null;\r | |
71 | \r | |
72 | private ClonedFrom cf = null;\r | |
73 | \r | |
74 | private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = null;\r | |
75 | \r | |
76 | private ModuleDefinitionsDocument.ModuleDefinitions md = null;\r | |
77 | \r | |
78 | /**\r | |
79 | * This method initializes jScrollPane \r | |
80 | * \r | |
81 | * @return javax.swing.JScrollPane \r | |
82 | */\r | |
83 | private JScrollPane getJScrollPane() {\r | |
84 | if (jScrollPane == null) {\r | |
85 | jScrollPane = new JScrollPane();\r | |
86 | jScrollPane.setViewportView(getJContentPane());\r | |
87 | }\r | |
88 | return jScrollPane;\r | |
89 | }\r | |
90 | \r | |
91 | /**\r | |
92 | * This method initializes jPanel \r | |
93 | * \r | |
94 | * @return javax.swing.JPanel \r | |
95 | */\r | |
96 | private JPanel getJContentPane() {\r | |
97 | if (jContentPane == null) {\r | |
98 | jLabelOutputFileBasename = new JLabel();\r | |
99 | jLabelOutputFileBasename.setBounds(new java.awt.Rectangle(15, 10, 140, 20));\r | |
100 | jLabelOutputFileBasename.setText("Output File Basename");\r | |
101 | jLabelBinaryModule = new JLabel();\r | |
102 | jLabelBinaryModule.setBounds(new java.awt.Rectangle(15, 35, 140, 20));\r | |
103 | jLabelBinaryModule.setText("Binary Module");\r | |
104 | jLabelArch = new JLabel();\r | |
105 | jLabelArch.setBounds(new java.awt.Rectangle(15, 60, 140, 20));\r | |
106 | jLabelArch.setText("Supported Architectures");\r | |
107 | jStarLabel1 = new StarLabel();\r | |
108 | jStarLabel1.setLocation(new java.awt.Point(0, 10));\r | |
109 | jStarLabel2 = new StarLabel();\r | |
110 | jStarLabel2.setLocation(new java.awt.Point(0, 35));\r | |
111 | jStarLabel3 = new StarLabel();\r | |
112 | jStarLabel3.setLocation(new java.awt.Point(0, 60));\r | |
113 | \r | |
114 | jContentPane = new JPanel();\r | |
115 | jContentPane.setLayout(null);\r | |
116 | jContentPane.setPreferredSize(new java.awt.Dimension(490, 150));\r | |
117 | \r | |
118 | jContentPane.add(jLabelArch, null);\r | |
119 | jContentPane.add(getJScrollPaneArch(), null);\r | |
120 | jContentPane.add(jLabelBinaryModule, null);\r | |
121 | jContentPane.add(getJComboBoxBinaryModule(), null);\r | |
122 | jContentPane.add(jLabelOutputFileBasename, null);\r | |
123 | jContentPane.add(getJTextFieldOutputFileBasename(), null);\r | |
124 | jContentPane.add(jStarLabel1, null);\r | |
125 | jContentPane.add(jStarLabel2, null);\r | |
126 | jContentPane.add(jStarLabel3, null);\r | |
127 | }\r | |
128 | return jContentPane;\r | |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | This method initializes iCheckBoxListArch \r | |
133 | \r | |
134 | @return ICheckBoxList \r | |
135 | **/\r | |
136 | private ICheckBoxList getICheckBoxListSupportedArchitectures() {\r | |
137 | if (iCheckBoxListArch == null) {\r | |
138 | iCheckBoxListArch = new ICheckBoxList();\r | |
139 | iCheckBoxListArch.addFocusListener(this);\r | |
79cb6fdb | 140 | iCheckBoxListArch.setToolTipText(DataType.SUP_ARCH_LIST_HELP_TEXT);\r |
a13899c5 | 141 | }\r |
142 | return iCheckBoxListArch;\r | |
143 | }\r | |
144 | \r | |
145 | /**\r | |
146 | * This method initializes jComboBoxBinaryModule \r | |
147 | * \r | |
148 | * @return javax.swing.JComboBox \r | |
149 | */\r | |
150 | private JComboBox getJComboBoxBinaryModule() {\r | |
151 | if (jComboBoxBinaryModule == null) {\r | |
152 | jComboBoxBinaryModule = new JComboBox();\r | |
153 | jComboBoxBinaryModule.setBounds(new java.awt.Rectangle(160, 35, 320, 20));\r | |
154 | jComboBoxBinaryModule.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
155 | jComboBoxBinaryModule.addFocusListener(this);\r | |
156 | 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.");\r | |
157 | }\r | |
158 | return jComboBoxBinaryModule;\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | * This method initializes jTextFieldOutputFileBasename \r | |
163 | * \r | |
164 | * @return javax.swing.JTextField \r | |
165 | */\r | |
166 | private JTextField getJTextFieldOutputFileBasename() {\r | |
167 | if (jTextFieldOutputFileBasename == null) {\r | |
168 | jTextFieldOutputFileBasename = new JTextField();\r | |
169 | jTextFieldOutputFileBasename.setBounds(new java.awt.Rectangle(160, 10, 320, 20));\r | |
170 | jTextFieldOutputFileBasename.setPreferredSize(new java.awt.Dimension(320, 20));\r | |
171 | jTextFieldOutputFileBasename.addFocusListener(this);\r | |
172 | jTextFieldOutputFileBasename.setToolTipText("Enter a single word for generated output file names");\r | |
173 | }\r | |
174 | return jTextFieldOutputFileBasename;\r | |
175 | }\r | |
176 | \r | |
177 | /**\r | |
178 | This method initializes jScrollPaneArch \r | |
179 | \r | |
180 | @return javax.swing.JScrollPane \r | |
181 | \r | |
182 | **/\r | |
183 | private JScrollPane getJScrollPaneArch() {\r | |
184 | if (jScrollPaneArch == null) {\r | |
185 | jScrollPaneArch = new JScrollPane();\r | |
186 | jScrollPaneArch.setBounds(new java.awt.Rectangle(160, 60, 320, 80));\r | |
187 | jScrollPaneArch.setPreferredSize(new java.awt.Dimension(320, 60));\r | |
188 | jScrollPaneArch.setViewportView(getICheckBoxListSupportedArchitectures());\r | |
189 | }\r | |
190 | return jScrollPaneArch;\r | |
191 | }\r | |
192 | \r | |
193 | /**\r | |
194 | \r | |
195 | @param args\r | |
196 | \r | |
197 | **/\r | |
198 | public static void main(String[] args) {\r | |
199 | // TODO Auto-generated method stub\r | |
200 | \r | |
201 | }\r | |
202 | \r | |
203 | /**\r | |
204 | * This is the default constructor\r | |
205 | */\r | |
206 | public ModuleDefinitions() {\r | |
207 | super();\r | |
208 | init();\r | |
209 | this.setVisible(true);\r | |
210 | }\r | |
211 | \r | |
212 | /**\r | |
213 | This is the override edit constructor\r | |
214 | \r | |
215 | @param inMsa\r | |
216 | \r | |
217 | **/\r | |
218 | public ModuleDefinitions(OpeningModuleType inOmt) {\r | |
219 | super();\r | |
220 | this.omt = inOmt;\r | |
221 | this.msa = omt.getXmlMsa();\r | |
222 | if (msa.getModuleDefinitions() != null) {\r | |
223 | this.cf = msa.getModuleDefinitions().getClonedFrom(); \r | |
224 | }\r | |
225 | init(msa.getModuleDefinitions());\r | |
226 | this.setVisible(true);\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | * This method initializes this\r | |
231 | * \r | |
232 | * @return void\r | |
233 | */\r | |
234 | private void init() {\r | |
235 | this.setContentPane(getJScrollPane());\r | |
236 | this.setTitle("Module Definitions");\r | |
237 | initFrame();\r | |
238 | this.setPreferredSize(new java.awt.Dimension(490, 520));\r | |
239 | }\r | |
240 | \r | |
241 | /**\r | |
242 | This method initializes this\r | |
243 | Fill values to all fields if these values are not empty\r | |
244 | \r | |
245 | @param inMsaHeader The input data of MsaHeaderDocument.MsaHeader\r | |
246 | \r | |
247 | **/\r | |
248 | private void init(ModuleDefinitionsDocument.ModuleDefinitions inMd) {\r | |
249 | init();\r | |
250 | if (inMd != null) {\r | |
251 | this.md = inMd;\r | |
252 | if (md.getSupportedArchitectures() != null) {\r | |
253 | this.iCheckBoxListArch.initCheckedItem(true, Tools.convertListToVector(md.getSupportedArchitectures()));\r | |
254 | }\r | |
255 | if (md.getBinaryModule()) {\r | |
256 | this.jComboBoxBinaryModule.setSelectedIndex(1);\r | |
257 | } else {\r | |
258 | this.jComboBoxBinaryModule.setSelectedIndex(0);\r | |
259 | }\r | |
260 | if (md.getOutputFileBasename() != null) {\r | |
261 | this.jTextFieldOutputFileBasename.setText(md.getOutputFileBasename());\r | |
262 | }\r | |
263 | }\r | |
264 | }\r | |
265 | \r | |
266 | /**\r | |
267 | This method initializes Module type and Compontent type\r | |
268 | \r | |
269 | **/\r | |
270 | private void initFrame() {\r | |
271 | EnumerationData ed = new EnumerationData();\r | |
272 | this.iCheckBoxListArch.setAllItems(ed.getVSupportedArchitectures());\r | |
273 | Tools.generateComboBoxByVector(jComboBoxBinaryModule, ed.getVBoolean());\r | |
274 | }\r | |
275 | \r | |
276 | private boolean check() {\r | |
277 | if (isEmpty(this.jTextFieldOutputFileBasename.getText())) {\r | |
278 | Log.err("Output File Basename couldn't be empty!");\r | |
279 | return false;\r | |
280 | }\r | |
281 | if (!DataValidation.isOutputFileBasename(this.jTextFieldOutputFileBasename.getText())) {\r | |
282 | Log.err("Incorrect data type for Output File Basename");\r | |
283 | return false;\r | |
284 | }\r | |
285 | return true;\r | |
286 | }\r | |
287 | \r | |
288 | /* (non-Javadoc)\r | |
289 | * @see java.awt.event.ComponentListener#componentResized(java.awt.event.ComponentEvent)\r | |
290 | * \r | |
291 | * Override componentResized to resize all components when frame's size is changed\r | |
292 | */\r | |
293 | public void componentResized(ComponentEvent arg0) {\r | |
294 | int intCurrentWidth = this.getJContentPane().getWidth();\r | |
295 | int intPreferredWidth = this.getJContentPane().getPreferredSize().width;\r | |
296 | \r | |
297 | resizeComponentWidth(this.jScrollPaneArch, intCurrentWidth, intPreferredWidth);\r | |
298 | resizeComponentWidth(this.jComboBoxBinaryModule, intCurrentWidth, intPreferredWidth);\r | |
299 | resizeComponentWidth(this.jTextFieldOutputFileBasename, intCurrentWidth, intPreferredWidth);\r | |
300 | }\r | |
301 | \r | |
302 | /**\r | |
303 | Save all components of Module Definitions\r | |
304 | if exists Module Definitions, set the value directly\r | |
305 | if not exists Module Definitions, new an instance first\r | |
306 | \r | |
307 | **/\r | |
308 | public void save() {\r | |
309 | check();\r | |
310 | try {\r | |
311 | if (this.md == null) {\r | |
312 | md = ModuleDefinitionsDocument.ModuleDefinitions.Factory.newInstance();\r | |
313 | }\r | |
314 | \r | |
315 | if (!isEmpty(this.jTextFieldOutputFileBasename.getText())) {\r | |
316 | md.setOutputFileBasename(this.jTextFieldOutputFileBasename.getText());\r | |
317 | }\r | |
318 | \r | |
319 | if (this.jComboBoxBinaryModule.getSelectedIndex() == 0) {\r | |
320 | md.setBinaryModule(false);\r | |
321 | } else {\r | |
322 | md.setBinaryModule(true);\r | |
323 | }\r | |
324 | \r | |
325 | //\r | |
326 | // Set ClonedFrom field\r | |
327 | //\r | |
328 | if (this.cf != null) {\r | |
329 | md.setClonedFrom(this.cf);\r | |
330 | }\r | |
331 | \r | |
332 | //\r | |
333 | // Save Arch list\r | |
334 | //\r | |
335 | md.setSupportedArchitectures(this.iCheckBoxListArch.getAllCheckedItemsString());\r | |
336 | \r | |
337 | msa.setModuleDefinitions(md);\r | |
338 | \r | |
339 | this.omt.setSaved(false);\r | |
340 | \r | |
341 | } catch (Exception e) {\r | |
342 | Log.err("Save Module Definitions", e.getMessage());\r | |
343 | }\r | |
344 | }\r | |
345 | \r | |
346 | public void focusLost(FocusEvent arg0) {\r | |
347 | this.save();\r | |
79cb6fdb | 348 | if (arg0.getSource() == this.jTextFieldOutputFileBasename) {\r |
349 | }\r | |
a13899c5 | 350 | }\r |
351 | }\r |