Fixed grammar in text messages.
[mirror_edk2.git] / Tools / Source / FrameworkWizard / src / org / tianocore / frameworkwizard / far / createui / CreateStepOne.java
1 /** @file
2
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 package org.tianocore.frameworkwizard.far.createui;
15
16 import java.awt.event.MouseEvent;
17 import java.awt.event.MouseListener;
18
19 import javax.swing.JButton;
20 import javax.swing.JLabel;
21 import javax.swing.JPanel;
22 import javax.swing.JScrollPane;
23 import javax.swing.JTextArea;
24 import javax.swing.JTextField;
25
26 import org.tianocore.frameworkwizard.common.DataValidation;
27 import org.tianocore.frameworkwizard.common.Log;
28 import org.tianocore.frameworkwizard.common.Tools;
29 import org.tianocore.frameworkwizard.common.ui.IDialog;
30 import org.tianocore.frameworkwizard.common.ui.IFrame;
31 import org.tianocore.frameworkwizard.common.ui.StarLabel;
32 import org.tianocore.frameworkwizard.far.FarHeader;
33 import org.tianocore.frameworkwizard.far.FarStringDefinition;
34
35 public class CreateStepOne extends IDialog implements MouseListener {
36
37 // /
38 // / Define class Serial Version UID
39 // /
40 private static final long serialVersionUID = -8152099582923006900L;
41
42 //
43 // Define class members
44 //
45 private JPanel jContentPane = null;
46
47 private JLabel jLabelBaseName = null;
48
49 private JTextField jTextFieldBaseName = null;
50
51 private JLabel jLabelGuid = null;
52
53 private JTextField jTextFieldGuid = null;
54
55 private JLabel jLabelVersion = null;
56
57 private JTextField jTextFieldVersion = null;
58
59 private JButton jButtonGenerateGuid = null;
60
61 private JLabel jLabelLicense = null;
62
63 private JTextArea jTextAreaLicense = null;
64
65 private JLabel jLabelCopyright = null;
66
67 private JLabel jLabelDescription = null;
68
69 private JTextArea jTextAreaDescription = null;
70
71 private JLabel jLabelSpecification = null;
72
73 private JTextField jTextFieldSpecification = null;
74
75 private JButton jButtonOk = null;
76
77 private JScrollPane jScrollPaneLicense = null;
78
79 private JScrollPane jScrollPaneDescription = null;
80
81 private JLabel jLabelAbstract = null;
82
83 private JTextField jTextFieldAbstract = null;
84
85 private StarLabel jStarLabel1 = null;
86
87 private StarLabel jStarLabel4 = null;
88
89 private StarLabel jStarLabel5 = null;
90
91 private StarLabel jStarLabel6 = null;
92
93 private StarLabel jStarLabel7 = null;
94
95 private StarLabel jStarLabel8 = null;
96
97 private StarLabel jStarLabel10 = null;
98
99 private StarLabel jStarLabel12 = null;
100
101 private JLabel jLabelURL = null;
102
103 private JTextField jTextFieldURL = null;
104
105 private JScrollPane jScrollPane = null;
106
107 private CreateStepTwo stepTwo = null;
108
109 private JButton jButtonCancel = null;
110
111 private JButton jButtonNext = null;
112
113 private FarHeader farHeader = new FarHeader();
114
115 private JScrollPane jScrollPaneCopyright = null;
116
117 private JTextArea jTextAreaCopyright = null;
118
119 /**
120 * This method initializes jTextFieldBaseName
121 *
122 * @return javax.swing.JTextField jTextFieldBaseName
123 *
124 */
125 private JTextField getJTextFieldBaseName() {
126 if (jTextFieldBaseName == null) {
127 jTextFieldBaseName = new JTextField();
128 jTextFieldBaseName.setBounds(new java.awt.Rectangle(160, 10, 520, 20));
129 jTextFieldBaseName.setToolTipText("A brief Identifier, such as USB I/O Drivers, of the Framework Archive.");
130 }
131 return jTextFieldBaseName;
132 }
133
134 /**
135 * This method initializes jTextFieldGuid
136 *
137 * @return javax.swing.JTextField jTextFieldGuid
138 *
139 */
140 private JTextField getJTextFieldGuid() {
141 if (jTextFieldGuid == null) {
142 jTextFieldGuid = new JTextField();
143 jTextFieldGuid.setBounds(new java.awt.Rectangle(160, 35, 410, 20));
144 jTextFieldGuid.setToolTipText("Guaranteed Unique Identification Number (8-4-4-4-12)");
145 }
146 return jTextFieldGuid;
147 }
148
149 /**
150 * This method initializes jTextFieldVersion
151 *
152 * @return javax.swing.JTextField jTextFieldVersion
153 *
154 */
155 private JTextField getJTextFieldVersion() {
156 if (jTextFieldVersion == null) {
157 jTextFieldVersion = new JTextField();
158 jTextFieldVersion.setBounds(new java.awt.Rectangle(160, 60, 520, 20));
159 jTextFieldVersion.setToolTipText("A Version Number, 1.0, 1, 1.01");
160 }
161 return jTextFieldVersion;
162 }
163
164 /**
165 * This method initializes jButtonGenerateGuid
166 *
167 * @return javax.swing.JButton jButtonGenerateGuid
168 *
169 */
170 private JButton getJButtonGenerateGuid() {
171 if (jButtonGenerateGuid == null) {
172 jButtonGenerateGuid = new JButton();
173 jButtonGenerateGuid.setBounds(new java.awt.Rectangle(590, 35, 90, 20));
174 jButtonGenerateGuid.setText("Generate");
175 jButtonGenerateGuid.addMouseListener(this);
176 }
177 return jButtonGenerateGuid;
178 }
179
180 /**
181 * This method initializes jTextAreaLicense
182 *
183 * @return javax.swing.JTextArea jTextAreaLicense
184 *
185 */
186 private JTextArea getJTextAreaLicense() {
187 if (jTextAreaLicense == null) {
188 jTextAreaLicense = new JTextArea();
189 jTextAreaLicense.setText("");
190 jTextAreaLicense.setLineWrap(true);
191 jTextAreaLicense.setWrapStyleWord(true);
192 jTextAreaLicense.setToolTipText("The License for this FAR file.");
193 }
194 return jTextAreaLicense;
195 }
196
197 /**
198 * This method initializes jTextAreaDescription
199 *
200 * @return javax.swing.JTextArea jTextAreaDescription
201 *
202 */
203 private JTextArea getJTextAreaDescription() {
204 if (jTextAreaDescription == null) {
205 jTextAreaDescription = new JTextArea();
206 jTextAreaDescription.setLineWrap(true);
207 jTextAreaDescription.setWrapStyleWord(true);
208 jTextAreaDescription.setToolTipText("A verbose description of the FAR contents.");
209 }
210 return jTextAreaDescription;
211 }
212
213 /**
214 * This method initializes jTextFieldSpecification
215 *
216 * @return javax.swing.JTextField jTextFieldSpecification
217 *
218 */
219 private JTextField getJTextFieldSpecification() {
220 if (jTextFieldSpecification == null) {
221 jTextFieldSpecification = new JTextField();
222 jTextFieldSpecification.setText("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
223 jTextFieldSpecification.setBounds(new java.awt.Rectangle(160, 310, 520, 20));
224 jTextFieldSpecification.setEditable(false);
225 }
226 return jTextFieldSpecification;
227 }
228
229 /**
230 * This method initializes jScrollPaneLicense
231 *
232 * @return javax.swing.JScrollPane jScrollPaneLicense
233 *
234 */
235 private JScrollPane getJScrollPaneLicense() {
236 if (jScrollPaneLicense == null) {
237 jScrollPaneLicense = new JScrollPane();
238 jScrollPaneLicense.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
239 jScrollPaneLicense.setBounds(new java.awt.Rectangle(160, 220, 520, 60));
240 jScrollPaneLicense.setViewportView(getJTextAreaLicense());
241 }
242 return jScrollPaneLicense;
243 }
244
245 /**
246 * This method initializes jScrollPaneDescription
247 *
248 * @return javax.swing.JScrollPane jScrollPaneDescription
249 *
250 */
251 private JScrollPane getJScrollPaneDescription() {
252 if (jScrollPaneDescription == null) {
253 jScrollPaneDescription = new JScrollPane();
254 jScrollPaneDescription.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
255 jScrollPaneDescription.setBounds(new java.awt.Rectangle(160, 110, 520, 60));
256 jScrollPaneDescription.setViewportView(getJTextAreaDescription());
257 }
258 return jScrollPaneDescription;
259 }
260
261 /**
262 * This method initializes jTextFieldAbstract
263 *
264 * @return javax.swing.JTextField jTextFieldAbstract
265 *
266 */
267 private JTextField getJTextFieldAbstract() {
268 if (jTextFieldAbstract == null) {
269 jTextFieldAbstract = new JTextField();
270 jTextFieldAbstract.setBounds(new java.awt.Rectangle(160, 85, 520, 20));
271 jTextFieldAbstract.setToolTipText("A one sentence description of this FAR package.");
272 }
273 return jTextFieldAbstract;
274 }
275
276 /**
277 * This method initializes jTextFieldURL
278 *
279 * @return javax.swing.JTextField
280 */
281 private JTextField getJTextFieldURL() {
282 if (jTextFieldURL == null) {
283 jTextFieldURL = new JTextField();
284 jTextFieldURL.setBounds(new java.awt.Rectangle(160, 285, 520, 20));
285 jTextFieldURL.setToolTipText("A URL for the latest version of the license");
286 }
287 return jTextFieldURL;
288 }
289
290 /**
291 * This method initializes jScrollPane
292 *
293 * @return javax.swing.JScrollPane
294 */
295 private JScrollPane getJScrollPane() {
296 if (jScrollPane == null) {
297 jScrollPane = new JScrollPane();
298 jScrollPane.setViewportView(getJContentPane());
299 }
300 return jScrollPane;
301 }
302
303 /**
304 * This method initializes jButtonCancel1
305 *
306 * @return javax.swing.JButton
307 */
308 private JButton getJButtonCancel() {
309 if (jButtonCancel == null) {
310 jButtonCancel = new JButton();
311 jButtonCancel.setBounds(new java.awt.Rectangle(590, 350, 90, 20));
312 jButtonCancel.setText("Cancel");
313 jButtonCancel.addMouseListener(this);
314 }
315 return jButtonCancel;
316 }
317
318 /**
319 * This method initializes jButtonNext
320 *
321 * @return javax.swing.JButton
322 */
323 private JButton getJButtonNext() {
324 if (jButtonNext == null) {
325 jButtonNext = new JButton();
326 jButtonNext.setBounds(new java.awt.Rectangle(480, 350, 90, 20));
327 jButtonNext.setText("Next");
328 jButtonNext.addMouseListener(this);
329 }
330 return jButtonNext;
331 }
332
333 /**
334 * This method initializes jScrollPaneCopyright
335 *
336 * @return javax.swing.JScrollPane
337 */
338 private JScrollPane getJScrollPaneCopyright() {
339 if (jScrollPaneCopyright == null) {
340 jScrollPaneCopyright = new JScrollPane();
341 jScrollPaneCopyright.setBounds(new java.awt.Rectangle(160, 175, 520, 40));
342 jScrollPaneCopyright.setViewportView(getJTextAreaCopyright());
343 }
344 return jScrollPaneCopyright;
345 }
346
347 /**
348 * This method initializes jTextAreaCopyright
349 *
350 * @return javax.swing.JTextArea
351 */
352 private JTextArea getJTextAreaCopyright() {
353 if (jTextAreaCopyright == null) {
354 jTextAreaCopyright = new JTextArea();
355 }
356 return jTextAreaCopyright;
357 }
358
359 public static void main(String[] args) {
360 CreateStepOne c = new CreateStepOne(new IFrame(), true);
361 c.setVisible(true);
362 }
363
364 /**
365 * This is the default constructor
366 *
367 */
368 public CreateStepOne(IFrame iFrame, boolean modal) {
369 super(iFrame, modal);
370 initialize();
371 }
372
373 /**
374 * Disable all components when the mode is view
375 *
376 * @param isView
377 * true - The view mode; false - The non-view mode
378 *
379 */
380 public void setViewMode(boolean isView) {
381 if (isView) {
382 this.jTextFieldBaseName.setEnabled(!isView);
383 this.jTextFieldGuid.setEnabled(!isView);
384 this.jTextFieldVersion.setEnabled(!isView);
385 this.jTextAreaLicense.setEnabled(!isView);
386 this.jScrollPaneCopyright.setEnabled(!isView);
387 this.jTextAreaCopyright.setEnabled(!isView);
388 this.jTextAreaDescription.setEnabled(!isView);
389 this.jTextFieldSpecification.setEnabled(!isView);
390 this.jTextFieldAbstract.setEnabled(!isView);
391 this.jButtonGenerateGuid.setEnabled(!isView);
392 this.jButtonOk.setEnabled(!isView);
393 }
394 }
395
396 /**
397 * This method initializes this
398 *
399 */
400 private void initialize() {
401 this.setSize(700, 425);
402 this.setContentPane(getJScrollPane());
403 this.setTitle(FarStringDefinition.CREATE_STEP_ONE_TITLE);
404 this.centerWindow();
405 }
406
407 /**
408 * This method initializes jContentPane
409 *
410 * @return javax.swing.JPanel jContentPane
411 *
412 */
413 private JPanel getJContentPane() {
414 if (jContentPane == null) {
415
416 jLabelURL = new JLabel();
417 jLabelURL.setText("License URL");
418 jLabelURL.setBounds(new java.awt.Rectangle(35, 285, 120, 20));
419 jLabelBaseName = new JLabel();
420 jLabelBaseName.setText("FAR Name");
421 jLabelBaseName.setBounds(new java.awt.Rectangle(35, 10, 120, 20));
422 jLabelGuid = new JLabel();
423 jLabelGuid.setText("Guid Value");
424 jLabelGuid.setBounds(new java.awt.Rectangle(35, 35, 120, 20));
425 jLabelVersion = new JLabel();
426 jLabelVersion.setText("Version");
427 jLabelVersion.setBounds(new java.awt.Rectangle(35, 60, 120, 20));
428 jLabelAbstract = new JLabel();
429 jLabelAbstract.setText("Abstract");
430 jLabelAbstract.setBounds(new java.awt.Rectangle(35, 85, 120, 20));
431 jLabelDescription = new JLabel();
432 jLabelDescription.setText("Description");
433 jLabelDescription.setBounds(new java.awt.Rectangle(35, 110, 120, 20));
434 jLabelCopyright = new JLabel();
435 jLabelCopyright.setText("Copyright");
436 jLabelCopyright.setBounds(new java.awt.Rectangle(35, 175, 120, 20));
437 jLabelLicense = new JLabel();
438 jLabelLicense.setText("License");
439 jLabelLicense.setBounds(new java.awt.Rectangle(35, 220, 120, 20));
440 jLabelSpecification = new JLabel();
441 jLabelSpecification.setText("Specification");
442 jLabelSpecification.setBounds(new java.awt.Rectangle(35, 310, 120, 20));
443
444 jContentPane = new JPanel();
445 jContentPane.setLayout(null);
446
447 jContentPane.add(jLabelBaseName, null);
448 jContentPane.add(getJTextFieldBaseName(), null);
449 jContentPane.add(jLabelGuid, null);
450 jContentPane.add(getJTextFieldGuid(), null);
451 jContentPane.add(jLabelVersion, null);
452 jContentPane.add(getJTextFieldVersion(), null);
453 jContentPane.add(getJButtonGenerateGuid(), null);
454 jContentPane.add(jLabelLicense, null);
455 jContentPane.add(jLabelCopyright, null);
456 jContentPane.add(jLabelDescription, null);
457 jContentPane.add(jLabelSpecification, null);
458 jContentPane.add(getJTextFieldSpecification(), null);
459 jContentPane.add(getJScrollPaneLicense(), null);
460 jContentPane.add(getJScrollPaneDescription(), null);
461 jContentPane.add(jLabelAbstract, null);
462 jContentPane.add(getJTextFieldAbstract(), null);
463 jContentPane.add(jLabelURL, null);
464 jContentPane.add(getJTextFieldURL(), null);
465 jStarLabel1 = new StarLabel();
466 jStarLabel1.setLocation(new java.awt.Point(20, 10));
467 jStarLabel4 = new StarLabel();
468 jStarLabel4.setLocation(new java.awt.Point(20, 35));
469 jStarLabel5 = new StarLabel();
470 jStarLabel5.setLocation(new java.awt.Point(20, 60));
471 jStarLabel6 = new StarLabel();
472 jStarLabel6.setLocation(new java.awt.Point(20, 110));
473 jStarLabel7 = new StarLabel();
474 jStarLabel7.setLocation(new java.awt.Point(20, 175));
475 jStarLabel8 = new StarLabel();
476 jStarLabel8.setLocation(new java.awt.Point(20, 220));
477 jStarLabel10 = new StarLabel();
478 jStarLabel10.setLocation(new java.awt.Point(20, 85));
479 jStarLabel12 = new StarLabel();
480 jStarLabel12.setLocation(new java.awt.Point(20, 310));
481
482 jContentPane.add(jStarLabel1, null);
483 jContentPane.add(jStarLabel4, null);
484 jContentPane.add(jStarLabel5, null);
485 jContentPane.add(jStarLabel6, null);
486 jContentPane.add(jStarLabel7, null);
487 jContentPane.add(jStarLabel8, null);
488 jContentPane.add(jStarLabel10, null);
489 jContentPane.add(jStarLabel12, null);
490 jContentPane.add(getJButtonCancel(), null);
491 jContentPane.add(getJButtonNext(), null);
492 jContentPane.add(getJScrollPaneCopyright(), null);
493 }
494 return jContentPane;
495 }
496
497 public boolean valid() {
498 //
499 // Check BaseName
500 //
501 if (isEmpty(this.jTextFieldBaseName.getText())) {
502 Log.wrn("Create far", "FAR Name must be entered.");
503 return false;
504 }
505 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
506 Log.wrn("Create far", "Incorrect data type for FAR Name");
507 return false;
508 }
509 farHeader.setFarName(this.jTextFieldBaseName.getText());
510
511 //
512 // Check Guid
513 //
514 if (isEmpty(this.jTextFieldGuid.getText())) {
515 Log.wrn("Create far", "A GUID must be entered.");
516 return false;
517 }
518 if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {
519 Log.wrn("Create far", "Incorrect data type for Guid");
520 return false;
521 }
522 farHeader.setGuidValue(this.jTextFieldGuid.getText());
523
524 //
525 // Check Version
526 //
527 if (isEmpty(this.jTextFieldVersion.getText())) {
528 Log.wrn("Create far", "A Version must be entered.");
529 return false;
530 }
531 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
532 Log.wrn("Create far", "Incorrect data type for Version");
533 return false;
534 }
535 farHeader.setVersion(this.jTextFieldVersion.getText());
536
537 //
538 // Check Abstact
539 //
540 if (isEmpty(this.jTextFieldAbstract.getText())) {
541 Log.wrn("Create far", "An Abstract must be entered.");
542 return false;
543 }
544 if (!DataValidation.isAbstract(this.jTextFieldAbstract.getText())) {
545 Log.wrn("Create far", "Incorrect data type for Abstract");
546 return false;
547 }
548 farHeader.setAbstractStr(this.jTextFieldAbstract.getText());
549
550 //
551 // Check Description
552 //
553 if (isEmpty(this.jTextAreaDescription.getText())) {
554 Log.wrn("Create far", "A Description must be entered.");
555 return false;
556 }
557 farHeader.setDescription(this.jTextAreaDescription.getText());
558
559 //
560 // Check Copyright
561 //
562 if (isEmpty(this.jTextAreaCopyright.getText())) {
563 Log.wrn("Create far", "The Copyright must be entered.");
564 return false;
565 }
566 farHeader.setCopyright(this.jTextAreaCopyright.getText());
567
568 //
569 // Check License
570 //
571 if (isEmpty(this.jTextAreaLicense.getText())) {
572 Log.wrn("Create far", "The License must be entered.");
573 return false;
574 }
575 farHeader.setLicense(this.jTextAreaLicense.getText());
576
577 farHeader.setSpecification(this.jTextFieldSpecification.getText());
578 return true;
579 }
580
581 /**
582 * Check the input data is empty or not
583 *
584 * @param strValue
585 * The input data which need be checked
586 *
587 * @retval true - The input data is empty
588 * @retval fals - The input data is not empty
589 *
590 */
591 public boolean isEmpty(String strValue) {
592 if (strValue.length() > 0) {
593 return false;
594 }
595 return true;
596 }
597
598 public void mouseClicked(MouseEvent e) {
599 if (e.getSource() == jButtonCancel) {
600 this.setVisible(false);
601 } else if (e.getSource() == jButtonNext) {
602 //
603 // Add some logic process here
604 //
605 if (!valid()) {
606 return ;
607 }
608 if (stepTwo == null) {
609 stepTwo = new CreateStepTwo(this, true, this);
610 }
611 this.setVisible(false);
612 stepTwo.setVisible(true);
613 } else if (e.getSource() == jButtonGenerateGuid) {
614 this.jTextFieldGuid.setText(Tools.generateUuidString());
615 }
616 }
617
618 public void mousePressed(MouseEvent e) {
619 // TODO Auto-generated method stub
620
621 }
622
623 public void mouseReleased(MouseEvent e) {
624 // TODO Auto-generated method stub
625
626 }
627
628 public void mouseEntered(MouseEvent e) {
629 // TODO Auto-generated method stub
630
631 }
632
633 public void mouseExited(MouseEvent e) {
634 // TODO Auto-generated method stub
635
636 }
637
638 public FarHeader getFarHeader() {
639 return farHeader;
640 }
641 }