// Copyright 1996, Marimba Inc. All Rights Reserved.
// @(#)HighScore.java, 1.1, 11/21/96

package wordsmith;

import java.util.*;
import java.awt.*;
import marimba.gui.*;

/**
 * Comment here
 *
 * @author      Carl W. Haynes III
 * @version     1.1, 11/21/96
 */

public class HighScore extends ListItemWidget {
    Date date;
    int score = 0;
    String name = "name";
    String email = "email";

    FontMetrics fm = null;

    /** default constructor */
    public HighScore() {
	this(0, "none", "none", new Date());
    }

    /** primary constructor */
    public HighScore(int score, String name, String email, Date date) {
	this.score = score;
	this.name = name;
	this.date = date;
	this.email = email;
    }

    /** returns score */
    public int getScore() {
	return(score);
    }

    /** returns name */
    public String getName() {
	return(name);
    }

    /** returns name */
    public String getEmail() {
	return(email);
    }

    /** returns date */
    public Date getDate() {
	return(date);
    }

    /**
     * Draw a column of this item. The x,y position is
     * the baseline on the left most edge of the item.
     */
    public void paint(Graphics g, int col, int x, int y) {
	if (fm == null)
	    fm = g.getFontMetrics();

	switch(col) {
	  case 0:
	    int rank = getListWidget().indexOf(this) + 1; 
	    g.drawString(""+rank, x, y);
	    break;
	  case 1:
	    String tmp = name;
	    int strw = fm.stringWidth(name);
	    int colw = getColumnWidth(col);
	    if (strw > colw) {
		tmp = tmp.substring(0, tmp.length()-1);
		while (fm.stringWidth(tmp+"...") > colw) {
		    tmp = tmp.substring(0, tmp.length()-1);
		}
		tmp += "...";
	    } 
	    g.drawString(tmp, x, y);
	    break;
	  case 2:
	    tmp = email;
	    strw = fm.stringWidth(email);
	    colw = getColumnWidth(col);
	    if (strw > colw) {
		tmp = tmp.substring(0, tmp.length()-1);
		while (fm.stringWidth(tmp+"...") > colw) {
		    tmp = tmp.substring(0, tmp.length()-1);
		}
		tmp += "...";
	    } 
	    g.drawString(tmp, x, y);
	    break;
	  case 3:
	    g.drawString(""+score, x, y);
	    break;
	}
    }
    


    /** debugging */
    public String toString() {
	return(name + "\t" + email + "\t" + score + "\t" + date.getTime());
    }
}

