// Copyright 1996, Marimba Inc. All Rights Reserved.


// @(#)ListBoxItemWidget.java, 1.7, 12/17/96





package marimba.gui;





import java.awt.*;





/**


 * An Item in a ListBoxWidget.


 *


 * @author	Arthur van Hoff


 * @version 	1.7, 12/17/96


 */


public class ListBoxItemWidget extends ListItemWidget {


    /**


     * The label of this listbox item.


     * @see #getText


     * @see #setText


     */


    public String  label;





    /**


     * Create an item for a ListBox


     */


    public ListBoxItemWidget(String label) {


	this.label = label;


    }





    /**


     * Get the label.


     * @see #label


     */


    public String getText() {


	return label;


    }





    /**


     * Set the label of this list item.


     * @see #label


     */


    public void setText(String label) {


	this.label = label;


	repaint();


    }








    /**


     * Get the ListBoxWidget for this item. Returns null if none is found.


     */


    protected ListBoxWidget getListBoxWidget() {


        ListWidget  listWidget = getListWidget();


	if (listWidget != null) {


	    return (ListBoxWidget) listWidget.getParent();


	}


	return null;


    }





    /**


     * The key to this widget.


     */


    public String key() {


	return label;


    }





    /**


     * Paint this item


     */


    public void paint(Graphics g, int col, int x, int y) {


	if (col == 0) {


	    g.setColor((selected) ? getSelForeground() : foreground);


	    g.drawString(label, x, y);


	}


    }


    


    /**


     * Paint the item and all of its columns.


     */


    public void paint(Graphics g) {


	super.paint(g);


	if (selected && getListBoxWidget().hasFocus()) {


	    g.setColor(getSelFocusColor());


	    Dash.drawFocusRect(g, 0, 0, width, height);


	}


    }


}


