Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

TUserAuthenticationDialog.java

00001 /*
00002 *  Name:      TUserAuthenticationDialog.java
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Dialog for authenticating an user
00005 *  Date:      $Date: 2003/10/06 12:45:11 $
00006 *  Revision:  $Revision: 1.6 $
00007 *
00008 *  Copyright (C) 2003  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00027 package org.mpcl.nui;
00028 
00029 import java.awt.BorderLayout;
00030 import java.awt.GridBagConstraints;
00031 import java.awt.GridBagLayout;
00032 import java.awt.event.ActionEvent;
00033 import java.awt.event.ActionListener;
00034 import javax.swing.BorderFactory;
00035 import javax.swing.Box;
00036 import javax.swing.BoxLayout;
00037 import javax.swing.JButton;
00038 import javax.swing.JLabel;
00039 import javax.swing.JPanel;
00040 import javax.swing.JPasswordField;
00041 import javax.swing.JTextField;
00042 import javax.swing.SwingConstants;
00043 
00044 
00046 public class TUserAuthenticationDialog
00047   extends    TAbstractDialog
00048   implements ActionListener
00049 {
00050 
00052   private boolean   gIsAuthentic;
00053 
00055   private JButton   tAcceptButton;
00056 
00058   private IAuthenticator   tAuthenticator;
00059 
00061   private JTextField   tNameTextField;
00062 
00064   private JPasswordField   tPasswordField;
00065 
00067   private IResourceSupplier   tResourceSupplier;
00068 
00070   private String   yUserName;
00071 
00073   private String   yUserPassword;
00074 
00075 
00077   public static class _TEvents
00078   {
00079 
00081     public static final String   _kyAccept = "TUserAuthenticationDialog._TEvents._kyAccept";
00082 
00084     public static final String   _kyCancel = "TUserAuthenticationDialog._TEvents._kyCancel";
00085 
00086   }  // class _TEvents
00087 
00089   public static class _TNames
00090   {
00091 
00093     public static final String   _kyAccept = "org.mpcl.nui.TUserAuthenticationDialog._TNames._kyAccept";
00094 
00096     public static final String   _kyCancel = "org.mpcl.nui.TUserAuthenticationDialog._TNames._kyCancel";
00097 
00099     public static final String   _kyName = "org.mpcl.nui.TUserAuthenticationDialog._TNames._kyName";
00100 
00102     public static final String   _kyPassword = "org.mpcl.nui.TUserAuthenticationDialog._TNames._kyPassword";
00103 
00105     public static final String   _kyTitle = "org.mpcl.nui.TUserAuthenticationDialog._TNames._kyTitle";
00106 
00107   }  // class _TNames
00108 
00109 
00110   //
00111   //  C O N S T R U C T O R S
00112   //
00113 
00119   public TUserAuthenticationDialog ( IResourceSupplier tRESOURCE_SUPPLIER ,
00120                                      IAuthenticator    tAUTHENTICATOR     )
00121   {
00122     super (null, tRESOURCE_SUPPLIER.getText (_TNames._kyTitle), null, true);
00123     gIsAuthentic      = false;
00124     tAuthenticator    = tAUTHENTICATOR;
00125     tResourceSupplier = tRESOURCE_SUPPLIER;
00126     yUserName         = new String();
00127     yUserPassword     = null;
00128     tMainPanel.add (createDataSheetPanel(), BorderLayout.CENTER);
00129     tMainPanel.add (createButtonPanel(),    BorderLayout.SOUTH);
00130   }
00131 
00138   public TUserAuthenticationDialog ( IResourceSupplier tRESOURCE_SUPPLIER ,
00139                                      IAuthenticator    tAUTHENTICATOR     ,
00140                                      String            yDEFAULT_USER_NAME )
00141   {
00142     super (null, tRESOURCE_SUPPLIER.getText (_TNames._kyTitle), null, true);
00143     gIsAuthentic      = false;
00144     tAuthenticator    = tAUTHENTICATOR;
00145     tResourceSupplier = tRESOURCE_SUPPLIER;
00146     yUserName         = yDEFAULT_USER_NAME;
00147     yUserPassword     = null;
00148     tMainPanel.add (createDataSheetPanel(), BorderLayout.CENTER);
00149     tMainPanel.add (createButtonPanel(),    BorderLayout.SOUTH);
00150   }
00151 
00156   public void actionPerformed (ActionEvent tACTION_EVENT)
00157   {
00158 
00159     String   yCommand = tACTION_EVENT.getActionCommand();
00160 
00161     if ( yCommand.equals (_TEvents._kyAccept) )
00162     {
00163       yUserName     = new String (tNameTextField.getText());
00164       yUserPassword = new String (tPasswordField.getPassword());
00165       if ( tAuthenticator.authenticate (yUserName, yUserPassword) )
00166       {
00167         gIsAuthentic = true;
00168         hide();
00169       }
00170       else
00171       {
00172         yUserName     = null;
00173         yUserPassword = null;
00174         gIsAuthentic  = false;
00175       }
00176     }
00177     else if ( yCommand.equals (_TEvents._kyCancel) )
00178     {
00179       yUserName     = null;
00180       yUserPassword = null;
00181       gIsAuthentic  = false;
00182       hide();
00183     }
00184 
00185   }  // actionPerformed()
00186 
00187   public void initialize()
00188   {
00189     getRootPane().setDefaultButton (tAcceptButton);
00190     tNameTextField.requestFocus();
00191   }
00192 
00193 
00194   //
00195   //  S E L E C T O R S
00196   //
00197 
00202   private JPanel createButtonPanel()
00203   {
00204 
00205     JPanel    tButtonPanel  = new JPanel();
00206     JButton   tCancelButton = new JButton (tResourceSupplier.getText (_TNames._kyCancel));
00207 
00208     tAcceptButton = new JButton (tResourceSupplier.getText (_TNames._kyAccept));
00209     tAcceptButton.setActionCommand (_TEvents._kyAccept);
00210     tCancelButton.setActionCommand (_TEvents._kyCancel);
00211     tAcceptButton.addActionListener (this);
00212     tCancelButton.addActionListener (this);
00213     tAcceptButton.setMnemonic (tResourceSupplier.getMnemonic (_TNames._kyAccept));
00214     tCancelButton.setMnemonic (tResourceSupplier.getMnemonic (_TNames._kyCancel));
00215     tButtonPanel.setLayout (new BoxLayout (tButtonPanel, BoxLayout.X_AXIS));
00216     tButtonPanel.setBorder (BorderFactory.createEmptyBorder (_kiEmptyBorderLength, 0, 0, 0));
00217     tButtonPanel.add (Box.createHorizontalGlue());
00218     tButtonPanel.add (tAcceptButton);
00219     tButtonPanel.add (tCancelButton);
00220     return tButtonPanel;
00221 
00222   }  // createButtonPanel()
00223 
00228   private JPanel createDataSheetPanel()
00229   {
00230 
00231     GridBagConstraints   tGridBagConstraints;
00232     GridBagLayout        tGridBagLayout;
00233     JPanel               tDataSheetPanel;
00234     JLabel               tNameLabel;
00235     JLabel               tPasswordLabel;
00236 
00237     tDataSheetPanel     = new JPanel();
00238     tGridBagConstraints = new GridBagConstraints();
00239     tGridBagLayout      = new GridBagLayout();
00240     tNameLabel          = new JLabel (tResourceSupplier.getText (_TNames._kyName),     SwingConstants.LEFT);
00241     tPasswordLabel      = new JLabel (tResourceSupplier.getText (_TNames._kyPassword), SwingConstants.LEFT);
00242     tNameTextField      = new JTextField     (yUserName, 8);
00243     tPasswordField      = new JPasswordField (8);
00244     tNameLabel.setDisplayedMnemonic     (tResourceSupplier.getMnemonic (_TNames._kyName));
00245     tPasswordLabel.setDisplayedMnemonic (tResourceSupplier.getMnemonic (_TNames._kyPassword));
00246     tNameLabel.setLabelFor     (tNameTextField);
00247     tPasswordLabel.setLabelFor (tPasswordField);
00248     tDataSheetPanel.setBorder (createBorder());
00249     tDataSheetPanel.setLayout (tGridBagLayout);
00250 
00251     //
00252     //  User name label.
00253     //
00254     tGridBagConstraints.fill   = GridBagConstraints.VERTICAL;
00255     tGridBagConstraints.anchor = GridBagConstraints.WEST;
00256     tGridBagConstraints.gridx  = 0;
00257     tGridBagConstraints.gridy  = 0;
00258     tGridBagConstraints.ipadx  = 10;
00259     tGridBagConstraints.ipady  = 10;
00260     tGridBagLayout.setConstraints (tNameLabel, tGridBagConstraints);
00261     tDataSheetPanel.add (tNameLabel);
00262 
00263     //
00264     //  Name text field. It selects all the text.
00265     //
00266     tGridBagConstraints.gridx = 1;
00267     tGridBagLayout.setConstraints (tNameTextField, tGridBagConstraints);
00268     tNameTextField.selectAll();
00269     tDataSheetPanel.add (tNameTextField);
00270 
00271     //
00272     //  Password label.
00273     //
00274     tGridBagConstraints.gridx = 0;
00275     tGridBagConstraints.gridy = 1;
00276     tGridBagLayout.setConstraints (tPasswordLabel, tGridBagConstraints);
00277     tDataSheetPanel.add (tPasswordLabel);
00278 
00279     //
00280     //  Password text field.
00281     //
00282     tGridBagConstraints.gridx = 1;
00283     tGridBagLayout.setConstraints (tPasswordField, tGridBagConstraints);
00284     tDataSheetPanel.add (tPasswordField);
00285     return tDataSheetPanel;
00286 
00287   }  // createDataSheetPanel()
00288 
00289 
00290   //
00291   //  S E L E C T O R S
00292   //
00293 
00299   public String getName()
00300   {
00301     return yUserName;
00302   }
00303 
00309   public String getPassword()
00310   {
00311     return yUserPassword;
00312   }
00313 
00318   public boolean isAuthentic()
00319   {
00320     return gIsAuthentic;
00321   }
00322 
00323 }  // class TUserAuthenticationDialog

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18