Orbital library

orbital.moon.awt
Class Closer

java.lang.Object
  extended by java.awt.event.WindowAdapter
      extended by orbital.moon.awt.Closer
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.event.WindowFocusListener, java.awt.event.WindowListener, java.awt.event.WindowStateListener, java.util.EventListener, Functor, Predicate

public final class Closer
extends java.awt.event.WindowAdapter
implements java.awt.event.ActionListener, Predicate

If Closer is registered to a component, it will automatically close it on user requests. On close, it will send an ActionEvent "close" to all listeners registered to Closer. If an additional parental Frame is specified, the Component is only closed on Confirmation.

A Closer registered to window events will react on closing events. When it registers to key events, it will react on the keycombos Alt-. or Alt-, or Ctrl-Break as well. Remember that, in some situations, you might have to register it to TextFields etc. by hand.

For example:

 Frame f = new Frame();
 // register to closing WindowEvents
 boolean register = true;
 // and to special KeyEvents
 // without parental Frame
 Closer closer = new Closer(f,register);
 Button b = new Button("Please Close");
 f.add(b);
 // register to Button's ActionEvents
 b.addActionListener(closer);
 

Never register a closer as an actionListener to itself.

Author:
André Platzer

Nested Class Summary
 
Nested classes/interfaces inherited from interface orbital.logic.functor.Predicate
Predicate.Composite
 
Nested classes/interfaces inherited from interface orbital.logic.functor.Functor
Functor.Specification
 
Field Summary
protected  java.awt.Component component
          the Component or Window to be closed
protected  java.awt.Frame parent
          parental frame.
 
Fields inherited from interface orbital.logic.functor.Predicate
callTypeDeclaration
 
Constructor Summary
Closer(java.awt.Component comp)
          Close instantly.
Closer(java.awt.Frame parent, java.awt.Component comp)
          Close only after confirmation dialog
Closer(java.awt.Frame parent, java.lang.String questionOnClosing, java.awt.Window comp, boolean register, boolean definitively)
          Close only after confirmation dialog; if register, self-register to WindowEvents, if definitifely force termination via System.exit().
Closer(java.awt.Frame parent, java.awt.Window comp, boolean register)
          Close only after confirmation dialog; if register, self-register to WindowEvents.
Closer(java.awt.Frame parent, java.awt.Window comp, boolean register, boolean definitively)
          Close only after confirmation dialog; if register, self-register to WindowEvents, if definitifely force termination via System.exit().
Closer(java.awt.Window comp, boolean register)
          Close instantly; if register, self-register to WindowEvents.
Closer(java.awt.Window comp, boolean register, boolean definitively)
          Close instantly; if register, self-register to WindowEvents,
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          when notified, request a close.
 void addActionListener(java.awt.event.ActionListener l)
          Adds the specified action listener to receive action events from this object.
 boolean apply(java.lang.Object a)
          Called to apply the Predicate.
 void close()
          The close action.
protected  void processActionEvent(java.awt.event.ActionEvent e)
          Processes action events occurring on this object by dispatching them to any registered ActionListener objects.
 void removeActionListener(java.awt.event.ActionListener l)
          Removes the specified action listener so that it no longer receives action events from this object.
 void requestClose()
          Request to close, but (if parent is specified) only after confirmation.
 void windowClosing(java.awt.event.WindowEvent e)
           
 
Methods inherited from class java.awt.event.WindowAdapter
windowActivated, windowClosed, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface orbital.logic.functor.Functor
equals, hashCode, toString
 

Field Detail

parent

protected java.awt.Frame parent
parental frame. If set, will ask before closing.


component

protected java.awt.Component component
the Component or Window to be closed

Constructor Detail

Closer

public Closer(java.awt.Component comp)
Close instantly.

Parameters:
comp - the component to be closed on demand.

Closer

public Closer(java.awt.Window comp,
              boolean register)
Close instantly; if register, self-register to WindowEvents.

Parameters:
comp - the component to be closed on demand.
register - whether this Closer should automatically register to comp's WindowEvents for closing events via comp.addWindowListener(this).

Closer

public Closer(java.awt.Window comp,
              boolean register,
              boolean definitively)
Close instantly; if register, self-register to WindowEvents,

Parameters:
comp - the component to be closed on demand.
register - whether this Closer should automatically register to comp's WindowEvents for closing events via comp.addWindowListener(this).
definitively - whether after a successful close action, Closer should exit the JVM via System.exit(0).

Closer

public Closer(java.awt.Frame parent,
              java.awt.Component comp)
Close only after confirmation dialog

Parameters:
parent - the frame to be used as parent for confirmation dialogs. null if no confirmation is desired.
comp - the component to be closed on demand.

Closer

public Closer(java.awt.Frame parent,
              java.awt.Window comp,
              boolean register)
Close only after confirmation dialog; if register, self-register to WindowEvents.

Parameters:
parent - the frame to be used as parent for confirmation dialogs. null if no confirmation is desired.
comp - the component to be closed on demand.
register - whether this Closer should automatically register to comp's WindowEvents for closing events via comp.addWindowListener(this).

Closer

public Closer(java.awt.Frame parent,
              java.awt.Window comp,
              boolean register,
              boolean definitively)
Close only after confirmation dialog; if register, self-register to WindowEvents, if definitifely force termination via System.exit().

Parameters:
parent - the frame to be used as parent for confirmation dialogs. null if no confirmation is desired.
comp - the component to be closed on demand.
register - whether this Closer should automatically register to comp's WindowEvents for closing events via comp.addWindowListener(this).
definitively - whether after a successful close action, Closer should exit the JVM via System.exit(0).

Closer

public Closer(java.awt.Frame parent,
              java.lang.String questionOnClosing,
              java.awt.Window comp,
              boolean register,
              boolean definitively)
Close only after confirmation dialog; if register, self-register to WindowEvents, if definitifely force termination via System.exit().

Parameters:
parent - the frame to be used as parent for confirmation dialogs. null if no confirmation is desired.
questionOnClosing - which question to ask before closing component. Will only close on affirmation.
comp - the component to be closed on demand.
register - whether this Closer should automatically register to comp's WindowEvents for closing events via comp.addWindowListener(this).
definitively - whether after a successful close action, Closer should exit the JVM via System.exit(0).
Method Detail

close

public void close()
The close action. Will send an ActionEvent "close" to all registered listeners.


requestClose

public void requestClose()
Request to close, but (if parent is specified) only after confirmation.


apply

public boolean apply(java.lang.Object a)
Description copied from interface: Predicate
Called to apply the Predicate. Evaluates to P(a).

Specified by:
apply in interface Predicate
Parameters:
a - single Object argument
Returns:
a boolean.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
when notified, request a close.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent e)
Specified by:
windowClosing in interface java.awt.event.WindowListener
Overrides:
windowClosing in class java.awt.event.WindowAdapter

processActionEvent

protected void processActionEvent(java.awt.event.ActionEvent e)
Processes action events occurring on this object by dispatching them to any registered ActionListener objects.

Parameters:
e - the action event.
See Also:
ActionListener, addActionListener(ActionListener)

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this object. If l is null, no exception is thrown and no action is performed.

Parameters:
l - the action listener
See Also:
ActionListener, removeActionListener(ActionListener)

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so that it no longer receives action events from this object. If l is null, no exception is thrown and no action is performed.

Parameters:
l - the action listener
See Also:
ActionListener, addActionListener(ActionListener)

Orbital library
1.3.0: 11 Apr 2009

Copyright © 1996-2009 André Platzer
All Rights Reserved.