// Sample code file: Login.java
// Warning: This code has been marked up for HTML
/****************************************************************************
%name: Login.java %
%version: 1 %
%date_modified: Tue Oct 15 12:22:58 2001 %
Copyright (c) 2001 Novell, Inc. All Rights Reserved.
THIS WORK IS AN UNPUBLISHED WORK AND CONTAINS CONFIDENTIAL PROPRIETARY
AND TRADE SECRET INFORMATION OF NOVELL, INC. ACCESS TO THIS WORK IS
RESTRICTED TO (I) NOVELL, INC. EMPLOYEES WHO HAVE A NEED TO KNOW HOW
TO PERFORM TASKS WITHIN THE SCOPE OF THEIR ASSIGNMENTS AND (II)
ENTITIES OTHER THAN NOVELL, INC. WHO HAVE ENTERED INTO APPROPRIATE
LICENSE AGREEMENTS. NO PART OF THIS WORK MAY BE USED, PRACTICED,
PERFORMED COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED, ABRIDGED,
CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, RECAST, TRANSFORMED
OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF NOVELL, INC. ANY USE
OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD SUBJECT THE
PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
@author Sriramya Jambunathan
@modifier Sanjay Gupta
****************************************************************************/
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Login extends JDialog implements ActionListener, KeyListener{
// Member variables ('m' -> member)
private String m_fullName = null;
private String m_serverName = null;
private String m_context = null;
private String m_cn = null;
private String m_password = null;
private String m_entryFullName = null;
// Gui Components ('g' -> GUI component)
private JPanel g_root = null;
private JLabel g_cnLabel = null;
private JTextField g_cnText = null;
private JLabel g_passwordLabel = null;
private JPasswordField g_passwordText = null;
private JTabbedPane g_tabbedPane = null;
private JLabel g_serverNameLabel = null;
private JTextField g_serverNameText = null;
private JLabel g_contextLabel = null;
private JTextField g_contextText = null;
private JButton g_login = null;
private JButton g_cancel = null;
private UAMConsole g_testUI = null;
Login(UAMConsole frame, String title)
{
//this.super(frame.getFrame(),title,true);
super(frame.getFrame(),title,true);
g_testUI = frame;
g_root = new JPanel();
g_root.setLayout( new BoxLayout(g_root, BoxLayout.Y_AXIS) );
JPanel pan4 = new JPanel();
pan4.setLayout(new BoxLayout(pan4,BoxLayout.Y_AXIS));
JPanel pan11 = new JPanel();
pan11.setLayout(new FlowLayout(FlowLayout.LEFT));
g_serverNameLabel = new JLabel("Server Name :");
g_serverNameLabel.setDisplayedMnemonic('s');
g_serverNameLabel.setLabelFor(g_serverNameText);
g_serverNameText = new JTextField(30);
pan11.add( g_serverNameLabel );
pan11.add( g_serverNameText );
g_serverNameText.addKeyListener( this );
g_root.add(pan11);
JPanel pan2 = new JPanel();
pan2.setLayout(new FlowLayout(FlowLayout.LEFT));
g_cnLabel = new JLabel(" UserName :");
g_cnText = new JTextField(30);
pan2.add( g_cnLabel );
pan2.add( g_cnText );
g_cnText.addKeyListener( this );
pan4.add(pan2);
JPanel pan3 = new JPanel();
pan3.setLayout(new FlowLayout(FlowLayout.LEFT));
g_passwordLabel = new JLabel(" Password :");
g_passwordText = new JPasswordField(30);
pan3.add( g_passwordLabel );
pan3.add( g_passwordText );
g_passwordText.addKeyListener( this );
pan4.add(pan3);
g_root.add(pan4);
JPanel pan5 = new JPanel();
pan5.setLayout(new FlowLayout(FlowLayout.RIGHT));
g_login = new JButton(" Login ");
g_cancel = new JButton(" Cancel ");
g_login.setMnemonic('l');
g_cancel.setMnemonic('c');
pan5.add(g_login);
pan5.add(g_cancel);
Insets insets = pan5.getInsets();
g_root.add(pan5);
g_login.addActionListener(this);
g_cancel.addActionListener(this);
this.getContentPane().add( g_root );
this.pack();
//this.setLocation(x,y );
}
public void setVisible(boolean b)
{
if (b == true)
Utilities.centerWindow(this);
super.setVisible(b);
g_serverNameText.requestFocus();
}
public void actionPerformed(ActionEvent evt)
{
if(evt.getSource() == g_login)
this.checkFields();
if(evt.getSource() == g_cancel)
{
m_password = "";
g_passwordText.setText("");
this.dispose();
}
}
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent evt)
{
if(evt.getKeyCode() == KeyEvent.VK_ENTER)
checkFields();
if (evt.getKeyCode() == KeyEvent.VK_ESCAPE)
{
m_password = "";
g_passwordText.setText("");
this.dispose();
}
// super(evt);
}
private void checkFields()
{
m_cn = g_cnText.getText();
m_password = new String(g_passwordText.getPassword());
m_serverName = g_serverNameText.getText();
if((m_cn == null) || (m_cn.equals("")))
{
JOptionPane.showMessageDialog(this, "Enter the common name","Error",JOptionPane.ERROR_MESSAGE);
if (m_password != null)
g_passwordText.setText("");
g_cnText.requestFocus();
return;
}
else if(m_password == null) {
JOptionPane.showMessageDialog(this, "Enter the Password","Error", JOptionPane.ERROR_MESSAGE);
g_passwordText.setText("");
g_passwordText.requestFocus();
return;
}
else if((m_serverName == null) || (m_serverName.equals(""))) {
JOptionPane.showMessageDialog(this, "Enter the ServerName","Error",JOptionPane.ERROR_MESSAGE);
if (m_password != null)
g_passwordText.setText("");
g_serverNameText.requestFocus();
return;
}
try
{
g_testUI.authenticate(m_serverName, m_cn,m_password);
}catch (Exception e)
{
return;
}
m_password = "";
g_passwordText.setText("");
this.dispose();
//setVisible(false);
}
}