示例#1
0
  @Override
  public AttributeEditorInfo init(Map<String, Object> defaultValues) {
    constraint = NumberUtils.getDoubleRange(descriptor);

    final double min = constraint.min();
    final double max = constraint.max();
    final double increment = RangeUtils.getDoubleMinorTicks(min, max);
    final double pageIncrement = RangeUtils.getDoubleMajorTicks(min, max);

    setRanges(to_i(min), to_i(max), to_i(increment), to_i(pageIncrement));

    return super.init(defaultValues);
  }
示例#2
0
  /** Initialize and instantiate the delegate editor class. */
  public AttributeEditorInfo init(
      BindableDescriptor bindable,
      AttributeDescriptor descriptor,
      IAttributeEventProvider eventProvider,
      Map<String, Object> defaultValues) {
    final boolean floatingPointType =
        descriptor.type.equals(Double.class) || descriptor.type.equals(Float.class);

    final boolean unbounded;
    final boolean hasNegativeValues;
    if (floatingPointType) {
      final DoubleRange r = NumberUtils.getDoubleRange(descriptor);

      hasNegativeValues = (r == null || r.min() < 0);
      unbounded = (r == null || NumberUtils.isUnbounded(r));
    } else {
      final IntRange r = NumberUtils.getIntRange(descriptor);

      hasNegativeValues = (r == null || r.min() < 0);
      unbounded = (r == null || NumberUtils.isUnbounded(r));
    }

    final IAttributeEditor delegate;
    if (unbounded) {
      /*
       * If the range is unbounded or contains negative values, use unbounded
       * numeric editor (simple text box). Such unconstrained public attributes
       * shouldn't be common anyway.
       */
      if (floatingPointType) {
        delegate = new UnboundedDoubleEditor();
      } else {
        if (!hasNegativeValues) {
          delegate = new IntegerRangeEditor();
        } else {
          delegate = new UnboundedIntegerEditor();
        }
      }
    } else if (hasNegativeValues) {
      /*
       * If the range covers negative values, or if the range is too big to fit in
       * the integer range, use unbounded double editor. TODO: Negative
       * scale/sliders are available in Eclipse 3.4M5:
       * https://bugs.eclipse.org/bugs/show_bug.cgi?id=91317
       */
      if (floatingPointType) {
        delegate = new UnboundedDoubleEditor();
      } else {
        delegate = new UnboundedIntegerEditor();
      }
    } else {
      /*
       * The range exists, is bounded and contains only non-negative values, use
       * slider/scale directly.
       */
      if (floatingPointType) {
        delegate = new DoubleRangeEditor();
      } else {
        delegate = new IntegerRangeEditor();
      }
    }

    this.delegate = delegate;
    return delegate.init(bindable, descriptor, eventProvider, defaultValues);
  }