1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail/IM me at jeti@jabber.org |
---|
21 | * |
---|
22 | * created 24-4-2005 |
---|
23 | */ |
---|
24 | |
---|
25 | package nu.fw.jeti.ui; |
---|
26 | |
---|
27 | import java.awt.BorderLayout; |
---|
28 | import java.awt.event.ActionEvent; |
---|
29 | |
---|
30 | import javax.swing.*; |
---|
31 | |
---|
32 | import nu.fw.jeti.jabber.Backend; |
---|
33 | import nu.fw.jeti.jabber.JID; |
---|
34 | import nu.fw.jeti.jabber.elements.IQRegister; |
---|
35 | import nu.fw.jeti.jabber.elements.InfoQuery; |
---|
36 | import nu.fw.jeti.util.I18N; |
---|
37 | import nu.fw.jeti.util.Utils; |
---|
38 | |
---|
39 | /** |
---|
40 | * @author E.S. de Boer |
---|
41 | */ |
---|
42 | |
---|
43 | public class ChangePassword extends JDialog |
---|
44 | { |
---|
45 | //JPanel panel1 = new JPanel(); |
---|
46 | private Box panel1 = Box.createVerticalBox(); |
---|
47 | private JLabel jLabel1 = new JLabel(); |
---|
48 | private JPasswordField txtOldPassword = new JPasswordField(); |
---|
49 | private JLabel jLabel2 = new JLabel(); |
---|
50 | private JPasswordField txtNewPassword1 = new JPasswordField(); |
---|
51 | private JPasswordField txtNewPassword2 = new JPasswordField(); |
---|
52 | private JLabel jLabel3 = new JLabel(); |
---|
53 | private JPanel jPanel1 = new JPanel(); |
---|
54 | private JButton btnCancel = new JButton(); |
---|
55 | private JButton btnOK = new JButton(); |
---|
56 | private Backend backend; |
---|
57 | |
---|
58 | |
---|
59 | public ChangePassword(Backend backend) |
---|
60 | { |
---|
61 | super(backend.getMainFrame(), I18N.gettext("main.ChangePassword.Change_Password"), false); |
---|
62 | this.backend = backend; |
---|
63 | jbInit(); |
---|
64 | pack(); |
---|
65 | setLocationRelativeTo(backend.getMainFrame()); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | void jbInit() |
---|
70 | { |
---|
71 | I18N.setTextAndMnemonic("main.ChangePassword.Old_Password",jLabel1); |
---|
72 | |
---|
73 | txtOldPassword.setHorizontalAlignment(SwingConstants.LEADING); |
---|
74 | txtNewPassword1.setHorizontalAlignment(SwingConstants.LEFT); |
---|
75 | txtNewPassword2.setHorizontalAlignment(SwingConstants.LEFT); |
---|
76 | |
---|
77 | jPanel1.setAlignmentX(0.0f); |
---|
78 | this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); |
---|
79 | panel1.add(Box.createHorizontalGlue()); |
---|
80 | |
---|
81 | I18N.setTextAndMnemonic("main.ChangePassword.New_Password",jLabel2); |
---|
82 | jLabel2.setLabelFor(txtNewPassword1); |
---|
83 | jLabel3.setHorizontalAlignment(SwingConstants.LEFT); |
---|
84 | |
---|
85 | I18N.setTextAndMnemonic("main.ChangePassword.New_Password",jLabel3); |
---|
86 | jLabel3.setLabelFor(txtNewPassword2); |
---|
87 | jLabel1.setHorizontalAlignment(SwingConstants.LEFT); |
---|
88 | |
---|
89 | Action cancelAction = new AbstractAction(I18N.gettext("Cancel")) |
---|
90 | { |
---|
91 | public void actionPerformed(ActionEvent e) |
---|
92 | { |
---|
93 | dispose(); |
---|
94 | } |
---|
95 | }; |
---|
96 | Utils.addCancelButton(this, btnCancel, cancelAction); |
---|
97 | |
---|
98 | btnOK.setText(I18N.gettext("OK")); |
---|
99 | btnOK.addActionListener(new java.awt.event.ActionListener() |
---|
100 | { |
---|
101 | |
---|
102 | public void actionPerformed(ActionEvent e) |
---|
103 | { |
---|
104 | btnOK_actionPerformed(e); |
---|
105 | } |
---|
106 | }); |
---|
107 | getContentPane().add(panel1, BorderLayout.CENTER); |
---|
108 | panel1.add(jLabel1); |
---|
109 | panel1.add(txtOldPassword); |
---|
110 | panel1.add(jLabel2); |
---|
111 | panel1.add(txtNewPassword1); |
---|
112 | panel1.add(jLabel3); |
---|
113 | panel1.add(txtNewPassword2); |
---|
114 | panel1.add(jPanel1); |
---|
115 | jPanel1.add(btnOK); |
---|
116 | jPanel1.add(btnCancel); |
---|
117 | } |
---|
118 | |
---|
119 | void btnOK_actionPerformed(ActionEvent e) |
---|
120 | { |
---|
121 | if(txtNewPassword1.getText().equals(" ") |
---|
122 | || !txtNewPassword1.getText().equals(txtNewPassword2.getText())) |
---|
123 | { |
---|
124 | JOptionPane.showMessageDialog(this, I18N.gettext("main.ChangePassword.Password_not_equal")); |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | if(backend.isPasswordValid(txtOldPassword.getText())) |
---|
129 | { |
---|
130 | //TODO add iq listener that changes password in profile if set |
---|
131 | backend.send(new InfoQuery(new JID(backend.getMyJID().getDomain()) |
---|
132 | ,"set",new IQRegister( |
---|
133 | backend.getMyJID().getUser(),txtNewPassword1.getText()))); |
---|
134 | this.dispose(); |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | /* |
---|
140 | * Overrides for emacs |
---|
141 | * Local variables: |
---|
142 | * tab-width: 4 |
---|
143 | * End: |
---|
144 | */ |
---|