KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > account > AddUserDialog


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: AddUserDialog.java,v 1.1 2003/11/09 15:47:32 per_nyfelt Exp $
8
package org.ozoneDB.adminGui.feature.account;
9
10 import org.ozoneDB.adminGui.main.AdminGui;
11 import org.ozoneDB.adminGui.res.Settings;
12 import org.ozoneDB.adminGui.widget.QuickButton;
13 import org.ozoneDB.adminGui.widget.QuickLabel;
14 import org.ozoneDB.adminGui.widget.MessageBox;
15 import org.ozoneDB.core.User;
16
17 import javax.swing.*;
18 import java.awt.*;
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.ActionListener JavaDoc;
21
22 /**
23  * Prompts for username and id so that a a new account can be created
24  */

25 public class AddUserDialog extends JDialog {
26
27     private static final Dimension DIALOG_SIZE = new Dimension(400, 200);
28
29     private JTextField userNameField;
30     private JTextField userIdField;
31     private boolean inputOK = false;
32
33     public AddUserDialog(Frame owner, String JavaDoc title) {
34         super(owner, title, true);
35
36         userNameField = new JTextField(10);
37         userNameField.setBackground(Color.WHITE);
38         userIdField = new JTextField(10);
39         userIdField.setBackground(Color.WHITE);
40
41         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
42         doGUILayout();
43         setVisible(true);
44     }
45
46     private void doGUILayout() {
47
48         setSize(DIALOG_SIZE);
49         setLocationRelativeTo(null);
50         setResizable(false);
51
52         getContentPane().add(createContentPanel(), BorderLayout.CENTER);
53         getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
54     }
55
56     private JPanel createContentPanel() {
57
58         JPanel panel = new JPanel(new GridBagLayout());
59         panel.setBorder(BorderFactory.createLoweredBevelBorder());
60         panel.setBackground(Color.WHITE);
61
62         GridBagConstraints gbc = new GridBagConstraints();
63
64         gbc.weightx = 1.0d;
65         gbc.weighty = 1.0d;
66         gbc.insets = new Insets(0, 10, 0, 10);
67
68         gbc.anchor = GridBagConstraints.EAST;
69
70         gbc.gridy = 0;
71         gbc.gridx = 0;
72         panel.add(new QuickLabel("User name", Settings.COLOR_COBALT), gbc);
73
74         gbc.anchor = GridBagConstraints.WEST;
75         gbc.gridx++;
76         panel.add(userNameField, gbc);
77
78         gbc.anchor = GridBagConstraints.EAST;
79         gbc.gridy++;
80         gbc.gridx = 0;
81         panel.add(new QuickLabel("User Id", Settings.COLOR_COBALT), gbc);
82
83         gbc.anchor = GridBagConstraints.WEST;
84         gbc.gridx++;
85         panel.add(userIdField, gbc);
86
87         return panel;
88     }
89
90     private JPanel createButtonPanel() {
91         JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
92
93         QuickButton ok = new QuickButton("OK", new OKListener());
94         ok.setBackground(Color.WHITE);
95         panel.add(ok);
96
97         QuickButton close = new QuickButton("Close", new CloseListener());
98         close.setBackground(Color.WHITE);
99         panel.add(close);
100
101         return panel;
102     }
103
104     public boolean isInputOK() {
105         return inputOK;
106     }
107
108     public String JavaDoc getUserName() {
109         return userNameField.getText();
110     }
111
112     public int getUserId() {
113         return Integer.parseInt(userIdField.getText());
114     }
115
116     class OKListener implements ActionListener JavaDoc {
117         public void actionPerformed(ActionEvent JavaDoc ae) {
118             try {
119                 User user = AdminGui.instance().getAdmin().userForName(getUserName());
120                 if (user == null) {
121                     inputOK = true;
122                     AddUserDialog.this.hide();
123                 } else {
124                     inputOK = false;
125                     MessageBox.showInfo("User exists", "User " + getUserName() + " already exist");
126                 }
127             } catch (Exception JavaDoc e) {
128                 inputOK = false;
129                 MessageBox.showError("Failed to check for existing account", e.toString());
130             }
131         }
132     }
133
134     class CloseListener implements ActionListener JavaDoc {
135         public void actionPerformed(ActionEvent JavaDoc ae) {
136             inputOK = false;
137             AddUserDialog.this.hide();
138         }
139     }
140
141 }
142
143
Popular Tags