XEasterEgg.java :  » XML-UI » xui32 » com » xoetrope » awt » Java Open Source

Java Open Source » XML UI » xui32 
xui32 » com » xoetrope » awt » XEasterEgg.java
package com.xoetrope.awt;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import net.xoetrope.awt.XImage;
import com.xoetrope.event.XClickListener;
import net.xoetrope.xui.XAttributedComponent;
import net.xoetrope.xui.XProjectManager;

/**
 * An easter eggs is a special control used to obscure access to certain
 * functionality. Frequently it is used to control access to superuser mode
 * menus and actions. In a modal/fullscreen application it may obscure access
 * to the exit/shutdown functionality. A password can also be added to further
 * protect access.
 * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
 * the GNU Public License (GPL), please see license.txt for more details. If
 * you make commercial use of this software you must purchase a commercial
 * license from Xoetrope.</p>
 * <p>$Revision: 1.4 $</p>
 */
public class XEasterEgg extends XImage implements XAttributedComponent, ActionListener
{
  String password = "";
  XClickListener clickListener;

  public XEasterEgg()
  {
    super();
    clickListener = new XClickListener( this );
    if ( currentProject.getAppFrame() != null )
      addMouseListener( clickListener );
    clickListener.addActionListener( this );
  }

  /**
   * Set one or more attributes of the component.
   * @param attribName the name of the attribute
   * @param attribValue the value of the attribute
   */
  public void setAttribute( String attribName, String attribValue )
  {
    if ( attribName.compareToIgnoreCase( "password" ) == 0 )
      password = attribValue;
  }

  /**
   * Pops up a password dialog and exits the survey if the password matches
   * @param e
   */
  public void actionPerformed( ActionEvent e )
  {
    XPasswordDlg passwordDlg = new XPasswordDlg( );
    passwordDlg.showDialog( getParent(), null );
    if ( passwordDlg.getPassword().compareTo( password ) == 0 )
      exitSurvey();
    passwordDlg = null;
  }

  /**
   * Exist the survey and shuts down the application
   */
  public void exitSurvey()
  {
    System.exit( 0 );
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.