// ImageCommentDialog.py : Dialog box for adding comments to an image
//
// Distributed under the terms described in the LICENCE file.
//
// Developed by akuchlin@mems-exchange.org
//
// Presents the user with a text area for entering comments about an
// image.

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

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

    private TextArea textarea;
    private Button ok_button, cancel_button;
    public String comments;

    public ImageCommentDialog (Frame parent) {
        // Initialize as a modal dialog
        super(parent, "Image Comments", true);

        this.textarea = new TextArea("", 6, 20);
        this.comments = null;
        
        this.setLayout( new BorderLayout() );
        this.add("North", new Label("Comments on this image") );
        this.add("Center", this.textarea );

        Panel p = new Panel();
	p.setLayout( new BorderLayout() );
        this.ok_button = new Button("OK");
        this.cancel_button = new Button("Cancel");
        p.add("West", this.ok_button);
        p.add("East", this.cancel_button);

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

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