01: package jimm.datavision.gui.parameter;
02:
03: import jimm.datavision.Parameter;
04: import java.util.Iterator;
05: import javax.swing.*;
06:
07: /**
08: * A single-choice string list inquisitor knows how to display and control
09: * the widgets needed to ask a user for a single string parameter value from
10: * a list.
11: *
12: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
13: */
14: class ListStringInq extends Inquisitor {
15:
16: protected JList list;
17:
18: ListStringInq(Parameter param, boolean allowMultipleSelection) {
19: super (param);
20:
21: // Build GUI
22: Box box = Box.createVerticalBox();
23:
24: DefaultListModel model = new DefaultListModel();
25: list = new JList(model);
26: list
27: .setSelectionMode(allowMultipleSelection ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
28: : ListSelectionModel.SINGLE_SELECTION);
29: box.add(list);
30:
31: panel.add(box);
32:
33: // Copy default value into "real" value
34: for (Iterator iter = parameter.defaultValues(); iter.hasNext();)
35: model.addElement(iter.next());
36:
37: if (!allowMultipleSelection)
38: list.setSelectedIndex(0); // Select first item
39: }
40:
41: void copyGUIIntoParam() {
42: int[] is = list.getSelectedIndices();
43: parameter.removeValues();
44: for (int i = 0; i < is.length; ++i)
45: parameter.setValue(i, parameter.getDefaultValue(is[i]));
46: }
47:
48: void copyParamIntoGUI() {
49: list.clearSelection();
50: boolean first = true;
51: for (Iterator iter = parameter.values(); iter.hasNext();) {
52: list.setSelectedValue(iter.next(), first); // Scroll if first
53: first = false;
54: }
55: }
56:
57: }
|