]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/PackageEditor/src/org/tianocore/packaging/GenGuidDialog.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@671 6f19259b...
[mirror_edk2.git] / Tools / Source / PackageEditor / src / org / tianocore / packaging / GenGuidDialog.java
1 /** @file
2 Java class GenGuidDialog.
3
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
9
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.
12 **/
13 package org.tianocore.packaging;
14
15 import java.awt.BorderLayout;
16 import java.awt.Dimension;
17 import java.awt.Toolkit;
18
19 import javax.swing.JPanel;
20 import javax.swing.JDialog;
21 import java.awt.GridLayout;
22
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;
30
31 import org.tianocore.common.Tools;
32
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;
38
39 /**
40 Dialog for GUID generation.
41 @since PackageEditor 1.0
42 **/
43 public class GenGuidDialog extends JDialog implements ActionListener{
44
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;
59
60 // private String guid = null;
61
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);
68 }
69 else {
70 //ToDo: transform to comma-sep guid
71 String s = Tools.formatGuidString(uuid);
72 if (s.equals("0")) {
73 JOptionPane.showMessageDialog(frame, "Check GUID Value, it don't conform to the schema.");
74 return;
75 }
76 jTextField.setText(s);
77 }
78 }
79
80 if (arg0.getSource() == jRadioButton1){
81
82 //ToDo: check text field value against RegExp and transform if needed
83 if (jTextField.getText().matches(Tools.guidRegistryPat)){
84 return;
85 }
86 if (jTextField.getText().matches(Tools.guidArrayPat)) {
87 jTextField.setText(Tools.formatGuidString(jTextField.getText()));
88 return;
89 }
90
91 JOptionPane.showMessageDialog(frame, "Check GUID Value, it don't conform to the schema.");
92
93 }
94
95 if (arg0.getSource() == jRadioButton){
96
97 //ToDo: check text field value against RegExp and transform if needed
98 if (jTextField.getText().matches(Tools.guidArrayPat)){
99 return;
100 }
101 if (jTextField.getText().matches(Tools.guidRegistryPat)) {
102 jTextField.setText(Tools.formatGuidString(jTextField.getText()));
103 return;
104 }
105
106 JOptionPane.showMessageDialog(frame, "Check GUID Value, it don't conform to the schema.");
107
108 }
109
110 if (arg0.getSource() == jButton2){
111 // if (jTextField.getText().matches(Tools.guidArrayPat)
112 // || jTextField.getText().matches(Tools.guidRegistryPat)){
113 // this.setVisible(false);
114 // }
115 // else {
116 // JOptionPane.showMessageDialog(frame, "Incorrect GUID Value Format.");
117 // }
118 this.dispose();
119 }
120
121 if (arg0.getSource() == jButton){
122 this.dispose();
123 }
124 }
125
126 /**
127 * This method initializes jPanel
128 *
129 * @return javax.swing.JPanel
130 */
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);
141 }
142 return jPanel;
143 }
144
145 /**
146 * This method initializes jPanel1
147 *
148 * @return javax.swing.JPanel
149 */
150 private JPanel getJPanel1() {
151 if (jPanel1 == null) {
152 jPanel1 = new JPanel();
153 }
154 return jPanel1;
155 }
156
157 /**
158 * This method initializes jPanel2
159 *
160 * @return javax.swing.JPanel
161 */
162 private JPanel getJPanel2() {
163 if (jPanel2 == null) {
164 jPanel2 = new JPanel();
165 }
166 return jPanel2;
167 }
168
169 /**
170 * This method initializes jPanel3
171 *
172 * @return javax.swing.JPanel
173 */
174 private JPanel getJPanel3() {
175 if (jPanel3 == null) {
176 jPanel3 = new JPanel();
177 }
178 return jPanel3;
179 }
180
181 /**
182 * This method initializes jPanel4
183 *
184 * @return javax.swing.JPanel
185 */
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);
201 }
202 return jPanel4;
203 }
204
205 /**
206 * This method initializes jTextField
207 *
208 * @return javax.swing.JTextField
209 */
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));
215 }
216 return jTextField;
217 }
218
219 /**
220 * This method initializes jRadioButton
221 *
222 * @return javax.swing.JRadioButton
223 */
224 private JRadioButton getJRadioButton() {
225 if (jRadioButton == null) {
226 jRadioButton = new JRadioButton();
227 jRadioButton.setText("Comma-Seperated Format");
228 jRadioButton.addActionListener(this);
229 }
230 return jRadioButton;
231 }
232
233 /**
234 * This method initializes jRadioButton1
235 *
236 * @return javax.swing.JRadioButton
237 */
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);
244 }
245 return jRadioButton1;
246 }
247
248 /**
249 * This method initializes jButton
250 *
251 * @return javax.swing.JButton
252 */
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);
259 }
260 return jButton;
261 }
262
263 /**
264 * This method initializes jButton1
265 *
266 * @return javax.swing.JButton
267 */
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);
275 }
276 return jButton1;
277 }
278
279 /**
280 * This method initializes jButton2
281 *
282 * @return javax.swing.JButton
283 */
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);
290 }
291 return jButton2;
292 }
293
294 /**
295
296 @param args
297 **/
298 public static void main(String[] args) {
299 // TODO Auto-generated method stub
300 new GenGuidDialog().setVisible(true);
301 }
302
303 public String getGuid(){
304 return jTextField.getText();
305 }
306
307 public void setGuid(String s){
308 jTextField.setText(s);
309 }
310 /**
311 * This is the default constructor
312 */
313 public GenGuidDialog() {
314 super();
315 initialize();
316 }
317
318 public GenGuidDialog(ActionListener i){
319 super();
320 initialize();
321 jButton2.addActionListener(i);
322 this.addWindowListener(new WindowAdapter(){
323
324 @Override
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()));
331 }
332
333 // if (!jTextField.getText().matches(Tools.guidArrayPat) || !jTextField.getText().matches(Tools.guidRegistryPat)) {
334 // JOptionPane.showMessageDialog(frame, "InitVal: Incorrect GUID Value Format.");
335 // return;
336 // }
337 }
338
339 });
340 }
341
342 /**
343 * This method initializes this
344 *
345 * @return void
346 */
347 private void initialize() {
348 this.setSize(466, 157);
349 this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
350 this.setModal(true);
351 this.setTitle("Editing GUID Value");
352 this.setContentPane(getJContentPane());
353 this.centerWindow();
354 }
355
356 /**
357 * This method initializes jContentPane
358 *
359 * @return javax.swing.JPanel
360 */
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);
370 }
371 return jContentPane;
372 }
373
374 /**
375 Start the window at the center of screen
376
377 **/
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);
381 }
382
383 /**
384 Start the window at the center of screen
385
386 **/
387 protected void centerWindow() {
388 centerWindow(this.getSize().width, this.getSize().height);
389 }
390
391 } // @jve:decl-index=0:visual-constraint="10,10"