Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/voytechs/example/desktop/LoginPanel.java


1   /* 
2    * File: LoginPanel.java 
3    * Auth: Mark Bednarczyk 
4    * Date: DATE 
5    *   Id: $Id: LoginPanel.java,v 1.1.1.1 2002/01/23 23:52:50 voytechs Exp $
6    ********************************************
7    * $Log: LoginPanel.java,v $
8    * Revision 1.1.1.1  2002/01/23 23:52:50  voytechs
9    * Initial public release, BETA 1.0 - voytechs
10   *
11   */
12  package com.voytechs.example.desktop;
13  
14  import com.voytechs.html.component.*;
15  import com.voytechs.html.event.*;
16  import com.voytechs.html.util.LogFacility;
17  
18  import java.lang.*;
19  import java.util.*;
20  import java.io.*;
21  
22  /**
23   * A two state button. When no user is logged in the default
24   * login button displayes 'Login' text. By clicking on the Login
25   * element, a Login popup is displayed on the client. After a user has
26   * logged in, this element automatically turns off the login button and
27   * displays its second button, the profile button. This has the effect
28   * of at first seeing a Login then a Profile button immediately after the
29   * login. The displayed simple elements can be replaced by using the 
30   * addLoginElement() and addProfileElement() methods.
31   */
32  public class LoginPanel 
33    extends Panel {
34  
35    /* Internal attributes */
36  
37    private Link loginButton = null;
38    private LinkComponent profileButton = null;
39    private String userName = "";
40  
41    /**
42     * Prebuild the static structure of the control panel.
43     */
44    public LoginPanel() throws EventException {
45  
46      addElement(loginButton = new LoginButton().addElement(
47          new Text("Login")));
48      addElement(profileButton = new Link().addElement(
49          new Text("Profile")));
50  
51      profileButton.show(false);
52    }
53  
54    /**
55     *
56     */
57    protected void process() {
58      LogFacility.log.println("ContronPanel::process() - profileButton.show()=" + 
59                              profileButton.show() + 
60                              " isUserLoggedIn()=" + 
61                              getRootFrame().isUserLoggedIn());
62  
63      if((profileButton.show() == false && getRootFrame().isUserLoggedIn()) ||
64         (getRootFrame().isUserLoggedIn() && 
65          userName.equals(getRootFrame().getUserName()) == false)) {
66  
67         userName = getRootFrame().getUserName();
68  
69        loginButton.show(false);
70  
71        profileButton.show(true);
72      }
73    }
74  
75    /**
76     * Adds a simple textual/graphical element to the Login button.
77     * The element is displayed when no user is logged in. The show(false) is
78     * called when a user login is detected at which time the profile element
79     * is displayed.
80     */
81    public void addLoginElement(SimpleComponent loginElement)
82        throws EventException {
83  
84      loginButton.addElement(loginElement);
85    }
86  
87    /**
88     * Adds a simple textual/graphical element to the Profile button.
89     * The element is displayed when a user is logged in. Normally this button
90     * is not displayed when no user is logged in. 
91     */
92    public void addProfileElement(LinkComponent profileElement)
93        throws EventException {
94  
95      // remove the current element from the LoginPanel
96      if(profileButton != null);
97        removeElement(profileButton);
98  
99      profileButton = profileElement;
100     addElement(profileElement);
101   }
102 
103   /**
104    * Test function for LoginPanel
105    * @param args command line arguments
106    */
107   public static void main(String [] args) {
108   }
109 
110 } /* END OF: LoginPanel */