01: package net.ar.webonswing.tutorial;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import javax.swing.*;
07:
08: import net.ar.webonswing.*;
09: import net.ar.webonswing.swing.components.validators.*;
10:
11: public class UserDetails extends JDialog {
12: protected User user;
13:
14: public UserDetails() {
15: this (new User());
16: }
17:
18: public UserDetails(User aUser) {
19: user = aUser;
20:
21: final JTextField firstNameField = new JTextField(user
22: .getFirstName());
23: final JTextField lastNameField = new JTextField(user
24: .getLastName());
25: final JTextField emailField = new JTextField(user.getEmail());
26:
27: final JGroupValidator groupValidator = new JGroupValidator(
28: "Please fix the following errors:", true);
29: JValidator validator1 = groupValidator
30: .addValidator(new JRequiredFieldValidator(
31: firstNameField, "*", "Enter the first name",
32: true));
33: JValidator validator2 = groupValidator
34: .addValidator(new JRangeValidator(lastNameField, "*",
35: "First and last name are equal!", true, "245",
36: "247", JCompareValidator.Type.STRING));
37: JValidator validator3 = groupValidator
38: .addValidator(new JRegularExpressionValidator(
39: emailField, "*", "Enter a valid email address",
40: true,
41: "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"));
42:
43: JButton saveButton = new JButton("save");
44: saveButton.addActionListener(new ActionListener() {
45: public void actionPerformed(ActionEvent e) {
46: if (groupValidator.doValidation()) {
47: user.setFirstName(firstNameField.getText());
48: user.setLastName(lastNameField.getText());
49: user.setLastName(lastNameField.getText());
50: WosFramework.hide(UserDetails.this );
51: }
52: }
53: });
54:
55: JPanel contentPane = new JPanel(new GridLayout(4, 2));
56: contentPane.add(firstNameField);
57: contentPane.add(validator1);
58: contentPane.add(lastNameField);
59: contentPane.add(validator2);
60: contentPane.add(emailField);
61: contentPane.add(validator3);
62: contentPane.add(saveButton);
63: contentPane.add(groupValidator);
64:
65: /*
66: * for (int i= 0; i < 60; i++) { JButton button= new JButton(i + "");
67: * contentPane.add(button); }
68: */
69: setContentPane(contentPane);
70:
71: firstNameField.setName("firstName");
72: lastNameField.setName("lastName");
73: emailField.setName("email");
74: validator1.setName("validator1");
75: validator2.setName("validator2");
76: validator3.setName("validator3");
77: saveButton.setName("saveButton");
78: groupValidator.setName("groupValidator");
79: contentPane.setName("contentPane");
80:
81: WosFramework.assignContributor(this ,
82: UserDetailsContributor.class);
83:
84: if (WosFramework.isActive())
85: contentPane
86: .setLayout(WosFramework
87: .getPropagateTemplateLayoutByNameFor("UserDetails"));
88:
89: }
90:
91: public User getUser() {
92: return user;
93: }
94:
95: public void setUser(User aUser) {
96: user = aUser;
97: }
98: }
|