KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > frames > GuiVirtualDatabaseLoginFrame


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.frames;
26
27 import java.awt.Dimension JavaDoc;
28 import java.awt.FlowLayout JavaDoc;
29 import java.awt.Toolkit JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JDialog JavaDoc;
34 import javax.swing.JFrame JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JPasswordField JavaDoc;
37 import javax.swing.JTextField JavaDoc;
38 import javax.swing.WindowConstants JavaDoc;
39
40 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
41 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener;
42 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
43 import org.objectweb.cjdbc.console.gui.session.GuiSession;
44
45 /**
46  * This class defines a GuiVirtualDatabaseLoginFrame
47  *
48  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
49  * @version 1.0
50  */

51 public class GuiVirtualDatabaseLoginFrame extends JDialog JavaDoc
52 {
53   private JPasswordField JavaDoc passwordBox;
54   private JTextField JavaDoc loginBox;
55   private ActionListener JavaDoc actionListener;
56   private String JavaDoc databaseName;
57   private String JavaDoc controllerHost;
58   private String JavaDoc controllerPort;
59   private JButton JavaDoc optionConfirm;
60   private FrameConfirmKeyListener keyListener;
61
62   /**
63    * Creates a new <code>GuiVirtualDatabaseLoginFrame.java</code> object
64    *
65    * @param listener that listens for actions
66    * @param databaseName the name of the virtual database
67    * @param parent the parent frame
68    * @param controllerHost controller ip address
69    * @param controllerPort controller port
70    * @param session the session to retrieve database stored parameters
71    */

72   public GuiVirtualDatabaseLoginFrame(JFrame JavaDoc parent, ActionListener JavaDoc listener,
73       String JavaDoc databaseName, String JavaDoc controllerHost, String JavaDoc controllerPort,
74       GuiSession session)
75
76   {
77     super(parent, GuiTranslate.get("frame.database.title", databaseName), true);
78
79     this.actionListener = listener;
80     this.controllerHost = controllerHost;
81     this.controllerPort = controllerPort;
82     Toolkit JavaDoc toolkit = Toolkit.getDefaultToolkit();
83     Dimension JavaDoc dim = toolkit.getScreenSize();
84     int screenHeight = dim.height;
85     int screenWidth = dim.width;
86     int frameWidth = 450;
87     int frameHeight = 80;
88     this.setBounds((screenWidth - frameWidth) / 2,
89         (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
90     this.validate();
91     this.setVisible(false);
92     this.setResizable(false);
93     this.getContentPane().setLayout(new FlowLayout JavaDoc());
94     this.databaseName = databaseName;
95
96     // Define confirm button before listener
97
optionConfirm = new JButton JavaDoc(GuiTranslate.get("frame.database.approve"));
98     optionConfirm.setActionCommand(GuiCommands.COMMAND_DATABASE_AUTHENTICATE);
99     optionConfirm.addActionListener(actionListener);
100
101     keyListener = new FrameConfirmKeyListener(optionConfirm);
102     this.addKeyListener(keyListener);
103
104     Dimension JavaDoc buttonDim = new Dimension JavaDoc(80, 20);
105
106     this.getContentPane().add(
107         new JLabel JavaDoc(GuiTranslate.get("frame.database.login")));
108     loginBox = new JTextField JavaDoc(0);
109     loginBox.setAlignmentX(CENTER_ALIGNMENT);
110     String JavaDoc login = session.getAuthenticatedDatabaseLogin(databaseName);
111     if (login != null)
112       loginBox.setText(login);
113     loginBox.setPreferredSize(buttonDim);
114     loginBox.addActionListener(actionListener);
115     loginBox.addKeyListener(keyListener);
116     this.getContentPane().add(loginBox);
117
118     this.getContentPane().add(
119         new JLabel JavaDoc(GuiTranslate.get("frame.database.password")));
120     passwordBox = new JPasswordField JavaDoc(0);
121     passwordBox.setPreferredSize(buttonDim);
122     String JavaDoc pass = session.getAuthenticatedDatabasePassword(databaseName);
123     if (pass != null)
124       passwordBox.setText(pass);
125     passwordBox.setAlignmentX(CENTER_ALIGNMENT);
126     passwordBox.addKeyListener(keyListener);
127     passwordBox.addActionListener(actionListener);
128     this.getContentPane().add(passwordBox);
129
130     this.getContentPane().add(optionConfirm);
131     this.validate();
132     setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
133   }
134
135   /**
136    * Returns the loginBox value.
137    *
138    * @return Returns the loginBox.
139    */

140   public JTextField JavaDoc getLoginBox()
141   {
142     return loginBox;
143   }
144
145   /**
146    * Returns the passwordBox value.
147    *
148    * @return Returns the passwordBox.
149    */

150   public JTextField JavaDoc getPasswordBox()
151   {
152     return passwordBox;
153   }
154
155   /**
156    * Returns the databaseName value.
157    *
158    * @return Returns the databaseName.
159    */

160   public String JavaDoc getDatabaseName()
161   {
162     return databaseName;
163   }
164
165   /**
166    * Returns the controllerHost value.
167    *
168    * @return Returns the controllerHost.
169    */

170   public String JavaDoc getControllerHost()
171   {
172     return controllerHost;
173   }
174
175   /**
176    * Returns the controllerPort value.
177    *
178    * @return Returns the controllerPort.
179    */

180   public String JavaDoc getControllerPort()
181   {
182     return controllerPort;
183   }
184 }
Popular Tags