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


// @(#)DropDownComboBoxWidget.java, 1.15, 11/29/96





package marimba.gui;





import java.awt.*;


import java.util.*;





import marimba.persist.*;





/**


 * A text widget with an associated pull down menu.


 *


 * @author	Arthur van Hoff


 * @version 	1.15, 11/29/96


 */


public class DropDownComboBoxWidget extends DropDownListBoxWidget {


    /**


     * Constructor.


     */


    public DropDownComboBoxWidget() {


    }





    /**


     * Constructor that initializes some variables.


     */


    public DropDownComboBoxWidget(String value, int style, int align, String list) {


	super(value, style, align, list);


    }





    /**


     * Set value.


     */


    public void setValue(String value) {


	super.setValue(value);


	if (text != null) {


	    text.setText(value);


	}


    }





    /**


     * Get value.


     */


    public String getStringValue() {


	if (text != null) {


	    String str = text.getText().trim();


	    return (str.length() == 0) ? null : str;


	}


	return super.getStringValue();


    }





    /**


     * New TextBox that is editable.


     */


    protected DropDownTextBoxWidget newTextBox() {


	DropDownTextBoxWidget text = super.newTextBox();


	text.setEditable(true);


	return text;


    }





    /**


     * Display and return a new dropdown that also paints


     * a focus rectangle around a selected item.


     */


    protected DropDownMenu newDropDown() {


	DropDownMenu  dropDown = super.newDropDown();


	dropDown.setItemFocus(false);


	return dropDown;


    }





    /**


     * Handle events.


     */


    public boolean handleEvent(Event evt) {


	switch (evt.id) {


	    case Event.MOUSE_DOWN:


		boolean  onButton = ((Boolean)evt.arg).booleanValue();


		if (!onButton) {


		    return false;


		}


		break;





	    case Event.KEY_ACTION:


		switch (evt.key) {


		    case Event.DOWN:


		    case Event.UP:


			newDropDown().requestFocus();


			return true;


		}


		break;


	}


	return super.handleEvent(evt);


    }


}


