// BrokenConnectionDialog.py : Dialog box used when the connection gets broken
//
// Distributed under the terms described in the LICENCE file.
//
// Developed by akuchlin@mems-exchange.org
//
// Presents the user with the option of exiting or reconnecting 
// to the server.

import java.awt.*;
import java.awt.Event;

public class BrokenConnectionDialog extends Dialog {
    static String __revision__ = "$Id: BrokenConnectionDialog.java,v 1.3 2001/12/17 19:33:36 akuchlin Exp $";

    private Button reconnect_button, exit_button;
    public boolean reconnect;

    public BrokenConnectionDialog (Frame parent, String hostname) {
        // Initialize as a modal dialog
        super(parent, "Connection Broken", true);

        this.setLayout( new BorderLayout() );
        this.add("North", 
		 new Label("The connection to the microscope server " + 
			   hostname + 
			   " cannot be made."));
	this.add("Center", new Label("Do you want to " +
				     "try connecting again, or exit?") );

        Panel p = new Panel();
	p.setLayout( new BorderLayout() );
        this.reconnect_button = new Button("Reconnect");
        this.exit_button = new Button("Exit");
        p.add("West", this.reconnect_button);
        p.add("East", this.exit_button);

	this.add("South", p);
    }

    public boolean handleEvent(Event e) {
        if (e.id == Event.WINDOW_DESTROY) {
            this.dispose();
            this.reconnect = false;
            return true;
	}
	else if (e.id == Event.ACTION_EVENT &&
		 (e.target instanceof Button) ) {
            if (e.arg.equals("Reconnect"))
                {this.reconnect = true;}
            else 
		{this.reconnect = false;}
	    
            this.dispose();
	    return true;
	}
	return false;
    }
}
