]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/module/ui/dialog/BootModesDlg.java
1. Wrap text by word when showing a message box
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / module / ui / dialog / BootModesDlg.java
1 /** @file
2
3 The file is used to create, update BootModes of MSA/MBD file
4
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
10
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.
13
14 **/
15
16 package org.tianocore.frameworkwizard.module.ui.dialog;
17
18 import java.awt.event.ActionEvent;
19 import java.util.Vector;
20
21 import javax.swing.JButton;
22 import javax.swing.JComboBox;
23 import javax.swing.JLabel;
24 import javax.swing.JPanel;
25 import javax.swing.JScrollPane;
26 import javax.swing.JTextField;
27
28 import org.tianocore.frameworkwizard.common.DataType;
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.ui.ArchCheckBox;
34 import org.tianocore.frameworkwizard.common.ui.IDialog;
35 import org.tianocore.frameworkwizard.common.ui.IFrame;
36 import org.tianocore.frameworkwizard.common.ui.StarLabel;
37 import org.tianocore.frameworkwizard.module.Identifications.BootModes.BootModesIdentification;
38
39 /**
40 The class is used to create, update BootModes of MSA/MBD file
41 It extends IDialog
42
43
44
45 **/
46 public class BootModesDlg extends IDialog {
47
48 ///
49 /// Define class Serial Version UID
50 ///
51 private static final long serialVersionUID = -3888558623432442561L;
52
53 //
54 //Define class members
55 //
56 private JPanel jContentPane = null;
57
58 private JLabel jLabelBootModeName = null;
59
60 private JComboBox jComboBoxBootModeName = null;
61
62 private JLabel jLabelUsage = null;
63
64 private JComboBox jComboBoxUsage = null;
65
66 private StarLabel jStarLabel1 = null;
67
68 private StarLabel jStarLabel2 = null;
69
70 private JLabel jLabelFeatureFlag = null;
71
72 private JTextField jTextFieldFeatureFlag = null;
73
74 private JLabel jLabelArch = null;
75
76 private JScrollPane jScrollPane = null;
77
78 private JLabel jLabelHelpText = null;
79
80 private JTextField jTextFieldHelpText = null;
81
82 private ArchCheckBox jArchCheckBox = null;
83
84 private JButton jButtonOk = null;
85
86 private JButton jButtonCancel = null;
87
88 //
89 // Not used by UI
90 //
91 private BootModesIdentification id = null;
92
93 private EnumerationData ed = new EnumerationData();
94
95 /**
96 This method initializes jComboBoxBootModeName
97
98 @return javax.swing.JComboBox jComboBoxBootModeName
99
100 **/
101 private JComboBox getJComboBoxBootModeName() {
102 if (jComboBoxBootModeName == null) {
103 jComboBoxBootModeName = new JComboBox();
104 jComboBoxBootModeName.setBounds(new java.awt.Rectangle(160, 10, 320, 20));
105 jComboBoxBootModeName.setPreferredSize(new java.awt.Dimension(320, 20));
106 }
107 return jComboBoxBootModeName;
108 }
109
110 /**
111 This method initializes jComboBoxUsage
112
113 @return javax.swing.JComboBox jComboBoxUsage
114
115 **/
116 private JComboBox getJComboBoxUsage() {
117 if (jComboBoxUsage == null) {
118 jComboBoxUsage = new JComboBox();
119 jComboBoxUsage.setBounds(new java.awt.Rectangle(160, 35, 320, 20));
120 jComboBoxUsage.setPreferredSize(new java.awt.Dimension(320, 20));
121 }
122 return jComboBoxUsage;
123 }
124
125 /**
126 * This method initializes jTextFieldFeatureFlag
127 *
128 * @return javax.swing.JTextField
129 */
130 private JTextField getJTextFieldFeatureFlag() {
131 if (jTextFieldFeatureFlag == null) {
132 jTextFieldFeatureFlag = new JTextField();
133 jTextFieldFeatureFlag.setBounds(new java.awt.Rectangle(160, 85, 320, 20));
134 jTextFieldFeatureFlag.setPreferredSize(new java.awt.Dimension(320, 20));
135 }
136 return jTextFieldFeatureFlag;
137 }
138
139 /**
140 This method initializes jScrollPane
141
142 @return javax.swing.JScrollPane
143 */
144 private JScrollPane getJScrollPane() {
145 if (jScrollPane == null) {
146 jScrollPane = new JScrollPane();
147 jScrollPane.setViewportView(getJContentPane());
148 }
149 return jScrollPane;
150 }
151
152 /**
153 This method initializes jTextFieldHelpText
154
155 @return javax.swing.JTextField
156
157 **/
158 private JTextField getJTextFieldHelpText() {
159 if (jTextFieldHelpText == null) {
160 jTextFieldHelpText = new JTextField();
161 jTextFieldHelpText.setBounds(new java.awt.Rectangle(160, 60, 320, 20));
162 jTextFieldHelpText.setPreferredSize(new java.awt.Dimension(320, 20));
163 }
164 return jTextFieldHelpText;
165 }
166
167 /**
168 This method initializes jButtonOk
169
170 @return javax.swing.JButton
171
172 **/
173 private JButton getJButtonOk() {
174 if (jButtonOk == null) {
175 jButtonOk = new JButton();
176 jButtonOk.setBounds(new java.awt.Rectangle(290, 140, 90, 20));
177 jButtonOk.setText("Ok");
178 jButtonOk.addActionListener(this);
179 }
180 return jButtonOk;
181 }
182
183 /**
184 This method initializes jButtonCancel
185
186 @return javax.swing.JButton
187
188 **/
189 private JButton getJButtonCancel() {
190 if (jButtonCancel == null) {
191 jButtonCancel = new JButton();
192 jButtonCancel.setBounds(new java.awt.Rectangle(390, 140, 90, 20));
193 jButtonCancel.setText("Cancel");
194 jButtonCancel.addActionListener(this);
195 }
196 return jButtonCancel;
197 }
198
199 public static void main(String[] args) {
200 }
201
202 /**
203 This method initializes this
204
205 **/
206 private void init() {
207 this.setSize(500, 200);
208 this.setContentPane(getJScrollPane());
209 this.setTitle("Boot Modes");
210 initFrame();
211 this.setViewMode(false);
212 this.centerWindow();
213 }
214
215 /**
216 This method initializes this
217 Fill values to all fields if these values are not empty
218
219 @param inBootModesId
220
221 **/
222 private void init(BootModesIdentification inBootModesId) {
223 init();
224 this.id = inBootModesId;
225
226 if (this.id != null) {
227 this.jComboBoxBootModeName.setSelectedItem(id.getName());
228 this.jComboBoxUsage.setSelectedItem(id.getUsage());
229 this.jTextFieldHelpText.setText(id.getHelp());
230 this.jTextFieldFeatureFlag.setText(id.getFeatureFlag());
231 this.jArchCheckBox.setSelectedItems(id.getSupArchList());
232 }
233 }
234
235 /**
236 This is the override edit constructor
237
238 @param inBootModesIdentification
239 @param iFrame
240
241 **/
242 public BootModesDlg(BootModesIdentification inBootModesIdentification, IFrame iFrame) {
243 super(iFrame, true);
244 init(inBootModesIdentification);
245 }
246
247 /**
248 Disable all components when the mode is view
249
250 @param isView true - The view mode; false - The non-view mode
251
252 **/
253 public void setViewMode(boolean isView) {
254 if (isView) {
255 this.jComboBoxBootModeName.setEnabled(!isView);
256 this.jComboBoxUsage.setEnabled(!isView);
257 }
258 }
259
260 /**
261 This method initializes jContentPane
262
263 @return javax.swing.JPanel jContentPane
264
265 **/
266 private JPanel getJContentPane() {
267 if (jContentPane == null) {
268 jArchCheckBox = new ArchCheckBox();
269 jArchCheckBox.setBounds(new java.awt.Rectangle(160, 110, 320, 20));
270 jArchCheckBox.setPreferredSize(new java.awt.Dimension(320, 20));
271 jLabelArch = new JLabel();
272 jLabelArch.setBounds(new java.awt.Rectangle(15, 110, 140, 20));
273 jLabelArch.setText("Arch");
274 jLabelFeatureFlag = new JLabel();
275 jLabelFeatureFlag.setBounds(new java.awt.Rectangle(15, 85, 140, 20));
276 jLabelFeatureFlag.setText("Feature Flag");
277 jLabelUsage = new JLabel();
278 jLabelUsage.setText("Usage");
279 jLabelUsage.setBounds(new java.awt.Rectangle(15, 35, 140, 20));
280 jLabelBootModeName = new JLabel();
281 jLabelBootModeName.setText("Boot Mode Name");
282 jLabelBootModeName.setBounds(new java.awt.Rectangle(15, 10, 140, 20));
283 jLabelHelpText = new JLabel();
284 jLabelHelpText.setBounds(new java.awt.Rectangle(14, 60, 140, 20));
285 jLabelHelpText.setText("Help Text");
286
287 jContentPane = new JPanel();
288 jContentPane.setLayout(null);
289 jContentPane.setPreferredSize(new java.awt.Dimension(490, 165));
290
291 jContentPane.add(jLabelBootModeName, null);
292 jContentPane.add(getJComboBoxBootModeName(), null);
293 jContentPane.add(jLabelUsage, null);
294 jContentPane.add(getJComboBoxUsage(), null);
295 jStarLabel1 = new StarLabel();
296 jStarLabel1.setLocation(new java.awt.Point(0, 10));
297 jStarLabel2 = new StarLabel();
298 jStarLabel2.setLocation(new java.awt.Point(0, 35));
299
300 jContentPane.add(jStarLabel1, null);
301 jContentPane.add(jStarLabel2, null);
302 jContentPane.add(jLabelFeatureFlag, null);
303 jContentPane.add(getJTextFieldFeatureFlag(), null);
304 jContentPane.add(jLabelArch, null);
305
306 jContentPane.add(jLabelHelpText, null);
307 jContentPane.add(getJTextFieldHelpText(), null);
308 jContentPane.add(jArchCheckBox, null);
309 jContentPane.add(getJButtonOk(), null);
310 jContentPane.add(getJButtonCancel(), null);
311 }
312 return jContentPane;
313 }
314
315 /**
316 This method initializes BootModeName groups and Usage type
317
318 **/
319 private void initFrame() {
320 Tools.generateComboBoxByVector(jComboBoxBootModeName, ed.getVBootModeNames());
321 Tools.generateComboBoxByVector(jComboBoxUsage, ed.getVPpiUsage());
322 }
323
324 /* (non-Javadoc)
325 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
326 *
327 * Override actionPerformed to listen all actions
328 *
329 */
330 public void actionPerformed(ActionEvent arg0) {
331 if (arg0.getSource() == jButtonOk) {
332 if (checkAdd()) {
333 getCurrentBootModes();
334 this.returnType = DataType.RETURN_TYPE_OK;
335 this.setVisible(false);
336 }
337 }
338
339 if (arg0.getSource() == jButtonCancel) {
340 this.returnType = DataType.RETURN_TYPE_CANCEL;
341 this.setVisible(false);
342 }
343 }
344
345 /**
346 Data validation for all fields
347
348 @retval true - All datas are valid
349 @retval false - At least one data is invalid
350
351 **/
352 public boolean checkAdd() {
353 //
354 // Check if all fields have correct data types
355 //
356
357 //
358 // Check FeatureFlag
359 //
360 if (!isEmpty(this.jTextFieldFeatureFlag.getText())) {
361 if (!DataValidation.isFeatureFlag(this.jTextFieldFeatureFlag.getText())) {
362 Log.wrn("Update Boot Modes", "Incorrect data type for Feature Flag");
363 return false;
364 }
365 }
366
367 return true;
368 }
369
370 private BootModesIdentification getCurrentBootModes() {
371 String arg0 = this.jComboBoxBootModeName.getSelectedItem().toString();
372
373 String arg1 = this.jComboBoxUsage.getSelectedItem().toString();
374
375 String arg2 = this.jTextFieldFeatureFlag.getText();
376 Vector<String> arg3 = this.jArchCheckBox.getSelectedItemsVector();
377 String arg4 = this.jTextFieldHelpText.getText();
378 id = new BootModesIdentification(arg0, arg1, arg2, arg3, arg4);
379 return id;
380 }
381
382 public BootModesIdentification getId() {
383 return id;
384 }
385
386 public void setId(BootModesIdentification id) {
387 this.id = id;
388 }
389 }