Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/gui/login/ChangePwDialog.java


1   /*
2    * ChangePwDialog.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:48 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.gui.login;
12  
13  import java.awt.Dimension;
14  import java.awt.Frame;
15  import java.awt.Label;
16  import java.awt.event.ActionEvent;
17  import java.awt.event.ActionListener;
18  
19  import com.flexstor.common.awt.FlexPanel;
20  import com.flexstor.common.awt.MultiColumnLayout;
21  import com.flexstor.common.awt.dialogs.OptionDlg;
22  import com.flexstor.common.awt.event.FlexTextEvent;
23  import com.flexstor.common.awt.event.FlexTextListener;
24  import com.flexstor.common.awt.field.FlexTextField;
25  import com.flexstor.common.resources.Resources;
26  
27  
28  /**
29   * Creates the Text Fields for Old and New PW and puts them in a Panel
30   * for the super class to display.
31   */
32  public class ChangePwDialog
33         extends OptionDlg
34         implements FlexTextListener, ActionListener
35  {
36     private int             nStatus        = LoginModel.STATE_SHOW_CHANGE_PW_GUI;
37     private boolean         bValidPassword = false;
38     private boolean         bValidConfirm  = false;
39     private boolean         bPrevPassword  = true;
40     private boolean         bPrevConfirm   = true;
41     private FlexTextField     tfPassword, tfConfirm;
42  
43     public ChangePwDialog ( Frame frame, String sTitle )
44     {
45        super ( frame, sTitle, OK_CANCEL );
46        frame.setTitle ( sTitle );
47  
48        setContent(buildFieldPanel());
49        setFocusComponent(tfPassword);
50        enableFields();
51        pack();
52        centerOn ( null );
53     }
54     
55     
56     public int doChangePassword ( LoginUserData loginData )
57     {
58        setVisible ( true );
59        requestFocus();
60        toFront();
61      
62        loginData.setNewPassword ( tfPassword.getText() );
63        return nStatus;
64     }
65  
66     
67     /**
68      * Builds the panel for the text fields.
69      * @return The text field panel.
70      */
71     private FlexPanel buildFieldPanel ( )
72     {
73        tfPassword = new FlexTextField ( LoginModel.PASSWORD_LENGTH );
74        tfConfirm  = new FlexTextField ( LoginModel.PASSWORD_LENGTH );
75        tfPassword.setPasswordMode();
76        tfConfirm.setPasswordMode();
77  
78        tfPassword.addTextListener ( this );
79        tfConfirm.addTextListener ( this );
80  
81        FlexPanel  panel    = new FlexPanel();
82        int[]    naWidths = { 125, 140 };
83  
84        panel.setInsets ( new Dimension ( 20, 15 ) );
85        panel.setLayout ( new MultiColumnLayout ( 10, naWidths ) );
86        panel.add ( "0,0", new Label ( Resources.get( 5007 ) ) );
87        panel.add ( "1,0", new Label ( Resources.get( 5008) ) );
88        panel.add ( "0,1", tfPassword );
89        panel.add ( "1,1", tfConfirm );
90        return panel;
91     }
92  
93  
94     public void textValueChangeBegin ( FlexTextEvent e )
95     {
96     }
97  
98  
99     public void textValueChangeEnd ( FlexTextEvent e )
100    {
101       if ( e.getSource() == tfPassword )
102          bValidPassword = LoginModel.isValidPassword ( tfPassword.getText() );
103 
104       else if ( e.getSource() == tfConfirm )
105          bValidConfirm = LoginModel.isValidPassword ( tfConfirm.getText() );
106 
107       enableFields();
108    }
109 
110 
111    private void enableFields ( )
112    {
113       if ( bValidPassword != bPrevPassword )
114          tfConfirm.setEnabled ( bValidPassword );
115 
116       getComponentForId(ACTION_OK).setEnabled ( canPerformDefaultAction() );
117 
118       bPrevPassword = bValidPassword;
119       bPrevConfirm  = bValidConfirm;
120    }
121 
122    protected boolean canPerformDefaultAction()
123    {
124       return bValidPassword && bValidConfirm &&
125              !tfPassword.getText().equals("") && tfPassword.getText().equals(tfConfirm.getText());
126    }
127 
128    public void actionPerformed(ActionEvent e)
129    {
130       if (Integer.parseInt(e.getActionCommand()) == ACTION_OK)
131          nStatus = LoginModel.STATE_READY_TO_CHANGE_PW;
132       else
133          nStatus = LoginModel.STATE_CHANGE_PW_CANCELED;
134          
135       // Due to bug of Modal dialog use dispose() for Solaris or Linux
136       String osName = System.getProperty("os.name");
137       java.util.Properties systemProperties = System.getProperties();
138       //if ((OS.isSolaris()) || osName.equals("Linux"))
139       //{
140         dispose();
141       //}
142       //else // else use setVisible(false)
143       //{
144       //  setVisible ( false );
145       //}
146    }
147 }