001: package jimm.datavision.gui.parameter;
002:
003: import jimm.datavision.Parameter;
004: import jimm.util.I18N;
005: import javax.swing.*;
006:
007: /**
008: * An inquisitor knows how to display and control the widgets needed
009: * to ask a user for parameter values. Inquisitors are used in
010: * {@link ParamAskWin}s.
011: *
012: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
013: */
014: abstract class Inquisitor {
015:
016: protected static final int TEXT_FIELD_COLS = 24;
017:
018: protected static int instanceCount;
019: protected Parameter parameter;
020: protected JPanel panel;
021: protected String panelName;
022:
023: /**
024: * This factory method returns the proper inquisitor for the specified
025: * parameter.
026: *
027: * @param param a parameter
028: */
029: public static Inquisitor create(Parameter param) {
030: if (!param.isLegal(param.getType(), param.getArity())) {
031: // Should not happen
032: String str = I18N.get("Inquisitor.param_cap") + ' '
033: + param.getName() + ' '
034: + I18N.get("Inquisitor.illegal");
035: throw new IllegalArgumentException(str);
036: }
037:
038: switch (param.getType()) {
039: case Parameter.TYPE_BOOLEAN:
040: return new BoolInq(param);
041: case Parameter.TYPE_STRING:
042: switch (param.getArity()) {
043: case Parameter.ARITY_ONE:
044: return new SingleStringInq(param);
045: case Parameter.ARITY_RANGE:
046: return new RangeStringInq(param);
047: case Parameter.ARITY_LIST_SINGLE:
048: return new ListStringInq(param, false);
049: case Parameter.ARITY_LIST_MULTIPLE:
050: return new ListStringInq(param, true);
051: }
052: break;
053: case Parameter.TYPE_NUMERIC:
054: switch (param.getArity()) {
055: case Parameter.ARITY_ONE:
056: return new SingleNumericInq(param);
057: case Parameter.ARITY_RANGE:
058: return new RangeNumericInq(param);
059: case Parameter.ARITY_LIST_SINGLE:
060: return new ListNumericInq(param, false);
061: case Parameter.ARITY_LIST_MULTIPLE:
062: return new ListNumericInq(param, true);
063: }
064: break;
065: case Parameter.TYPE_DATE:
066: switch (param.getArity()) {
067: case Parameter.ARITY_ONE:
068: return new SingleDateInq(param);
069: case Parameter.ARITY_RANGE:
070: return new RangeDateInq(param);
071: }
072: break;
073: }
074: return null; // Not reached
075: }
076:
077: /**
078: * Constructor.
079: *
080: * @param param the parameter we're going to edit
081: */
082: Inquisitor(Parameter param) {
083: parameter = param;
084: panel = new JPanel();
085: panel
086: .setBorder(BorderFactory.createEmptyBorder(20, 20, 20,
087: 20));
088: panelName = "" + instanceCount++;
089: }
090:
091: JPanel getPanel() {
092: return panel;
093: }
094:
095: String getPanelName() {
096: return panelName;
097: }
098:
099: /**
100: * Copy all values from our GUI widgets into the parameter's value(s).
101: */
102: abstract void copyGUIIntoParam();
103:
104: /**
105: * Copy all values from parameter's value(s) into our GUI widgets.
106: */
107: abstract void copyParamIntoGUI();
108:
109: }
|