/*
 * saveDialog.java    97/06/26
 *
 * Modifications by BFC
 */


import java.awt.*;

/**
 * This is the program from page 96 of "Late Night Advanced Java."
 * It demonstrates the rudiments of a more or less standard dialog
 * box that gets popped up anytime you exit a file in which you
 * have made changes.  The dialog box asks if the changes should
 * be saved or cancelled before quitting.
 *
 * Note that it uses the deprecated event handling mechanism from 
 * JDK 1.0.  Event handling has been substantially changed in JDK 1.1.
 *
 * I had to make quite a few changes to get this program to compile
 * and execute under Unix.  I also tried it under Microsoft's J++; 
 * it required fewer modifications in that environment, clearly the
 * one that the author was using.
 */

public class saveDialog extends Dialog
{
    Panel bottom;				// Must not be local to the constructor

    public saveDialog( Frame parent )		// Constructor
    {
        super( parent, "Attention", false );
        System.out.println( "saveDialog.saveDialog:" );
        setSize( 300,200 );			// Set size of dialog box.  Seems necessary
        add( "Center", 				// to get box to display.
              new Label( "Save changes before quitting?" ) );
        
        bottom = new Panel();
        bottom.add( new Button( "Save" ) );
        bottom.add( new Button( "Quit" ) );
        bottom.add( new Button( "Cancel" ) );
        add( "South", bottom );
    }

    public boolean action( Event e, Object arg )
    {
        System.out.println( "saveDialog.action: e = " + e );
        if ( e.target instanceof Button )
        {
            this.hide();			// Hide and dispose of the dialog box.
            this.dispose();
            if ( e.arg == "Save" )
            {
                save();
                return true;
            }
            else if ( e.arg == "Quit" )
            {
                quit();
                return true;
            }
            else if ( e.arg == "Cancel" )
            {
                cancel();
                return true;
            }
        }
        return super.action( e,arg );
    }

    void save(){}				// Stub
    void quit(){}				// Stub
    void cancel(){}				// Stub

    public static void main( String[] arg )
    {
        Frame f = new Frame( "Main Frame" );
        f.setSize( 300,200 );
        f.show();
        saveDialog sd = new saveDialog( f );
        sd.show();
    }
}
