32d2da4278a70b23c44ac543a009e45f9a008d16
[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("An brief Identifier, such as USB I/O Library, of the module");
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.setToolTipText("The License for this file");
192 }
193 return jTextAreaLicense;
194 }
195
196 /**
197 * This method initializes jTextAreaDescription
198 *
199 * @return javax.swing.JTextArea jTextAreaDescription
200 *
201 */
202 private JTextArea getJTextAreaDescription() {
203 if (jTextAreaDescription == null) {
204 jTextAreaDescription = new JTextArea();
205 jTextAreaDescription.setLineWrap(true);
206 jTextAreaDescription.setToolTipText("A verbose description of the module");
207 }
208 return jTextAreaDescription;
209 }
210
211 /**
212 * This method initializes jTextFieldSpecification
213 *
214 * @return javax.swing.JTextField jTextFieldSpecification
215 *
216 */
217 private JTextField getJTextFieldSpecification() {
218 if (jTextFieldSpecification == null) {
219 jTextFieldSpecification = new JTextField();
220 jTextFieldSpecification.setText("FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052");
221 jTextFieldSpecification.setBounds(new java.awt.Rectangle(160, 310, 520, 20));
222 jTextFieldSpecification.setEditable(false);
223 }
224 return jTextFieldSpecification;
225 }
226
227 /**
228 * This method initializes jScrollPaneLicense
229 *
230 * @return javax.swing.JScrollPane jScrollPaneLicense
231 *
232 */
233 private JScrollPane getJScrollPaneLicense() {
234 if (jScrollPaneLicense == null) {
235 jScrollPaneLicense = new JScrollPane();
236 jScrollPaneLicense.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
237 jScrollPaneLicense.setBounds(new java.awt.Rectangle(160, 220, 520, 60));
238 jScrollPaneLicense.setViewportView(getJTextAreaLicense());
239 }
240 return jScrollPaneLicense;
241 }
242
243 /**
244 * This method initializes jScrollPaneDescription
245 *
246 * @return javax.swing.JScrollPane jScrollPaneDescription
247 *
248 */
249 private JScrollPane getJScrollPaneDescription() {
250 if (jScrollPaneDescription == null) {
251 jScrollPaneDescription = new JScrollPane();
252 jScrollPaneDescription.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
253 jScrollPaneDescription.setBounds(new java.awt.Rectangle(160, 110, 520, 60));
254 jScrollPaneDescription.setViewportView(getJTextAreaDescription());
255 }
256 return jScrollPaneDescription;
257 }
258
259 /**
260 * This method initializes jTextFieldAbstract
261 *
262 * @return javax.swing.JTextField jTextFieldAbstract
263 *
264 */
265 private JTextField getJTextFieldAbstract() {
266 if (jTextFieldAbstract == null) {
267 jTextFieldAbstract = new JTextField();
268 jTextFieldAbstract.setBounds(new java.awt.Rectangle(160, 85, 520, 20));
269 jTextFieldAbstract.setToolTipText("A one sentence description of this module");
270 }
271 return jTextFieldAbstract;
272 }
273
274 /**
275 * This method initializes jTextFieldURL
276 *
277 * @return javax.swing.JTextField
278 */
279 private JTextField getJTextFieldURL() {
280 if (jTextFieldURL == null) {
281 jTextFieldURL = new JTextField();
282 jTextFieldURL.setBounds(new java.awt.Rectangle(160, 285, 520, 20));
283 jTextFieldURL.setToolTipText("A URL for the latest version of the license");
284 }
285 return jTextFieldURL;
286 }
287
288 /**
289 * This method initializes jScrollPane
290 *
291 * @return javax.swing.JScrollPane
292 */
293 private JScrollPane getJScrollPane() {
294 if (jScrollPane == null) {
295 jScrollPane = new JScrollPane();
296 jScrollPane.setViewportView(getJContentPane());
297 }
298 return jScrollPane;
299 }
300
301 /**
302 * This method initializes jButtonCancel1
303 *
304 * @return javax.swing.JButton
305 */
306 private JButton getJButtonCancel() {
307 if (jButtonCancel == null) {
308 jButtonCancel = new JButton();
309 jButtonCancel.setBounds(new java.awt.Rectangle(590, 350, 90, 20));
310 jButtonCancel.setText("Cancel");
311 jButtonCancel.addMouseListener(this);
312 }
313 return jButtonCancel;
314 }
315
316 /**
317 * This method initializes jButtonNext
318 *
319 * @return javax.swing.JButton
320 */
321 private JButton getJButtonNext() {
322 if (jButtonNext == null) {
323 jButtonNext = new JButton();
324 jButtonNext.setBounds(new java.awt.Rectangle(480, 350, 90, 20));
325 jButtonNext.setText("Next");
326 jButtonNext.addMouseListener(this);
327 }
328 return jButtonNext;
329 }
330
331 /**
332 * This method initializes jScrollPaneCopyright
333 *
334 * @return javax.swing.JScrollPane
335 */
336 private JScrollPane getJScrollPaneCopyright() {
337 if (jScrollPaneCopyright == null) {
338 jScrollPaneCopyright = new JScrollPane();
339 jScrollPaneCopyright.setBounds(new java.awt.Rectangle(160, 175, 520, 40));
340 jScrollPaneCopyright.setViewportView(getJTextAreaCopyright());
341 }
342 return jScrollPaneCopyright;
343 }
344
345 /**
346 * This method initializes jTextAreaCopyright
347 *
348 * @return javax.swing.JTextArea
349 */
350 private JTextArea getJTextAreaCopyright() {
351 if (jTextAreaCopyright == null) {
352 jTextAreaCopyright = new JTextArea();
353 }
354 return jTextAreaCopyright;
355 }
356
357 public static void main(String[] args) {
358 CreateStepOne c = new CreateStepOne(new IFrame(), true);
359 c.setVisible(true);
360 }
361
362 /**
363 * This is the default constructor
364 *
365 */
366 public CreateStepOne(IFrame iFrame, boolean modal) {
367 super(iFrame, modal);
368 initialize();
369 }
370
371 /**
372 * Disable all components when the mode is view
373 *
374 * @param isView
375 * true - The view mode; false - The non-view mode
376 *
377 */
378 public void setViewMode(boolean isView) {
379 if (isView) {
380 this.jTextFieldBaseName.setEnabled(!isView);
381 this.jTextFieldGuid.setEnabled(!isView);
382 this.jTextFieldVersion.setEnabled(!isView);
383 this.jTextAreaLicense.setEnabled(!isView);
384 this.jScrollPaneCopyright.setEnabled(!isView);
385 this.jTextAreaCopyright.setEnabled(!isView);
386 this.jTextAreaDescription.setEnabled(!isView);
387 this.jTextFieldSpecification.setEnabled(!isView);
388 this.jTextFieldAbstract.setEnabled(!isView);
389 this.jButtonGenerateGuid.setEnabled(!isView);
390 this.jButtonOk.setEnabled(!isView);
391 }
392 }
393
394 /**
395 * This method initializes this
396 *
397 */
398 private void initialize() {
399 this.setSize(700, 425);
400 this.setContentPane(getJScrollPane());
401 this.setTitle(FarStringDefinition.CREATE_STEP_ONE_TITLE);
402 this.centerWindow();
403 }
404
405 /**
406 * This method initializes jContentPane
407 *
408 * @return javax.swing.JPanel jContentPane
409 *
410 */
411 private JPanel getJContentPane() {
412 if (jContentPane == null) {
413
414 jLabelURL = new JLabel();
415 jLabelURL.setText("License URL");
416 jLabelURL.setBounds(new java.awt.Rectangle(35, 285, 120, 20));
417 jLabelBaseName = new JLabel();
418 jLabelBaseName.setText("FAR Name");
419 jLabelBaseName.setBounds(new java.awt.Rectangle(35, 10, 120, 20));
420 jLabelGuid = new JLabel();
421 jLabelGuid.setText("Guid Value");
422 jLabelGuid.setBounds(new java.awt.Rectangle(35, 35, 120, 20));
423 jLabelVersion = new JLabel();
424 jLabelVersion.setText("Version");
425 jLabelVersion.setBounds(new java.awt.Rectangle(35, 60, 120, 20));
426 jLabelAbstract = new JLabel();
427 jLabelAbstract.setText("Abstract");
428 jLabelAbstract.setBounds(new java.awt.Rectangle(35, 85, 120, 20));
429 jLabelDescription = new JLabel();
430 jLabelDescription.setText("Description");
431 jLabelDescription.setBounds(new java.awt.Rectangle(35, 110, 120, 20));
432 jLabelCopyright = new JLabel();
433 jLabelCopyright.setText("Copyright");
434 jLabelCopyright.setBounds(new java.awt.Rectangle(35, 175, 120, 20));
435 jLabelLicense = new JLabel();
436 jLabelLicense.setText("License");
437 jLabelLicense.setBounds(new java.awt.Rectangle(35, 220, 120, 20));
438 jLabelSpecification = new JLabel();
439 jLabelSpecification.setText("Specification");
440 jLabelSpecification.setBounds(new java.awt.Rectangle(35, 310, 120, 20));
441
442 jContentPane = new JPanel();
443 jContentPane.setLayout(null);
444
445 jContentPane.add(jLabelBaseName, null);
446 jContentPane.add(getJTextFieldBaseName(), null);
447 jContentPane.add(jLabelGuid, null);
448 jContentPane.add(getJTextFieldGuid(), null);
449 jContentPane.add(jLabelVersion, null);
450 jContentPane.add(getJTextFieldVersion(), null);
451 jContentPane.add(getJButtonGenerateGuid(), null);
452 jContentPane.add(jLabelLicense, null);
453 jContentPane.add(jLabelCopyright, null);
454 jContentPane.add(jLabelDescription, null);
455 jContentPane.add(jLabelSpecification, null);
456 jContentPane.add(getJTextFieldSpecification(), null);
457 jContentPane.add(getJScrollPaneLicense(), null);
458 jContentPane.add(getJScrollPaneDescription(), null);
459 jContentPane.add(jLabelAbstract, null);
460 jContentPane.add(getJTextFieldAbstract(), null);
461 jContentPane.add(jLabelURL, null);
462 jContentPane.add(getJTextFieldURL(), null);
463 jStarLabel1 = new StarLabel();
464 jStarLabel1.setLocation(new java.awt.Point(20, 10));
465 jStarLabel4 = new StarLabel();
466 jStarLabel4.setLocation(new java.awt.Point(20, 35));
467 jStarLabel5 = new StarLabel();
468 jStarLabel5.setLocation(new java.awt.Point(20, 60));
469 jStarLabel6 = new StarLabel();
470 jStarLabel6.setLocation(new java.awt.Point(20, 110));
471 jStarLabel7 = new StarLabel();
472 jStarLabel7.setLocation(new java.awt.Point(20, 175));
473 jStarLabel8 = new StarLabel();
474 jStarLabel8.setLocation(new java.awt.Point(20, 220));
475 jStarLabel10 = new StarLabel();
476 jStarLabel10.setLocation(new java.awt.Point(20, 85));
477 jStarLabel12 = new StarLabel();
478 jStarLabel12.setLocation(new java.awt.Point(20, 310));
479
480 jContentPane.add(jStarLabel1, null);
481 jContentPane.add(jStarLabel4, null);
482 jContentPane.add(jStarLabel5, null);
483 jContentPane.add(jStarLabel6, null);
484 jContentPane.add(jStarLabel7, null);
485 jContentPane.add(jStarLabel8, null);
486 jContentPane.add(jStarLabel10, null);
487 jContentPane.add(jStarLabel12, null);
488 jContentPane.add(getJButtonCancel(), null);
489 jContentPane.add(getJButtonNext(), null);
490 jContentPane.add(getJScrollPaneCopyright(), null);
491 }
492 return jContentPane;
493 }
494
495 public boolean valid() {
496 //
497 // Check BaseName
498 //
499 if (isEmpty(this.jTextFieldBaseName.getText())) {
500 Log.wrn("Create far", "Base Name couldn't be empty");
501 return false;
502 }
503 if (!DataValidation.isBaseName(this.jTextFieldBaseName.getText())) {
504 Log.wrn("Create far", "Incorrect data type for Base Name");
505 return false;
506 }
507 farHeader.setFarName(this.jTextFieldBaseName.getText());
508
509 //
510 // Check Guid
511 //
512 if (isEmpty(this.jTextFieldGuid.getText())) {
513 Log.wrn("Create far", "Guid Value couldn't be empty");
514 return false;
515 }
516 if (!DataValidation.isGuid((this.jTextFieldGuid).getText())) {
517 Log.wrn("Create far", "Incorrect data type for Guid");
518 return false;
519 }
520 farHeader.setGuidValue(this.jTextFieldGuid.getText());
521
522 //
523 // Check Version
524 //
525 if (isEmpty(this.jTextFieldVersion.getText())) {
526 Log.wrn("Create far", "Version couldn't be empty");
527 return false;
528 }
529 if (!DataValidation.isVersion(this.jTextFieldVersion.getText())) {
530 Log.wrn("Create far", "Incorrect data type for Version");
531 return false;
532 }
533 farHeader.setVersion(this.jTextFieldVersion.getText());
534
535 //
536 // Check Abstact
537 //
538 if (isEmpty(this.jTextFieldAbstract.getText())) {
539 Log.wrn("Create far", "Abstract couldn't be empty");
540 return false;
541 }
542 if (!DataValidation.isAbstract(this.jTextFieldAbstract.getText())) {
543 Log.wrn("Create far", "Incorrect data type for Abstract");
544 return false;
545 }
546 farHeader.setAbstractStr(this.jTextFieldAbstract.getText());
547
548 //
549 // Check Description
550 //
551 if (isEmpty(this.jTextAreaDescription.getText())) {
552 Log.wrn("Create far", "Description couldn't be empty");
553 return false;
554 }
555 farHeader.setDescription(this.jTextAreaDescription.getText());
556
557 //
558 // Check Copyright
559 //
560 if (isEmpty(this.jTextAreaCopyright.getText())) {
561 Log.wrn("Create far", "Copyright couldn't be empty");
562 return false;
563 }
564 farHeader.setCopyright(this.jTextAreaCopyright.getText());
565
566 //
567 // Check License
568 //
569 if (isEmpty(this.jTextAreaLicense.getText())) {
570 Log.wrn("Create far", "License couldn't be empty");
571 return false;
572 }
573 farHeader.setLicense(this.jTextAreaLicense.getText());
574
575 farHeader.setSpecification(this.jTextFieldSpecification.getText());
576 return true;
577 }
578
579 /**
580 * Check the input data is empty or not
581 *
582 * @param strValue
583 * The input data which need be checked
584 *
585 * @retval true - The input data is empty
586 * @retval fals - The input data is not empty
587 *
588 */
589 public boolean isEmpty(String strValue) {
590 if (strValue.length() > 0) {
591 return false;
592 }
593 return true;
594 }
595
596 public void mouseClicked(MouseEvent e) {
597 if (e.getSource() == jButtonCancel) {
598 this.setVisible(false);
599 } else if (e.getSource() == jButtonNext) {
600 //
601 // Add some logic process here
602 //
603 if (!valid()) {
604 return ;
605 }
606 if (stepTwo == null) {
607 stepTwo = new CreateStepTwo(this, true, this);
608 }
609 this.setVisible(false);
610 stepTwo.setVisible(true);
611 } else if (e.getSource() == jButtonGenerateGuid) {
612 this.jTextFieldGuid.setText(Tools.generateUuidString());
613 }
614 }
615
616 public void mousePressed(MouseEvent e) {
617 // TODO Auto-generated method stub
618
619 }
620
621 public void mouseReleased(MouseEvent e) {
622 // TODO Auto-generated method stub
623
624 }
625
626 public void mouseEntered(MouseEvent e) {
627 // TODO Auto-generated method stub
628
629 }
630
631 public void mouseExited(MouseEvent e) {
632 // TODO Auto-generated method stub
633
634 }
635
636 public FarHeader getFarHeader() {
637 return farHeader;
638 }
639 }