Example #1
0
  /** @param model */
  public DoubleWidget(PropertyModel model, AbstractController controller) {
    super(model, controller);

    double min, max, inc;
    if (model.hasValueForParameter(MIN_VALUE_PARAM)) {
      min = model.getDoubleValueForParameter(MIN_VALUE_PARAM);
    } else {
      min = DEFAULT_MIN_VALUE;
    }
    if (model.hasValueForParameter(MAX_VALUE_PARAM)) {
      max = model.getDoubleValueForParameter(MAX_VALUE_PARAM);
    } else {
      max = DEFAULT_MAX_VALUE;
    }
    if (model.hasValueForParameter(INCREMENT_VALUE_PARAM)) {
      inc = model.getDoubleValueForParameter(INCREMENT_VALUE_PARAM);
    } else {
      inc = DEFAULT_INC_VALUE;
    }

    SpinnerNumberModel valueModel = new SpinnerNumberModel(min, min, max, inc);
    valueChooser = new JSpinner(valueModel);
    valueChooser.setEditor(new JSpinner.NumberEditor(valueChooser /*, "#.##"*/));
    valueChooser.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            if (e.getSource() == valueChooser) {
              updateModelFromWidget();
            }
          }
        });
    valueChooser.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    JComponent editor = valueChooser.getEditor();
    if (editor instanceof DefaultEditor) {
      ((DefaultEditor) editor).getTextField().setHorizontalAlignment(SwingConstants.LEFT);
      if (ToolBox.getPLATFORM() != ToolBox.MACOS) {
        ((DefaultEditor) editor)
            .getTextField()
            .setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
      }
    }
    if (model.hasValueForParameter(READONLY_TEXTFIELD)
        && model.getBooleanValueForParameter(READONLY_TEXTFIELD)) {
      valueChooser.setEnabled(false);
    }

    getDynamicComponent().addFocusListener(new WidgetFocusListener(this));
  }
Example #2
0
 public String getLastAccessor() {
   if (_lastAccessor == null) {
     _lastAccessor = PropertyModel.getLastAccessor(name);
   }
   return _lastAccessor;
 }
Example #3
0
 public KeyValueCoding getTargetObject(KeyValueCoding inspectable) {
   return PropertyModel.getTargetObject(inspectable, name);
 }