package extensions.awt; import java.awt.*; import java.util.*; /** * Generic pick list modal dialog. * @version 1.0.2 * @author John Webster Small */ public class PickListDialog extends ButtonDialog { private ListAction choices; /** * Construct a Picklist modal dialog. * @param parent dialog's parent frame * @param title title of dialog * @param items dictionary of choices, the key is displayed * @see extensions.awt.ButtonDialog */ public PickListDialog (Frame parent, String title, Hashtable items) { super(parent,title,OkCancel); choices = new ListAction(this); setItems(items); add("Center",choices); pack(); } /** * Construct a Picklist modal dialog. * @param parent dialog's parent frame * @param title title of dialog * @param items dictionary of choices, the key is displayed * @see extensions.awt.ButtonDialog */ public PickListDialog (Frame parent, String title, int rows, boolean multipleSelections, Hashtable items) { super(parent,title,OkCancel); choices = new ListAction(rows,multipleSelections,this); setItems(items); add("Center",choices); pack(); } /** Required by ActionProtocol interface, not called by user. */ public void action(Component forward, Event evt, Object what) { if (evt.target == choices && evt.id == Event.ACTION_EVENT) { setClickedIdx(0); // programmatically click "OK" destroy(); } else super.action(forward,evt,what); } /** Show pick list dialog. */ public void show() { choices.requestFocus(); super.show(); } /** Set multiple selections on choice list. */ public void setMultipleSelections(boolean v) { choices.setMultipleSelections(v); } /** Reset list from dictionary of items. * @param items dictionary of items, keys are strings to be displayed by list */ public void setItems(Hashtable items) { choices.setItems(items); } /** Returns a dictionary of selected items. */ public Hashtable getSelections() { return choices.getSelections(); } }