// ScoreEntry.java

//
// Description:
//	  
//	  
// Author:
//	Peter Pilgrim
//	  
// RCS HEADER 
// 
// $Author$
// $Date$
// $Source$
// $Revision$    $State$    $Locker$
//
// ================================================================================
// History
//	  $Log$
// 
// 

package xenon.gamekit;

import java.awt.*;				// for Component, Graphics
import java.awt.event.*;			// for ActionEvent, ActionListener
import java.awt.image.*;			// for ImageProducer

public class ScoreEntry extends Dialog 
implements ActionListener
{
    protected TextField		tf_entryname;
    protected boolean		finished;
    protected Button		bt_ok;
    
    public ScoreEntry( int points )
    {
	this( null, points );
    }
    
    public ScoreEntry( String name, int points )
    {
	this( new Frame(), name, points );
    }
    
    public ScoreEntry( Frame frame, String name, int points )
    {
	super( frame, "High Score Entry Dialog", true /*modal*/ );
	
	setLayout( new BorderLayout() );

	/* This will cause a security exception in a sensitive browser
	   like Netscape.
	  if ( name == null )
		name = System.getProperty("user.name");
	*/
	if ( name == null ) 
	    name = "Starship Trooper";

	setBackground( Color.blue );
	setForeground( Color.white );
	
	Label label = new Label( "Enter Your Name?" );
	label.setFont( new Font( "Dialog", Font.PLAIN, 18 ));
	add( label, BorderLayout.NORTH );
	
	tf_entryname = new TextField( name ) {
	    public Dimension getPreferredSize() {
		Dimension prefSize = new Dimension( super.getPreferredSize() );
		if ( prefSize.width < 375 )
		    prefSize.width = 375;
		return (prefSize);
	    }
	};
	tf_entryname.setFont( new Font( "Dialog", Font.BOLD, 18 ));
	tf_entryname.setForeground( Color.black );
	tf_entryname.setBackground( Color.yellow );
	add( tf_entryname, BorderLayout.CENTER );

	Panel panel = new Panel();
	panel.setLayout( new FlowLayout( FlowLayout.RIGHT ) );
	
	// Button [OK]
	bt_ok = new Button("Ok");
	bt_ok.setFont( new Font( "Dialog", Font.BOLD, 14 )); 
	panel.add( bt_ok );
	add( panel, BorderLayout.SOUTH );
	
	pack();

	bt_ok.addActionListener(this);
	tf_entryname.addActionListener(this);
    }
    
    public void getEntryName( String name )
    {
	tf_entryname.setText( name);
    }
    
    public String getEntryName()
    {
	return tf_entryname.getText();
    }

    public void showEntry() 
    {
	setVisible(true);
    }
    
    public void setVisible( boolean visible )
    {
	if (visible) {
	    // Center the dialog on the screen
	    Dimension size = new Dimension(getSize());
            Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
            int x = (screen.width-size.width)/2;
            int y = (screen.height-size.height)/2;
            setBounds(x, y, size.width, size.height);
        }
	
        super.setVisible(visible);
    }
    
    /** implementation defined */
    public void actionPerformed( ActionEvent e ) 
    {
	Object src = e.getSource();
	if ( src == tf_entryname || src == bt_ok ) {
	    setVisible( false );
	    dispose();
	}
    }
    
    /** return true if the dialog is finished */
    public boolean isFinished()
    {
	return (finished);
    }
}

// fini
