kirk.gui.closer
Class FinishingCloser

java.lang.Object
  extended byjava.awt.event.WindowAdapter
      extended bykirk.gui.closer.WindowCloser
          extended bykirk.gui.closer.FinishingCloser
All Implemented Interfaces:
EventListener, WindowFocusListener, WindowListener, WindowStateListener

public class FinishingCloser
extends WindowCloser

This class closes Windows that generate WindowEvents asking for it. Also, it calls finish() of the class specified on construction (which must implement Finisher). This does not have to be the same class as the Window that is being closed. finish() can then do stuff before the window is being closed, and it can even stop the window from being closed by returning false. Note that this elaborate implementation does not do much more than saving you of writing some Window closing code, but it adds to encapsulation and you don't have to extend WindowAdapter if you want only closing stuff. Thus you are able to extend another class. This saves a lot of unneccesary code of implementing WindowListener. Also, it stays in line with just adding a dedicated WindowCloser. This was all I could do to make me feel I didn't write useless code (^^)

Version:
1
Author:
Berend Wouda
See Also:
Window, Finisher

Field Summary
private  Finisher finisher
          The object we will call the finish() method of before closing the passed Window.
 
Fields inherited from class kirk.gui.closer.WindowCloser
 
Constructor Summary
FinishingCloser(boolean exit, Finisher finisher)
          Constructs a FinishingCloser with the passed Finisher and the given closing option.
FinishingCloser(Finisher finisher)
          Constructs a FinishingCloser with the passed Finisher that does not end the program after closing.
 
Method Summary
 void windowClosing(WindowEvent event)
          Makes the associated Finisher do its thing and closes the passed Window.
 
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
 

Field Detail

finisher

private Finisher finisher
The object we will call the finish() method of before closing the passed Window.

Constructor Detail

FinishingCloser

public FinishingCloser(boolean exit,
                       Finisher finisher)
Constructs a FinishingCloser with the passed Finisher and the given closing option.

Parameters:
exit - true if the program should exit after closing a window, false otherwise.
finisher - The associated Finisher.

FinishingCloser

public FinishingCloser(Finisher finisher)
Constructs a FinishingCloser with the passed Finisher that does not end the program after closing.

Parameters:
finisher - The associated Finisher.
Method Detail

windowClosing

public void windowClosing(WindowEvent event)
Makes the associated Finisher do its thing and closes the passed Window.

Specified by:
windowClosing in interface WindowListener
Overrides:
windowClosing in class WindowCloser
Parameters:
event - The event that indicates which Window to close.