/* * File: LoginPanel.java * Auth: Mark Bednarczyk * Date: DATE * Id: $Id$ ******************************************** * $Log$ */ package voytechs.tool.desktop; import voytechs.security.user.UserProfile; import voytechs.html.component.*; import voytechs.html.event.*; import voytechs.util.event.*; import voytechs.tool.LogFacility; import java.lang.*; import java.util.*; import java.io.*; /** * A two state button. When no user is logged in the default * login button displayes 'Login' text. By clicking on the Login * element, a Login popup is displayed on the client. After a user has * logged in, this element automatically turns off the login button and * displays its second button, the profile button. This has the effect * of at first seeing a Login then a Profile button immediately after the * login. The displayed simple elements can be replaced by using the * addLoginElement() and addProfileElement() methods. */ public class LoginPanel extends Panel { /* Internal attributes */ private Link loginButton = null; private LinkComponent profileButton = null; private String userName = ""; /** * Prebuild the static structure of the control panel. */ public LoginPanel() throws EventException { addElement(loginButton = new LoginButton().addElement( new Text("Login"))); addElement(profileButton = new Link().addElement( new Text("Profile"))); profileButton.show(false); } /** * */ protected void process() { LogFacility.log.println("ContronPanel::process() - profileButton.show()=" + profileButton.show() + " isUserLoggedIn()=" + getRootFrame().isUserLoggedIn()); if((profileButton.show() == false && getRootFrame().isUserLoggedIn()) || (getRootFrame().isUserLoggedIn() && userName.equals(getRootFrame().getUserName()) == false)) { userName = getRootFrame().getUserName(); loginButton.show(false); profileButton.show(true); } } /** * Adds a simple textual/graphical element to the Login button. * The element is displayed when no user is logged in. The show(false) is * called when a user login is detected at which time the profile element * is displayed. */ public void addLoginElement(SimpleComponent loginElement) throws EventException { loginButton.addElement(loginElement); } /** * Adds a simple textual/graphical element to the Profile button. * The element is displayed when a user is logged in. Normally this button * is not displayed when no user is logged in. */ public void addProfileElement(LinkComponent profileElement) throws EventException { // remove the current element from the LoginPanel if(profileButton != null); removeElement(profileButton); profileButton = profileElement; addElement(profileElement); } /** * Test function for LoginPanel * @param args command line arguments */ public static void main(String [] args) { } } /* END OF: LoginPanel */