// ClosableFrame.java
// $Id: ClosableFrame.java,v 1.2 1998/10/01 10:44:02 bmahe Exp $
// (c) COPYRIGHT MIT and INRIA, 1998.
// Please first read the full copyright statement in file COPYRIGHT.html
 
package org.w3c.tools.widgets;

import java.awt.*;
import java.awt.event.*;

/**
 * @version $Revision: 1.2 $
 * @author  Benoît Mahé (bmahe@w3.org)
 */
abstract public class ClosableFrame extends Frame {
    
    class WindowCloser extends WindowAdapter {

	ClosableFrame frame = null;
	
	public void windowClosing(WindowEvent e) {
	    if (e.getWindow() == frame)
		frame.close();
	}

	WindowCloser(ClosableFrame frame) {
	    this.frame = frame;
	}
    }

    protected abstract void close();

    public ClosableFrame() {
	super();
	build();
    }

    public ClosableFrame(String title) {
	super(title);
	build();
    }

    private void build() {
	addWindowListener(new WindowCloser(this));
	setBackground(Color.lightGray);
    }

}
