// File: TextView.java
// Classes: TextView
// Author: Kedar Patankar

package edu.neu.ccs.demeter.tools.apstudio.graphedit;

import java.awt.Frame;
import java.awt.Panel;
import java.awt.Button;
import java.awt.TextArea;
import java.awt.Event;
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Dialog;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

/* Purpose : Show the class dictionary on the fly
*/

//public class TextView extends Dialog implements ActionListener
public class TextView extends Frame implements ActionListener
{
	// Components
	Button dismiss;

	// Constructor
//	public TextView(Frame frame,String title, String text)
	public TextView(String title, String text)
	{
//		super(frame,title,true);
		super(title);
		setLayout( new BorderLayout() );
		
		// Create the Buttons
		Panel button_panel;
		dismiss = new Button( "Close" );
		dismiss.addActionListener(this);
		// Create the text area
		TextArea _text;
		_text = new TextArea(text,12,40);
		_text.setEditable(false);_text.setBackground(Color.lightGray);

		// create a button panel 
		button_panel = new Panel();
		button_panel.add( dismiss );
		
		// add the text area and the buttons to the window
		add( "Center",  _text );		
		add( "South",  button_panel );

		pack();
// jdk 1.1 type window event handling
		addWindowListener(new TVAdapter()); // using inner class for window handling.
	}
  

// jdk 1.1 style event handling. action converted to actionPerformed
	public void actionPerformed(ActionEvent event)
	{
		close();
	}

	private void close() { setVisible(false);dispose(); }

/*	public void setVisible(boolean status)
	{
		if(status)
		{
			dismiss.requestFocus();
			Dimension frameSize = getParent().getSize();
			Point     frameLoc  = getParent().getLocation();
			Dimension mySize    = getSize();
			int       x,y;

			x = frameLoc.x + (frameSize.width/2) -(mySize.width/2); 
			y = frameLoc.y + (frameSize.height/2)-(mySize.height/2); 
			setBounds(x,y,getSize().width,getSize().height);
		}
		super.setVisible(status);
	}
*/	
// inner class VDAdapter

	class TVAdapter extends WindowAdapter
	{
		public void windowClosing(WindowEvent event)
		{
			close();
		}
	}
} /* end class TextView */

