/************************************************************************
 * This library is free software; you can redistribute it and/or        *
 * modify it under the terms of the GNU Library General Public          *
 * License as published by the Free Software Foundation; either         *
 * version 2 of the License, or (at your option) any later version.     *
 *                                                                      *
 * This library is distributed in the hope that it will be useful,      *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    *
 * Library General Public License for more details.                     *
 *                                                                      *
 * You should have received a copy of the GNU Library General Public    *
 * License along with this library; if not, write to the                *
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,         *
 * Boston, MA  02111-1307, USA.                                         *
 *                                                                      *
 * The GNU Library General Public License file is included in           *
 * Online-Documentation                                                 *
 *                                                                      *
 * GNU's Homepage - http://www.gnu.org/                                 *
 *                                                                      *
 * Questions & comments referring to Hexi: please contact us:           *
 *                                                                      *
 * eMail:                                                               *
 *      ramsey@dbai.tuwien.ac.at                                        *
 * WWW:                                                                 *
 *      http://www.dbai.tuwien.ac.at/proj/ramsey/                       *
 *                                                                      *
 * (c) Wolfgang Slany 1987, Bidan Zhu 1996, Andreas Beer 1999           *
 * HallofFame.java                Version 2.3                18.08.1999 *
 ***********************************************************************/

import java.awt.*;
import java.io.*;

public class HallofFame extends Dialog
{
	Hexi hexi;
	HexiClient Hexi_Client = null;
	DialogLayout m_Layout;

	// Control definitions
	//--------------------------------------------------------------------------
	Button        OK;
	TextField     NameBox;
	Label         Lbl1;
	Label         Lbl2;
	Label         Lbl3;

	// Constructor
	//--------------------------------------------------------------------------
	public HallofFame (Hexi parent, Frame f,long time)
	{
		super(f,"Add to the Hall of Fame?",true);
		hexi = parent;
		setBackground(hexi.GRAY);

		// Since a given font may not be supported across all platforms, it
		// is safe to modify only the size of the font, not the typeface.
		//----------------------------------------------------------------------
		Font OldFnt = getFont();
		if (OldFnt != null)
		{
			Font NewFnt = new Font(OldFnt.getName(), OldFnt.getStyle(), 13);
			setFont(NewFnt);
		}

		// All position and sizes are in dialog logical units, so we use a
		// DialogLayout as our layout manager.
		//----------------------------------------------------------------------
		m_Layout = new DialogLayout((Container)this, 236, 172);
		setLayout(m_Layout);
		addNotify();
		Dimension size   = m_Layout.getDialogSize();
		Insets    insets = insets();

		resize(insets.left + size.width  + insets.right,insets.top  + size.height + insets.bottom);

		// Control creation
		//----------------------------------------------------------------------
		Lbl3 = new Label ("You win with score "+time+"!", Label.CENTER);
		add(Lbl3);
		m_Layout.setShape(Lbl3, 19, 16, 170, 11);
		Lbl2 = new Label ("Would you like to be included in the Hall of Fame?", Label.LEFT);
		add(Lbl2);
		m_Layout.setShape(Lbl2, 19, 34, 200, 19);
		Lbl1 = new Label ("Your name:", Label.LEFT);
		add(Lbl1);
		m_Layout.setShape(Lbl1, 30, 63, 41, 10);
		NameBox = new TextField ("");
		add(NameBox);
		m_Layout.setShape(NameBox, 74, 61, 83, 18);
		OK = new Button ("OK");
		add(OK);
		m_Layout.setShape(OK, 85, 98, 32, 14);
	}

	public boolean action(Event evt, Object obj)
	{
		if (evt.target == OK)
		{
			String name = NameBox.getText();
			if (name.length() != 0)
			{
				if (Hexi_Client == null || !Hexi_Client.isAlive())
				{
					Hexi_Client = new HexiClient(hexi,name,hexi.PlayTime);
					Hexi_Client.start();
				}
				dispose();
			}
		}
		return true;
	}

	public boolean handleEvent(Event evt)
	{
		if (evt.id == Event.WINDOW_DESTROY)
		{
			dispose();
			return true;
		}
		return super.handleEvent(evt);
	}
}