001 /*****************************************************************************
002
003 jBudget.
004 Copyright (C) Dmitri Petrov
005
006 This program is free software: you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation, either version 3 of the License, or
009 (at your option) any later version.
010
011 This program is distributed in the hope that it will be useful,
012 but WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014 GNU General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with this program. If not, see <http://www.gnu.org/licenses/>.
018
019 *****************************************************************************/
020
021 package org.jbudget.gui.user;
022
023 import java.awt.BorderLayout;
024 import org.jbudget.Core.User;
025 import org.jbudget.gui.templ.LoginPanelTempl;
026 import org.jbudget.gui.user.UserSelectorPanel.UserSelectionListener;
027
028 public class LoginPanel extends LoginPanelTempl implements UserSelectionListener
029 {
030
031 /** Panel for selecting the user. */
032 private final UserSelectorPanel userPanel;
033
034 /** Selected uid. */
035 private int selectedUid = -1;
036
037 /** Constructor */
038 LoginPanel()
039 {
040 UserSelectorModel model = new UserSelectorModel();
041 model.addToList(User.SYSTEM);
042 userPanel = new UserSelectorPanel(model);
043 userPanelHolder.setLayout(new BorderLayout());
044 userPanelHolder.add(userPanel, BorderLayout.CENTER);
045
046 userPanel.addListener(this);
047 }
048
049 public void dispose()
050 {
051 userPanel.dispose();
052 }
053
054 /** Called when a user with a given uid is selected. */
055 public void userSelected(int uid) {
056 selectedUid = uid;
057 }
058
059 /** Returns the UID of a selected user or, -1 if no selection was made. */
060 public int getSelectedUid() {
061 return selectedUid;
062 }
063
064 /** Returns the password that was entered by the user. */
065 public String getPasswd()
066 {
067 String passwd = new String("");
068 try {
069 passwd = new String(passwdField.getPassword());
070 } catch (NullPointerException ex){}
071 return passwd;
072 }
073 }