Source Code Cross Referenced for ChangePasswordDialog.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » contelligent » de.finix.contelligent.client.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.util;
019:
020:        import java.awt.Color;
021:        import java.awt.event.WindowAdapter;
022:        import java.awt.event.WindowEvent;
023:        import java.beans.PropertyChangeEvent;
024:        import java.beans.PropertyChangeListener;
025:
026:        import javax.swing.JDialog;
027:        import javax.swing.JLabel;
028:        import javax.swing.JOptionPane;
029:        import javax.swing.JPasswordField;
030:
031:        import de.finix.contelligent.client.ContelligentClient;
032:        import de.finix.contelligent.client.i18n.Resources;
033:
034:        public class ChangePasswordDialog extends EscapeDialog {
035:            private final String okString = Resources.getLocalString("ok");
036:
037:            private final String cancelString = Resources
038:                    .getLocalString("cancel");
039:
040:            private JLabel passwordLabel, retypePasswordLabel,
041:                    oldPasswordLabel;
042:
043:            private JPasswordField oldPasswordField = new JPasswordField(15);
044:
045:            private JPasswordField passwordField = new JPasswordField(15);
046:
047:            private JPasswordField password2Field = new JPasswordField(15);
048:
049:            private JOptionPane optionPane;
050:
051:            private Color defaultForeground;
052:
053:            private int option = JOptionPane.CANCEL_OPTION;
054:
055:            private boolean askForOldPassword = false;
056:
057:            private int minPasswordChars;
058:
059:            public ChangePasswordDialog(String title, String passwordText,
060:                    String retypePasswordText, String oldPasswordText,
061:                    int minPasswordChars) {
062:                super (ContelligentClient.getActiveFrame(), title, true);
063:                RestrictedDocument document = new RestrictedDocument();
064:                document.setAllowString(RestrictedDocument.PRINCIPALS);
065:                oldPasswordField.setDocument(document);
066:                document = new RestrictedDocument();
067:                document.setAllowString(RestrictedDocument.PRINCIPALS);
068:                passwordField.setDocument(document);
069:                document = new RestrictedDocument();
070:                document.setAllowString(RestrictedDocument.PRINCIPALS);
071:                password2Field.setDocument(document);
072:                passwordLabel = new JLabel(passwordText);
073:                retypePasswordLabel = new JLabel(retypePasswordText);
074:                defaultForeground = passwordLabel.getForeground();
075:                this .minPasswordChars = minPasswordChars;
076:                Object[] array;
077:                if (oldPasswordText != null) {
078:                    askForOldPassword = true;
079:                    oldPasswordLabel = new JLabel(oldPasswordText);
080:                    array = new Object[] { oldPasswordLabel, oldPasswordField,
081:                            passwordLabel, passwordField, retypePasswordLabel,
082:                            password2Field };
083:                } else {
084:                    array = new Object[] { passwordLabel, passwordField,
085:                            retypePasswordLabel, password2Field };
086:                }
087:                Object[] options = { okString, cancelString };
088:                optionPane = new JOptionPane(array,
089:                        JOptionPane.QUESTION_MESSAGE,
090:                        JOptionPane.YES_NO_OPTION, null, options, options[0]);
091:                setContentPane(optionPane);
092:
093:                setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
094:                addWindowListener(new WindowAdapter() {
095:                    public void windowClosing(WindowEvent we) {
096:                        /*
097:                         * Instead of directly closing the window, we're going to change
098:                         * the JOptionPane's value property.
099:                         */
100:                        option = JOptionPane.CANCEL_OPTION;
101:                        optionPane.setValue(new Integer(
102:                                JOptionPane.CLOSED_OPTION));
103:                    }
104:                });
105:
106:                optionPane
107:                        .addPropertyChangeListener(new PropertyChangeListener() {
108:                            public void propertyChange(PropertyChangeEvent e) {
109:                                String prop = e.getPropertyName();
110:
111:                                option = JOptionPane.CANCEL_OPTION;
112:
113:                                if (isVisible()
114:                                        && (e.getSource() == optionPane)
115:                                        && (prop
116:                                                .equals(JOptionPane.VALUE_PROPERTY) || prop
117:                                                .equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
118:                                    Object value = optionPane.getValue();
119:
120:                                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
121:                                        // ignore reset
122:                                        return;
123:                                    }
124:
125:                                    // Reset the JOptionPane's value.
126:                                    // If you don't do this, then if the user
127:                                    // presses the same button next time, no
128:                                    // property change event will be fired.
129:                                    optionPane
130:                                            .setValue(JOptionPane.UNINITIALIZED_VALUE);
131:
132:                                    if (value.equals(okString)) {
133:                                        boolean inputIsValid = checkPassword();
134:                                        if (inputIsValid) {
135:                                            option = JOptionPane.OK_OPTION;
136:                                            setVisible(false);
137:                                        } else {
138:                                            // Reset the JOptionPane's value.
139:                                            // If you don't do this, then if the user
140:                                            // presses the same button next time, no
141:                                            // property change event will be fired.
142:                                            optionPane
143:                                                    .setValue(JOptionPane.UNINITIALIZED_VALUE);
144:                                        }
145:                                    } else { // user closed dialog or clicked cancel
146:                                        setVisible(false);
147:                                    }
148:                                }
149:                            }
150:                        });
151:            }
152:
153:            private boolean checkPassword() {
154:                if (askForOldPassword
155:                        && String.valueOf(passwordField.getPassword()).length() == 0) {
156:                    JOptionPane.showMessageDialog(null, Resources
157:                            .getLocalString("password_missing"), Resources
158:                            .getLocalString("password_invalid"),
159:                            JOptionPane.ERROR_MESSAGE);
160:                    oldPasswordLabel.setForeground(Color.red);
161:                    return false;
162:                } else if (minPasswordChars > -1
163:                        && String.valueOf(passwordField.getPassword()).length() < minPasswordChars) {
164:                    JOptionPane.showMessageDialog(null, Resources
165:                            .getLocalString("password_too_short",
166:                                    new String[] { String
167:                                            .valueOf(minPasswordChars) }),
168:                            Resources.getLocalString("password_invalid"),
169:                            JOptionPane.ERROR_MESSAGE);
170:                    passwordLabel.setForeground(Color.red);
171:                    return false;
172:                } else if (String.valueOf(passwordField.getPassword()).length() == 0) {
173:                    JOptionPane.showMessageDialog(null, Resources
174:                            .getLocalString("password_missing"), Resources
175:                            .getLocalString("password_invalid"),
176:                            JOptionPane.ERROR_MESSAGE);
177:                    passwordLabel.setForeground(Color.red);
178:                    retypePasswordLabel.setForeground(defaultForeground);
179:                    return false;
180:                } else if (!String.valueOf(passwordField.getPassword()).equals(
181:                        String.valueOf(password2Field.getPassword()))) {
182:                    JOptionPane.showMessageDialog(null, Resources
183:                            .getLocalString("password_mismatch"), Resources
184:                            .getLocalString("password_invalid"),
185:                            JOptionPane.ERROR_MESSAGE);
186:                    retypePasswordLabel.setForeground(Color.red);
187:                    return false;
188:                }
189:                passwordLabel.setForeground(defaultForeground);
190:                return true;
191:            }
192:
193:            public String getPassword() {
194:                return String.valueOf(passwordField.getPassword());
195:            }
196:
197:            public String getOldPassword() {
198:                return String.valueOf(oldPasswordField.getPassword());
199:            }
200:
201:            public int getOption() {
202:                return option;
203:            }
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.