package extensions.awt; import java.awt.*; import java.util.*; /** * Delegate List action event. * * @see java.awt.List * @see extensions.awt.ActionProtocol * @version 1.0.2 * @author John Webster Small */ public class ListAction extends List implements ActionProtocol { private ActionProtocol ap; private Hashtable items; /** Construct a ListAction (i.e. a List) with * the action to be performed when this List is * clicked. The action is performed automatically * only if this ListAction appears within an * FrameExtended or DialogExtended window. * @param ap action to be performed, i.e. run() * @see extensions.awt.FrameExtended * @see extensions.awt.DialogExtended * @see extensions.awt.ActionProtocol */ public ListAction(ActionProtocol ap) { super(); this.ap = ap; } /** Construct a ListAction, e.g. a list. */ public ListAction() { this(null); } /** Construct a ListAction (i.e. a List) with * the action to be performed when this List is * clicked. The action is performed automatically * only if this ListAction appears within an * FrameExtended or DialogExtended window. * @param rows number of items to show * @param multipleSelections if true multiple selections are allowed * @param ap action to be performed, i.e. run() * @see extensions.awt.FrameExtended * @see extensions.awt.DialogExtended * @see extensions.awt.ActionProtocol */ public ListAction (int rows, boolean multipleSelections, ActionProtocol ap) { super(rows,multipleSelections); this.ap = ap; } /** Construct a ListAction, e.g. a list. * @param rows number of items to show * @param multipleSelections if true multiple selections are allowed */ public ListAction(int rows, boolean multipleSelections) { this(rows,multipleSelections,null); } /** Forward the list clicked action event on to * the action for further processing by the application * model rather than the GUI. This method is called * automatically by FrameExtended and DialogExtended. * @param forward the component forwarding action event * @param evt the event that caused the action * @param what the action * @see extensions.awt.ActionProtocol * @see extensions.awt.FrameExtended#handleEvent * @see extensions.awt.DialogExtended#handleEvent */ public final void action(Component forward, Event evt, Object what) { if (ap != null) ap.action(forward,evt,what); } /** Reset list from dictionary of items. * @param items dictionary of items, keys are strings to be displayed by list */ public void setItems(Hashtable items) { this.items = items; Enumeration itemNames = items.keys(); clear(); while (itemNames.hasMoreElements()) addItem((String)itemNames.nextElement()); } /** Returns a dictionary of selected items. */ public Hashtable getSelections() { Hashtable selected = new Hashtable(); if (items != null) { String[] keys = getSelectedItems(); String key; for (int i = 0; i < keys.length; i++) { key = keys[i]; selected.put(key,items.get(key)); } } return selected; } /** @return true if any selections outstanding. */ public boolean anySelected() { int[] idxs = getSelectedIndexes(); if (getSelectedIndex() >= 0 || idxs != null || idxs.length > 0) return true; return false; } }