Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GuiVirtualDatabaseLoginFrame.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.frames;
00026 
00027 import java.awt.Dimension;
00028 import java.awt.FlowLayout;
00029 import java.awt.Toolkit;
00030 import java.awt.event.ActionListener;
00031 
00032 import javax.swing.JButton;
00033 import javax.swing.JDialog;
00034 import javax.swing.JFrame;
00035 import javax.swing.JLabel;
00036 import javax.swing.JPasswordField;
00037 import javax.swing.JTextField;
00038 import javax.swing.WindowConstants;
00039 
00040 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
00041 import org.objectweb.cjdbc.console.gui.FrameConfirmKeyListener;
00042 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00043 import org.objectweb.cjdbc.console.gui.session.GuiSession;
00044 
00045 /**
00046  * This class defines a GuiVirtualDatabaseLoginFrame
00047  * 
00048  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00049  * @version 1.0
00050  */
00051 public class GuiVirtualDatabaseLoginFrame extends JDialog
00052 {
00053   private JPasswordField     passwordBox;
00054   private JTextField         loginBox;
00055   private ActionListener     actionListener;
00056   private String             databaseName;
00057   private String             controllerHost;
00058   private String             controllerPort;
00059   private JButton            optionConfirm;
00060   private FrameConfirmKeyListener keyListener;
00061 
00062   /**
00063    * Creates a new <code>GuiVirtualDatabaseLoginFrame.java</code> object
00064    * 
00065    * @param listener that listens for actions
00066    * @param databaseName the name of the virtual database
00067    * @param parent the parent frame
00068    * @param controllerHost controller ip address
00069    * @param controllerPort controller port
00070    * @param session the session to retrieve database stored parameters
00071    */
00072   public GuiVirtualDatabaseLoginFrame(JFrame parent, ActionListener listener,
00073       String databaseName, String controllerHost, String controllerPort,
00074       GuiSession session)
00075 
00076   {
00077     super(parent, GuiTranslate.get("frame.database.title", databaseName), true);
00078 
00079     this.actionListener = listener;
00080     this.controllerHost = controllerHost;
00081     this.controllerPort = controllerPort;
00082     Toolkit toolkit = Toolkit.getDefaultToolkit();
00083     Dimension dim = toolkit.getScreenSize();
00084     int screenHeight = dim.height;
00085     int screenWidth = dim.width;
00086     int frameWidth = 450;
00087     int frameHeight = 80;
00088     this.setBounds((screenWidth - frameWidth) / 2,
00089         (screenHeight - frameHeight) / 2, frameWidth, frameHeight);
00090     this.validate();
00091     this.setVisible(false);
00092     this.setResizable(false);
00093     this.getContentPane().setLayout(new FlowLayout());
00094     this.databaseName = databaseName;
00095 
00096     // Define confirm button before listener
00097     optionConfirm = new JButton(GuiTranslate.get("frame.database.approve"));
00098     optionConfirm.setActionCommand(GuiCommands.COMMAND_DATABASE_AUTHENTICATE);
00099     optionConfirm.addActionListener(actionListener);
00100 
00101     keyListener = new FrameConfirmKeyListener(optionConfirm);
00102     this.addKeyListener(keyListener);
00103 
00104     Dimension buttonDim = new Dimension(80, 20);
00105 
00106     this.getContentPane().add(
00107         new JLabel(GuiTranslate.get("frame.database.login")));
00108     loginBox = new JTextField(0);
00109     loginBox.setAlignmentX(CENTER_ALIGNMENT);
00110     String login = session.getAuthenticatedDatabaseLogin(databaseName);
00111     if (login != null)
00112       loginBox.setText(login);
00113     loginBox.setPreferredSize(buttonDim);
00114     loginBox.addActionListener(actionListener);
00115     loginBox.addKeyListener(keyListener);
00116     this.getContentPane().add(loginBox);
00117 
00118     this.getContentPane().add(
00119         new JLabel(GuiTranslate.get("frame.database.password")));
00120     passwordBox = new JPasswordField(0);
00121     passwordBox.setPreferredSize(buttonDim);
00122     String pass = session.getAuthenticatedDatabasePassword(databaseName);
00123     if (pass != null)
00124       passwordBox.setText(pass);
00125     passwordBox.setAlignmentX(CENTER_ALIGNMENT);
00126     passwordBox.addKeyListener(keyListener);
00127     passwordBox.addActionListener(actionListener);
00128     this.getContentPane().add(passwordBox);
00129 
00130     this.getContentPane().add(optionConfirm);
00131     this.validate();
00132     setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
00133   }
00134 
00135   /**
00136    * Returns the loginBox value.
00137    * 
00138    * @return Returns the loginBox.
00139    */
00140   public JTextField getLoginBox()
00141   {
00142     return loginBox;
00143   }
00144 
00145   /**
00146    * Returns the passwordBox value.
00147    * 
00148    * @return Returns the passwordBox.
00149    */
00150   public JTextField getPasswordBox()
00151   {
00152     return passwordBox;
00153   }
00154 
00155   /**
00156    * Returns the databaseName value.
00157    * 
00158    * @return Returns the databaseName.
00159    */
00160   public String getDatabaseName()
00161   {
00162     return databaseName;
00163   }
00164 
00165   /**
00166    * Returns the controllerHost value.
00167    * 
00168    * @return Returns the controllerHost.
00169    */
00170   public String getControllerHost()
00171   {
00172     return controllerHost;
00173   }
00174 
00175   /**
00176    * Returns the controllerPort value.
00177    * 
00178    * @return Returns the controllerPort.
00179    */
00180   public String getControllerPort()
00181   {
00182     return controllerPort;
00183   }
00184 }

Generated on Mon Apr 11 22:01:32 2005 for C-JDBC by  doxygen 1.3.9.1