2 Java class GenGuidDialog.
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.packaging
;
15 import java
.awt
.BorderLayout
;
16 import java
.awt
.Dimension
;
17 import java
.awt
.Toolkit
;
19 import javax
.swing
.JPanel
;
20 import javax
.swing
.JDialog
;
21 import java
.awt
.GridLayout
;
23 import javax
.swing
.JFrame
;
24 import javax
.swing
.JOptionPane
;
25 import javax
.swing
.JTextField
;
26 import javax
.swing
.JLabel
;
27 import javax
.swing
.JRadioButton
;
28 import javax
.swing
.ButtonGroup
;
29 import javax
.swing
.JButton
;
31 import org
.tianocore
.common
.Tools
;
33 import java
.awt
.FlowLayout
;
34 import java
.awt
.event
.ActionEvent
;
35 import java
.awt
.event
.ActionListener
;
36 import java
.awt
.event
.WindowAdapter
;
37 import java
.awt
.event
.WindowEvent
;
40 Dialog for GUID generation.
41 @since PackageEditor 1.0
43 public class GenGuidDialog
extends JDialog
implements ActionListener
{
45 static private JFrame frame
;
46 private JPanel jContentPane
= null;
47 private JPanel jPanel
= null;
48 private JPanel jPanel1
= null;
49 private JPanel jPanel2
= null;
50 private JPanel jPanel3
= null;
51 private JPanel jPanel4
= null;
52 private JTextField jTextField
= null;
53 private JLabel jLabel
= null;
54 private JRadioButton jRadioButton
= null;
55 private JRadioButton jRadioButton1
= null;
56 private JButton jButton
= null;
57 private JButton jButton1
= null;
58 private JButton jButton2
= null;
60 // private String guid = null;
62 public void actionPerformed(ActionEvent arg0
) {
63 // TODO Auto-generated method stub
64 if (arg0
.getSource() == jButton1
){
65 String uuid
= Tools
.generateUuidString();
66 if (jRadioButton1
.isSelected()) {
67 jTextField
.setText(uuid
);
70 //ToDo: transform to comma-sep guid
71 String s
= Tools
.formatGuidString(uuid
);
73 JOptionPane
.showMessageDialog(frame
, "Check GUID Value, it don't conform to the schema.");
76 jTextField
.setText(s
);
80 if (arg0
.getSource() == jRadioButton1
){
82 //ToDo: check text field value against RegExp and transform if needed
83 if (jTextField
.getText().matches(Tools
.guidRegistryPat
)){
86 if (jTextField
.getText().matches(Tools
.guidArrayPat
)) {
87 jTextField
.setText(Tools
.formatGuidString(jTextField
.getText()));
91 JOptionPane
.showMessageDialog(frame
, "Check GUID Value, it don't conform to the schema.");
95 if (arg0
.getSource() == jRadioButton
){
97 //ToDo: check text field value against RegExp and transform if needed
98 if (jTextField
.getText().matches(Tools
.guidArrayPat
)){
101 if (jTextField
.getText().matches(Tools
.guidRegistryPat
)) {
102 jTextField
.setText(Tools
.formatGuidString(jTextField
.getText()));
106 JOptionPane
.showMessageDialog(frame
, "Check GUID Value, it don't conform to the schema.");
110 if (arg0
.getSource() == jButton2
){
111 // if (jTextField.getText().matches(Tools.guidArrayPat)
112 // || jTextField.getText().matches(Tools.guidRegistryPat)){
113 // this.setVisible(false);
116 // JOptionPane.showMessageDialog(frame, "Incorrect GUID Value Format.");
121 if (arg0
.getSource() == jButton
){
127 * This method initializes jPanel
129 * @return javax.swing.JPanel
131 private JPanel
getJPanel() {
132 if (jPanel
== null) {
133 FlowLayout flowLayout
= new FlowLayout();
134 flowLayout
.setVgap(10);
135 jPanel
= new JPanel();
136 jPanel
.setLayout(flowLayout
);
137 jPanel
.setPreferredSize(new java
.awt
.Dimension(100,30));
138 jPanel
.add(getJButton1(), null);
139 jPanel
.add(getJButton2(), null);
140 jPanel
.add(getJButton(), null);
146 * This method initializes jPanel1
148 * @return javax.swing.JPanel
150 private JPanel
getJPanel1() {
151 if (jPanel1
== null) {
152 jPanel1
= new JPanel();
158 * This method initializes jPanel2
160 * @return javax.swing.JPanel
162 private JPanel
getJPanel2() {
163 if (jPanel2
== null) {
164 jPanel2
= new JPanel();
170 * This method initializes jPanel3
172 * @return javax.swing.JPanel
174 private JPanel
getJPanel3() {
175 if (jPanel3
== null) {
176 jPanel3
= new JPanel();
182 * This method initializes jPanel4
184 * @return javax.swing.JPanel
186 private JPanel
getJPanel4() {
187 if (jPanel4
== null) {
188 jLabel
= new JLabel();
189 jLabel
.setText("GUID Value");
190 GridLayout gridLayout
= new GridLayout();
191 gridLayout
.setRows(4);
192 jPanel4
= new JPanel();
193 jPanel4
.setLayout(gridLayout
);
194 jPanel4
.add(getJRadioButton1(), null);
195 jPanel4
.add(getJRadioButton(), null);
196 jPanel4
.add(jLabel
, null);
197 jPanel4
.add(getJTextField(), null);
198 ButtonGroup bg
= new ButtonGroup();
199 bg
.add(jRadioButton1
);
200 bg
.add(jRadioButton
);
206 * This method initializes jTextField
208 * @return javax.swing.JTextField
210 private JTextField
getJTextField() {
211 if (jTextField
== null) {
212 jTextField
= new JTextField();
213 jTextField
.setHorizontalAlignment(JTextField
.LEADING
);
214 jTextField
.setPreferredSize(new java
.awt
.Dimension(100,20));
220 * This method initializes jRadioButton
222 * @return javax.swing.JRadioButton
224 private JRadioButton
getJRadioButton() {
225 if (jRadioButton
== null) {
226 jRadioButton
= new JRadioButton();
227 jRadioButton
.setText("Comma-Seperated Format");
228 jRadioButton
.addActionListener(this);
234 * This method initializes jRadioButton1
236 * @return javax.swing.JRadioButton
238 private JRadioButton
getJRadioButton1() {
239 if (jRadioButton1
== null) {
240 jRadioButton1
= new JRadioButton();
241 jRadioButton1
.setText("Registry Format");
242 jRadioButton1
.setSelected(true);
243 jRadioButton1
.addActionListener(this);
245 return jRadioButton1
;
249 * This method initializes jButton
251 * @return javax.swing.JButton
253 private JButton
getJButton() {
254 if (jButton
== null) {
255 jButton
= new JButton();
256 jButton
.setPreferredSize(new java
.awt
.Dimension(80,20));
257 jButton
.setText("Cancel");
258 jButton
.addActionListener(this);
264 * This method initializes jButton1
266 * @return javax.swing.JButton
268 private JButton
getJButton1() {
269 if (jButton1
== null) {
270 jButton1
= new JButton();
271 jButton1
.setPreferredSize(new java
.awt
.Dimension(80,20));
272 jButton1
.setHorizontalTextPosition(javax
.swing
.SwingConstants
.LEADING
);
273 jButton1
.setText("New");
274 jButton1
.addActionListener(this);
280 * This method initializes jButton2
282 * @return javax.swing.JButton
284 private JButton
getJButton2() {
285 if (jButton2
== null) {
286 jButton2
= new JButton();
287 jButton2
.setPreferredSize(new java
.awt
.Dimension(80,20));
288 jButton2
.setText("Ok");
289 jButton2
.addActionListener(this);
298 public static void main(String
[] args
) {
299 // TODO Auto-generated method stub
300 new GenGuidDialog().setVisible(true);
303 public String
getGuid(){
304 return jTextField
.getText();
307 public void setGuid(String s
){
308 jTextField
.setText(s
);
311 * This is the default constructor
313 public GenGuidDialog() {
318 public GenGuidDialog(ActionListener i
){
321 jButton2
.addActionListener(i
);
322 this.addWindowListener(new WindowAdapter(){
325 public void windowActivated(WindowEvent arg0
) {
326 // TODO Auto-generated method stub
327 super.windowActivated(arg0
);
328 if ((jRadioButton1
.isSelected() && jTextField
.getText().matches(Tools
.guidArrayPat
))
329 || (jRadioButton
.isSelected() && jTextField
.getText().matches(Tools
.guidRegistryPat
))) {
330 jTextField
.setText(Tools
.formatGuidString(jTextField
.getText()));
333 // if (!jTextField.getText().matches(Tools.guidArrayPat) || !jTextField.getText().matches(Tools.guidRegistryPat)) {
334 // JOptionPane.showMessageDialog(frame, "InitVal: Incorrect GUID Value Format.");
343 * This method initializes this
347 private void initialize() {
348 this.setSize(466, 157);
349 this.setDefaultCloseOperation(javax
.swing
.WindowConstants
.DISPOSE_ON_CLOSE
);
351 this.setTitle("Editing GUID Value");
352 this.setContentPane(getJContentPane());
357 * This method initializes jContentPane
359 * @return javax.swing.JPanel
361 private JPanel
getJContentPane() {
362 if (jContentPane
== null) {
363 jContentPane
= new JPanel();
364 jContentPane
.setLayout(new BorderLayout());
365 jContentPane
.add(getJPanel(), java
.awt
.BorderLayout
.EAST
);
366 jContentPane
.add(getJPanel1(), java
.awt
.BorderLayout
.WEST
);
367 jContentPane
.add(getJPanel2(), java
.awt
.BorderLayout
.NORTH
);
368 jContentPane
.add(getJPanel3(), java
.awt
.BorderLayout
.SOUTH
);
369 jContentPane
.add(getJPanel4(), java
.awt
.BorderLayout
.CENTER
);
375 Start the window at the center of screen
378 protected void centerWindow(int intWidth
, int intHeight
) {
379 Dimension d
= Toolkit
.getDefaultToolkit().getScreenSize();
380 this.setLocation((d
.width
- intWidth
) / 2, (d
.height
- intHeight
) / 2);
384 Start the window at the center of screen
387 protected void centerWindow() {
388 centerWindow(this.getSize().width
, this.getSize().height
);
391 } // @jve:decl-index=0:visual-constraint="10,10"