package graphbrowser;

import java.awt.*;

import java.awt.event.*;
import graph.*;


public class DialogBox extends Dialog implements ActionListener
    {
    private String title;
    private Label lbl;
    private TextField inputField;
    private String inputValue;
    private Button ok;
    private Button cancel;
    private GraphPanel source;
    private int destination;

    Node node;

    public DialogBox ( String t, int i, String v, GraphPanel s, int j ,Node node, int x, int y)
    {
        super( (Frame) s.getParent(), t, true );
        title = t;
        inputValue = v;
        inputField = new TextField( v, i );
        source = s;
        destination = j;
        this.node=node;

        ok = new Button( " OK " );
        cancel = new Button( "Cancel" );
        Panel buttonPanel = new Panel();
		buttonPanel.setLayout ( new FlowLayout () );
		buttonPanel.add ( ok );
		buttonPanel.add ( cancel );
		setLayout ( new GridLayout ( 2, 1 ) );
		add ( inputField );
		add ( buttonPanel );

        ok.addActionListener(this);
        cancel.addActionListener(this);
        addWindowListener(new dwadapter(this));

		// resize( 275, 90 );

        setLocation(x,y);
		pack();
		show();
		//requestFocus();

    }  // end DialogBox Constructor

/*
    public boolean handleEvent( Event evt)
    {
        if ( evt.id == Event.WINDOW_DESTROY ) {
            dispose();
            hide();
            return true;
        }  // end if
        if ( evt.target == ok )  {
            inputValue = inputField.getText();
            source.receiveData( inputValue, destination );
            dispose();
            hide();
            pack();
            return true;
        }
        if ( evt.target == cancel)  {
            source.receiveData( inputValue, destination );
            dispose();
            hide();
            return true;
        }
        return super.handleEvent( evt );
    }  // end handleEvent

  public boolean mouseMove ( Event evt, int x, int y )
  {
        return true;
  }  // end mouseMove ( Event evt, int x, int y )

*/

  public void actionPerformed(ActionEvent e) {
        if (e.getSource() == ok) {
            inputValue = inputField.getText();
            //source.receiveData( inputValue, destination );
            source.nodeLabelFinish(node,inputValue);
            dispose();
            hide();
            pack();
        }
        if ( e.getSource() == cancel)  {
            //source.receiveData( inputValue, destination );
            dispose();
            hide();
        }


  }


}  // end DialogBox Class


// change for update to JDK1.1

class dwadapter  extends WindowAdapter {
  public Dialog source;
    public dwadapter(Dialog s) {
        this.source=s;
    }
    public void windowClosing(WindowEvent e) {
        System.out.println("Closing dialog box");
        source.dispose();
        source.hide();
    }
}