KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > account > users > WorkUserDialog


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
package org.ozoneDB.adminGui.feature.account.users;
8
9 import java.awt.BorderLayout JavaDoc;
10 import javax.swing.JDialog JavaDoc;
11
12 import org.ozoneDB.adminGui.widget.ButtonPanel;
13 import org.ozoneDB.adminGui.widget.ButtonPanelListener;
14 import org.ozoneDB.adminGui.main.AdminGui;
15
16
17 //#############################################################################
18
/**
19  * This class gets a new account name to be created.
20  *
21  * @author <p align=center>Ibsen Ramos-Bonilla
22  * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
23  *
24  * @version 1.0
25  */

26 //#############################################################################
27

28 public class WorkUserDialog extends JDialog JavaDoc implements ButtonPanelListener {
29
30     /** Handle to the parent UserAccount object. */
31     private UserAccount parent = null;
32     /** Panel used to get the account name and password. */
33     private WorkUserPanel userPane = null;
34     /** List of buttons for the button panel. */
35     private String JavaDoc[] button = {"OK", "Cancel"};
36     /** Flag to monitor if the ok buttons was clicked. */
37     private boolean ok = false;
38     /** The account name. */
39     private String JavaDoc name = "";
40     /** The account password. */
41     private String JavaDoc password = "";
42
43
44     /**
45      * Constructor creates the add account dialog.
46      */

47     public WorkUserDialog(UserAccount parent) {
48         super(AdminGui.instance(), "Create User", true);
49         this.parent = parent;
50
51         try {
52             init();
53             this.setSize(300, 200);
54         } catch (Exception JavaDoc e) {
55             e.printStackTrace();
56         }
57     }
58
59     /**
60      * This method initializes the dialog.
61      */

62     private void init() throws Exception JavaDoc {
63         //set dialog attributes
64
this.setResizable(false);
65         this.setLocationRelativeTo(AdminGui.instance());
66         this.getContentPane().setLayout(new BorderLayout JavaDoc());
67
68         //create panels
69
userPane = new WorkUserPanel();
70
71         ButtonPanel buttonPane = new ButtonPanel(this.button);
72         buttonPane.addConnectionListener(this);
73
74         //add the dialog components
75
this.getContentPane().add(userPane, BorderLayout.CENTER);
76         this.getContentPane().add(buttonPane, BorderLayout.SOUTH);
77     }
78
79     /**
80      * This method handles the button clicks..
81      *
82      * @param buttonName - name of the button pressed.
83      */

84     public void buttonExecute(String JavaDoc buttonName) {
85         //ok
86
if (button[0].equals(buttonName))
87             collectUserInfo();
88
89         //cancel
90
else
91             this.hide();
92     }
93
94     /**
95      * This method is called when the ok button is clicked.
96      */

97     private void collectUserInfo() {
98         this.name = this.userPane.getUserName().trim();
99         this.password = this.userPane.getUserPassword().trim();
100
101         //verify that we have a valid entry
102
if (this.name.equals("") | this.name == null)
103             this.ok = false;
104         else {
105             this.ok = true;
106
107             //check password
108
if (this.password.equals("") | this.password == null)
109                 this.password = name;
110         }
111
112         this.hide();
113     }
114
115     /**
116      * This method returns the account name.
117      *
118      * @return String - the new account name.
119      */

120     public String JavaDoc getName() {
121         return this.name;
122     }
123
124     /**
125      * This method returns the account password.
126      *
127      * @return String - the new account password.
128      */

129     public String JavaDoc getPassword() {
130         return this.password;
131     }
132
133     /**
134      * This method denotes if the ok button was pushed.
135      *
136      * @return boolean - TRUE = OK button pushed.
137      * FALSE = Cancel button pushed.
138      */

139     public boolean isOK() {
140         return this.ok;
141     }
142
143 } //--------------------------------- E O F -----------------------------------
144
Popular Tags