]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/BootModesDlg.java
Adjusted sizes to accommodate Windows, iMac and Linux GUI
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / BootModesDlg.java
1 /** @file
2 <<The file is used to create, update BootModes of MSA file>>
3
4 <<The BootModesDlg is called to add or edit a Module's Boot Modes definitions.>>
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 Package Name: Tools
16 Module Name: FrameworkWizard
17
18 **/
19
20 package org.tianocore.frameworkwizard.module.ui.dialog;
21
22 import java.awt.event.ActionEvent;
23 import java.util.Vector;
24
25 import javax.swing.JButton;
26 import javax.swing.JComboBox;
27 import javax.swing.JLabel;
28 import javax.swing.JPanel;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextField;
31 import javax.swing.JTextArea;
32
33 import org.tianocore.frameworkwizard.common.DataType;
34 import org.tianocore.frameworkwizard.common.DataValidation;
35 import org.tianocore.frameworkwizard.common.EnumerationData;
36 import org.tianocore.frameworkwizard.common.Log;
37 import org.tianocore.frameworkwizard.common.Tools;
38 import org.tianocore.frameworkwizard.common.ui.ArchCheckBox;
39 import org.tianocore.frameworkwizard.common.ui.IDialog;
40 import org.tianocore.frameworkwizard.common.ui.IFrame;
41 import org.tianocore.frameworkwizard.common.ui.StarLabel;
42 import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesIdentification;
43
44 /**
45 * The class is used to create, update BootModes of MSA/MBD file It extends
46 * IDialog
47 *
48 *
49 *
50 */
51 public class BootModesDlg extends IDialog {
52
53 // /
54 // / Define class Serial Version UID
55 // /
56 private static final long serialVersionUID = -3888558623432442561L;
57
58 //
59 // Define class members
60 //
61 private JPanel jContentPane = null;
62 private JLabel jLabelTest = null;
63 private JLabel jLabelBootModeName = null;
64
65 private JComboBox jComboBoxBootModeName = null;
66
67 private JLabel jLabelUsage = null;
68
69 private JComboBox jComboBoxUsage = null;
70
71 private StarLabel jStarLabel1 = null;
72
73 private StarLabel jStarLabel2 = null;
74
75 private JLabel jLabelFeatureFlag = null;
76
77 private JTextField jTextFieldFeatureFlag = null;
78
79 private JLabel jLabelArch = null;
80
81 private JScrollPane jScrollPane = null;
82
83 private JLabel jLabelHelpText = null;
84
85 private JTextArea jTextAreaHelpText = null;
86
87 private JScrollPane jScrollPaneHelpText = null;
88
89 private ArchCheckBox jArchCheckBox = null;
90
91 private JButton jButtonOk = null;
92
93 private JButton jButtonCancel = null;
94
95 //
96 // Not used by UI
97 //
98 private BootModesIdentification id = null;
99
100 private EnumerationData ed = new EnumerationData();
101
102 /**
103 * This method initializes jComboBoxBootModeName
104 *
105 * @return javax.swing.JComboBox jComboBoxBootModeName
106 *
107 */
108 private JComboBox getJComboBoxBootModeName() {
109 if (jComboBoxBootModeName == null) {
110 jComboBoxBootModeName = new JComboBox();
111 jComboBoxBootModeName.setBounds(new java.awt.Rectangle(168, 12, 320, 20));
112 jComboBoxBootModeName.setPreferredSize(new java.awt.Dimension(320, 20));
113 jComboBoxBootModeName
114 .setToolTipText("<html><table>"
115 + "<tr><td>FULL</td><td>Boot with full configuration</td></tr>"
116 + "<tr><td>MINIMAL</td><td>Boot with minimal configuration</td></tr>"
117 + "<tr><td>NO_CHANGE</td><td>Boot assuming no configuration changes</td></tr>"
118 + "<tr><td>DIAGNOSTICS</td><td>Boot with full configuration plus diagnostics</td></tr>"
119 + "<tr><td>DEFAULT</td><td>Boot with default settings</td></tr>"
120 + "<tr><td>BOOT_ON_S#_RESUME</td><td>where # is 2, 3, 4 or 5</td></tr>"
121 + "<tr><td>FLASH_UPDATE</td><td>Boot on flash update</td></tr>"
122 + "<tr><td>RECOVERY</td><td>Boot in recovery mode</td></tr>"
123 + "</table></html>");
124 }
125 return jComboBoxBootModeName;
126 }
127
128 /**
129 * This method initializes jComboBoxUsage
130 *
131 * @return javax.swing.JComboBox jComboBoxUsage
132 *
133 */
134 private JComboBox getJComboBoxUsage() {
135 if (jComboBoxUsage == null) {
136 jComboBoxUsage = new JComboBox();
137 jComboBoxUsage.setBounds(new java.awt.Rectangle(168, 37, 320, 20));
138 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
139 jComboBoxUsage
140 .setToolTipText("<html><table>"
141 + "<tr><td>ALWAYS_CONSUMED</td><td>Indicates Supports the specified boot mode</td></tr>"
142 + "<tr><td>SOMETIMES_CONSUMED</td><td>Indicates Supports the specified boot mode on some execution paths</td></tr>"
143 + "<tr><td>ALWAYS_PRODUCED</td><td>Always changes the boot mode</td></tr>"
144 + "<tr><td>SOMETIMES_PRODUCED</td><td>Change the boot mode sometimes</td></tr>"
145 + "</table></html>");
146 }
147 return jComboBoxUsage;
148 }
149
150 /**
151 * This method initializes jTextFieldFeatureFlag
152 *
153 * @return javax.swing.JTextField
154 */
155 private JTextField getJTextFieldFeatureFlag() {
156 if (jTextFieldFeatureFlag == null) {
157 jTextFieldFeatureFlag = new JTextField();
158 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(168, 107, 320, 20));
159 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
160 jTextFieldFeatureFlag.setToolTipText("Postfix expression that must evaluate to TRUE or FALSE");
161 }
162 return jTextFieldFeatureFlag;
163 }
164
165 /**
166 * This method initializes jScrollPane
167 *
168 * @return javax.swing.JScrollPane
169 */
170 private JScrollPane getJScrollPane() {
171 if (jScrollPane == null) {
172 jScrollPane = new JScrollPane();
173 jScrollPane.setViewportView(getJContentPane());
174 }
175 return jScrollPane;
176 }
177
178 /**
179 * This method initializes jTextAreaHelpText
180 *
181 * @return javax.swing.JTextArea
182 *
183 */
184 private JTextArea getJTextAreaHelpText() {
185 if (jTextAreaHelpText == null) {
186 jTextAreaHelpText = new JTextArea();
187 jTextAreaHelpText.setLineWrap(true);
188 jTextAreaHelpText.setWrapStyleWord(true);
189 }
190 return jTextAreaHelpText;
191 }
192
193 /**
194 * This method initializes jScrollPaneHelpText
195 *
196 * @return javax.swing.JScrollPane
197 *
198 */
199 private JScrollPane getJScrollPaneHelpText() {
200 if (jScrollPaneHelpText == null) {
201 jScrollPaneHelpText = new JScrollPane();
202 jScrollPaneHelpText.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
203 jScrollPaneHelpText.setSize(new java.awt.Dimension(320, 40));
204 jScrollPaneHelpText.setPreferredSize(new java.awt.Dimension(320, 40));
205 jScrollPaneHelpText.setLocation(new java.awt.Point(168, 62));
206 jScrollPaneHelpText.setViewportView(getJTextAreaHelpText());
207 }
208 return jScrollPaneHelpText;
209 }
210
211 /**
212 * This method initializes jButtonOk
213 *
214 * @return javax.swing.JButton
215 *
216 */
217 private JButton getJButtonOk() {
218 if (jButtonOk == null) {
219 jButtonOk = new JButton();
220 jButtonOk.setBounds(new java.awt.Rectangle(290, 162, 90, 20));
221 jButtonOk.setText("Ok");
222 jButtonOk.addActionListener(this);
223 }
224 return jButtonOk;
225 }
226
227 /**
228 * This method initializes jButtonCancel
229 *
230 * @return javax.swing.JButton
231 *
232 */
233 private JButton getJButtonCancel() {
234 if (jButtonCancel == null) {
235 jButtonCancel = new JButton();
236 jButtonCancel.setBounds(new java.awt.Rectangle(390, 162, 90, 20));
237 jButtonCancel.setText("Cancel");
238 jButtonCancel.addActionListener(this);
239 }
240 return jButtonCancel;
241 }
242
243 public static void main(String[] args) {
244 }
245
246 /**
247 * This method initializes this
248 *
249 */
250 private void init() {
251 this.setSize(505, 235);
252 this.setContentPane(getJScrollPane());
253 this.setTitle("Boot Modes");
254 initFrame();
255 this.setViewMode(false);
256 this.centerWindow();
257 }
258
259 /**
260 * This method initializes this Fill values to all fields if these values are
261 * not empty
262 *
263 * @param inBootModesId
264 *
265 */
266 private void init(BootModesIdentification inBootModesId) {
267 init();
268 this.id = inBootModesId;
269
270 if (this.id != null) {
271 this.jComboBoxBootModeName.setSelectedItem(id.getName());
272 this.jComboBoxUsage.setSelectedItem(id.getUsage());
273 this.jTextAreaHelpText.setText(id.getHelp());
274 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
275 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
276 }
277 }
278
279 /**
280 * This is the override edit constructor
281 *
282 * @param inBootModesIdentification
283 * @param iFrame
284 *
285 */
286 public BootModesDlg(BootModesIdentification inBootModesIdentification, IFrame iFrame) {
287 super(iFrame, true);
288 init(inBootModesIdentification);
289 }
290
291 /**
292 * Disable all components when the mode is view
293 *
294 * @param isView
295 * true - The view mode; false - The non-view mode
296 *
297 */
298 public void setViewMode(boolean isView) {
299 if (isView) {
300 this.jComboBoxBootModeName.setEnabled(!isView);
301 this.jComboBoxUsage.setEnabled(!isView);
302 }
303 }
304
305 /**
306 * This method initializes jContentPane
307 *
308 * @return javax.swing.JPanel jContentPane
309 *
310 */
311 private JPanel getJContentPane() {
312 if (jContentPane == null) {
313 jStarLabel1 = new StarLabel();
314 jStarLabel1.setLocation(new java.awt.Point(2, 12));
315 jLabelBootModeName = new JLabel();
316 jLabelBootModeName.setText("Boot Mode Name");
317 jLabelBootModeName.setBounds(new java.awt.Rectangle(12, 12, 155, 20));
318 jStarLabel2 = new StarLabel();
319 jStarLabel2.setLocation(new java.awt.Point(2, 37));
320 jLabelUsage = new JLabel();
321 jLabelUsage.setText("Usage");
322 jLabelUsage.setBounds(new java.awt.Rectangle(12, 37, 155, 20));
323 jLabelHelpText = new JLabel();
324 jLabelHelpText.setBounds(new java.awt.Rectangle(12, 62, 155, 20));
325 jLabelHelpText.setText("Help Text");
326 jLabelFeatureFlag = new JLabel();
327 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(12, 107, 155, 20));
328 jLabelFeatureFlag.setText("Feature Flag Expression");
329 jLabelArch = new JLabel();
330 jLabelArch.setBounds(new java.awt.Rectangle(12, 132, 155, 20));
331 jLabelArch.setText("Supported Archectures");
332 jArchCheckBox = new ArchCheckBox();
333 jArchCheckBox.setBounds(new java.awt.Rectangle(168, 132, 320, 20));
334 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
335
336 jContentPane = new JPanel();
337 jContentPane.setLayout(null);
338 jContentPane.setPreferredSize(new java.awt.Dimension(480, 180));
339
340 jContentPane.add(jLabelBootModeName, null);
341 jContentPane.add(getJComboBoxBootModeName(), null);
342 jContentPane.add(jLabelUsage, null);
343 jContentPane.add(getJComboBoxUsage(), null);
344
345 jContentPane.add(jStarLabel1, null);
346 jContentPane.add(jStarLabel2, null);
347 jContentPane.add(jLabelFeatureFlag, null);
348 jContentPane.add(getJTextFieldFeatureFlag(), null);
349 jContentPane.add(jLabelArch, null);
350
351 jContentPane.add(jLabelHelpText, null);
352 jContentPane.add(getJScrollPaneHelpText(), null);
353 jContentPane.add(jArchCheckBox, null);
354 jContentPane.add(getJButtonOk(), null);
355 jContentPane.add(getJButtonCancel(), null);
356 }
357 return jContentPane;
358 }
359
360 /**
361 * This method initializes BootModeName groups and Usage type
362 *
363 */
364 private void initFrame() {
365 Tools.generateComboBoxByVector(jComboBoxBootModeName, ed.getVBootModeNames());
366 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
367 }
368
369 /*
370 * (non-Javadoc)
371 *
372 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
373 *
374 * Override actionPerformed to listen all actions
375 *
376 */
377 public void actionPerformed(ActionEvent arg0) {
378 if (arg0.getSource() == jButtonOk) {
379 if (checkAdd()) {
380 getCurrentBootModes();
381 this.returnType = DataType.RETURN_TYPE_OK;
382 this.setVisible(false);
383 }
384 }
385
386 if (arg0.getSource() == jButtonCancel) {
387 this.returnType = DataType.RETURN_TYPE_CANCEL;
388 this.setVisible(false);
389 }
390 }
391
392 /**
393 * Data validation for all fields
394 *
395 * @retval true - All datas are valid
396 * @retval false - At least one data is invalid
397 *
398 */
399 public boolean checkAdd() {
400 //
401 // Check if all fields have correct data types
402 //
403
404 //
405 // Check FeatureFlag
406 //
407 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
408 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
409 Log.wrn("Update Boot Modes", "Incorrect data type for Feature Flag");
410 return false;
411 }
412 }
413
414 return true;
415 }
416
417 private BootModesIdentification getCurrentBootModes() {
418 String arg0 = this.jComboBoxBootModeName.getSelectedItem().toString();
419 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
420
421 String arg2 = this.jTextFieldFeatureFlag.getText();
422 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
423 String arg4 = this.jTextAreaHelpText.getText();
424 id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);
425 return id;
426 }
427
428 public BootModesIdentification getId() {
429 return id;
430 }
431
432 public void setId(BootModesIdentification id) {
433 this.id = id;
434 }
435 }