com.croftsoft.core.gui
Class LifecycleWindowListener

java.lang.Object
  extended by com.croftsoft.core.gui.LifecycleWindowListener
All Implemented Interfaces:
WindowListener, EventListener

public final class LifecycleWindowListener
extends Object
implements WindowListener

Calls the lifecycle methods in response to windowing events.

When the window is activated, calls the start() methods. When the window is deactivated, calls the stop() methods. The first time the window is activated, the init() method will be called.

Performs the following upon the window closing event:

  1. Prompts for shutdown confirmation.
  2. Calls the window hide() method.
  3. Calls the stop and destroy() method, in array order, of each of the Lifecycle instances passed via the constructor argument. Any exceptions are caught, printed, and ignored.
  4. Calls the window dispose() method.
  5. Calls System.exit(0).

Example:

 jFrame.setDefaultCloseOperation (
   javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE );

 jFrame.addWindowListener (
   new LifecycleWindowListener ( this, "Exit Program?" ) );
 

Since:
2002-12-24
Version:
$Date: 2006/01/03 20:05:54 $
Author:
David Wallace Croft

Constructor Summary
LifecycleWindowListener(Lifecycle lifecycle)
          Convenience constructor.
LifecycleWindowListener(Lifecycle[] lifecycles)
          Convenience constructor.
LifecycleWindowListener(Lifecycle[] lifecycles, String shutdownConfirmationPrompt)
          Convenience constructor.
LifecycleWindowListener(Lifecycle[] lifecycles, String shutdownConfirmationPrompt, String shutdownConfirmationTitle)
          Main constructor.
LifecycleWindowListener(Lifecycle lifecycle, String shutdownConfirmationPrompt)
          Convenience constructor.
 
Method Summary
static void launchAppletAsDesktopApp(JApplet applet, String frameTitle, String frameIconFilename, ClassLoader classLoader, boolean useFullScreenToggler, Dimension frameSize, String shutdownConfirmationPrompt)
           
static void launchFrameAsDesktopApp(JFrame jFrame, Lifecycle[] lifecycles, Dimension frameSize, String shutdownConfirmationPrompt)
          Associates a LifecycleWindowListener with the JFrame and launches.
static void launchFrameAsDesktopApp(JFrame jFrame, Lifecycle lifecycle, Dimension frameSize, String shutdownConfirmationPrompt)
           
static void main(String[] args)
          Test and demonstration method.
 void windowActivated(WindowEvent windowEvent)
           
 void windowClosed(WindowEvent windowEvent)
           
 void windowClosing(WindowEvent windowEvent)
           
 void windowDeactivated(WindowEvent windowEvent)
           
 void windowDeiconified(WindowEvent windowEvent)
           
 void windowIconified(WindowEvent windowEvent)
           
 void windowOpened(WindowEvent windowEvent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LifecycleWindowListener

public LifecycleWindowListener(Lifecycle[] lifecycles,
                               String shutdownConfirmationPrompt,
                               String shutdownConfirmationTitle)
Main constructor.

Parameters:
lifecycles - May be null.
shutdownConfirmationPrompt - If null, no shutdown confirmation prompt dialog will be given.
shutdownConfirmationTitle - If null, the shutdownConfirmationPrompt value will be used.

LifecycleWindowListener

public LifecycleWindowListener(Lifecycle[] lifecycles,
                               String shutdownConfirmationPrompt)
Convenience constructor.
 this ( lifecycles, shutdownConfirmationPrompt, null );
 


LifecycleWindowListener

public LifecycleWindowListener(Lifecycle lifecycle,
                               String shutdownConfirmationPrompt)
Convenience constructor.
 this (
   new Lifecycle [ ] { lifecycle },
   shutdownConfirmationPrompt );
 


LifecycleWindowListener

public LifecycleWindowListener(Lifecycle[] lifecycles)
Convenience constructor.
 this ( lifecycles, null );
 


LifecycleWindowListener

public LifecycleWindowListener(Lifecycle lifecycle)
Convenience constructor.
 this ( new Lifecycle [ ] { lifecycle } );
 

Method Detail

main

public static void main(String[] args)
Test and demonstration method.


launchFrameAsDesktopApp

public static void launchFrameAsDesktopApp(JFrame jFrame,
                                           Lifecycle[] lifecycles,
                                           Dimension frameSize,
                                           String shutdownConfirmationPrompt)
Associates a LifecycleWindowListener with the JFrame and launches.

In order to create a flexible JFrame subclass that can be run either as a stand-alone desktop application by itself or as a pop-up frame called from a currently running program, you will need to maintain the logic for handling these different modes of operation outside of the subclass itself. This method provides the logic for running a JFrame subclass as an independent desktop application.

This method associates a LifecycleWindowAdapter with the JFrame which will call the lifecycle methods in response to windowing events. It then launches the JFrame on the center of the screen.

Parameters:
lifecycles - An optional array of Lifecycle objects to initialized upon startup, started upon window activation, stopped upon window deactivation, and destroyed upon shutdown. May be null.
frameSize - If null, a default value will be used based upon screen size.
shutdownConfirmationPrompt - If null, no confirmation prompt will be given.
See Also:
Lifecycle

launchFrameAsDesktopApp

public static void launchFrameAsDesktopApp(JFrame jFrame,
                                           Lifecycle lifecycle,
                                           Dimension frameSize,
                                           String shutdownConfirmationPrompt)

launchAppletAsDesktopApp

public static void launchAppletAsDesktopApp(JApplet applet,
                                            String frameTitle,
                                            String frameIconFilename,
                                            ClassLoader classLoader,
                                            boolean useFullScreenToggler,
                                            Dimension frameSize,
                                            String shutdownConfirmationPrompt)

windowActivated

public void windowActivated(WindowEvent windowEvent)
Specified by:
windowActivated in interface WindowListener

windowClosed

public void windowClosed(WindowEvent windowEvent)
Specified by:
windowClosed in interface WindowListener

windowClosing

public void windowClosing(WindowEvent windowEvent)
Specified by:
windowClosing in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent windowEvent)
Specified by:
windowDeactivated in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent windowEvent)
Specified by:
windowDeiconified in interface WindowListener

windowIconified

public void windowIconified(WindowEvent windowEvent)
Specified by:
windowIconified in interface WindowListener

windowOpened

public void windowOpened(WindowEvent windowEvent)
Specified by:
windowOpened in interface WindowListener

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)