| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.dialog; |
| 16 | |
| 17 | import javax.swing.JLabel; |
| 18 | import javax.swing.JPasswordField; |
| 19 | import javax.swing.JTextField; |
| 20 | |
| 21 | import org.jdesktop.application.Action; |
| 22 | |
| 23 | import net.sourceforge.hivegui.component.TextListener; |
| 24 | import net.sourceforge.hivegui.dialog.AbstractDialogPanel; |
| 25 | |
| 26 | import zappini.designgridlayout.DesignGridLayout; |
| 27 | |
| 28 | public class LoginPanel extends AbstractDialogPanel |
| 29 | { |
| 30 | static private final String NAME = "login"; |
| 31 | |
| 32 | public LoginPanel(String login, String password) |
| 33 | { |
| 34 | super(NAME); |
| 35 | |
| 36 | _lblUser.setName(NAME + "-user-label"); |
| 37 | _txfUser.setName(NAME + "-user"); |
| 38 | _lblPassword.setName(NAME + "-password-label"); |
| 39 | _pwfPassword.setName(NAME + "-password"); |
| 40 | |
| 41 | _lblUser.setLabelFor(_txfUser); |
| 42 | _lblPassword.setLabelFor(_pwfPassword); |
| 43 | |
| 44 | DesignGridLayout layout = new DesignGridLayout(this); |
| 45 | setLayout(layout); |
| 46 | |
| 47 | layout.row().label(_lblUser).add(_txfUser); |
| 48 | layout.row().label(_lblPassword).add(_pwfPassword); |
| 49 | |
| 50 | _txfUser.setText(login); |
| 51 | _pwfPassword.setText(password); |
| 52 | |
| 53 | TextListener listener = new TextListener() |
| 54 | { |
| 55 | @Override protected void contentUpdated() |
| 56 | { |
| 57 | setAcceptEnabled(_txfUser.getText().length() != 0); |
| 58 | } |
| 59 | }; |
| 60 | _txfUser.getDocument().addDocumentListener(listener); |
| 61 | // _pwfPassword.getDocument().addDocumentListener(listener); |
| 62 | setAcceptEnabled(_txfUser.getText().length() != 0); |
| 63 | } |
| 64 | |
| 65 | @Action(enabledProperty = "acceptEnabled") |
| 66 | public void accept() |
| 67 | { |
| 68 | _parent.close(false); |
| 69 | } |
| 70 | |
| 71 | public String getUserName() |
| 72 | { |
| 73 | return _txfUser.getText(); |
| 74 | } |
| 75 | |
| 76 | public String getPassword() |
| 77 | { |
| 78 | return new String(_pwfPassword.getPassword()); |
| 79 | } |
| 80 | |
| 81 | final private JLabel _lblUser = new JLabel(); |
| 82 | final private JTextField _txfUser = new JTextField(); |
| 83 | final private JLabel _lblPassword = new JLabel(); |
| 84 | final private JPasswordField _pwfPassword = new JPasswordField(); |
| 85 | } |