01: package jimm.datavision.gui.parameter;
02:
03: import jimm.datavision.Parameter;
04: import jimm.util.I18N;
05: import javax.swing.*;
06:
07: /**
08: * A range string inquisitor knows how to display and control the widgets
09: * needed to ask a user for two string parameter values.
10: *
11: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
12: */
13: class RangeStringInq extends Inquisitor {
14:
15: protected JTextField rangeFromField;
16: protected JTextField rangeToField;
17:
18: RangeStringInq(Parameter param) {
19: super (param);
20:
21: // Build GUI
22: // panel.setLayout(new BorderLayout());
23:
24: // Labels
25: Box labelBox = Box.createVerticalBox();
26:
27: Box box = Box.createHorizontalBox();
28: box.add(Box.createHorizontalGlue());
29: box.add(new JLabel(I18N.get("GUI.from")));
30: labelBox.add(box);
31:
32: box = Box.createHorizontalBox();
33: box.add(Box.createHorizontalGlue());
34: box.add(new JLabel(I18N.get("GUI.to")));
35: labelBox.add(box);
36:
37: // Edit values
38: Box fieldBox = Box.createVerticalBox();
39:
40: // From and to
41: fieldBox.add(rangeFromField = new JTextField(TEXT_FIELD_COLS));
42: fieldBox.add(rangeToField = new JTextField(TEXT_FIELD_COLS));
43:
44: // Horizontal box
45: Box innerBox = Box.createHorizontalBox();
46: panel.add(innerBox);
47: innerBox.add(labelBox);
48: innerBox.add(Box.createHorizontalStrut(8));
49: innerBox.add(fieldBox);
50:
51: // Copy default values into "real" values
52: parameter.setValue(0, parameter.getDefaultValue(0));
53: parameter.setValue(1, parameter.getDefaultValue(1));
54: }
55:
56: void copyGUIIntoParam() {
57: // setValue translates the string to the appropriate numeric type
58: // (integer or float).
59: parameter.setValue(0, rangeFromField.getText());
60: parameter.setValue(1, rangeToField.getText());
61: }
62:
63: void copyParamIntoGUI() {
64: rangeFromField.setText(parameter.getValue(0).toString());
65: rangeToField.setText(parameter.getValue(1).toString());
66: }
67:
68: }
|