/**
  * Retrieve the Integer value from the given Attribute of the range element
  *
  * @param attribute The name of the attribute on the range element
  * @return The Integer vaulue read from the given attribute or null
  */
 private Integer getIntFromRangeElement(String attribute) {
   Element ele = getRangeElement();
   if (ele != null) {
     return ele.getPropertyInt(attribute);
   }
   return null;
 }
Beispiel #2
0
  @Override
  public void setValue(Double value) {
    if (value < min) {
      value = min;
    } else if (value > max) {
      value = max;
    }

    // Update handle position
    final String styleAttribute = isVertical() ? "marginTop" : "marginLeft";
    final String domProperty = isVertical() ? "offsetHeight" : "offsetWidth";
    final int handleSize = handle.getPropertyInt(domProperty);
    final int baseSize = base.getPropertyInt(domProperty) - 2 * BASE_BORDER_WIDTH;

    final int range = baseSize - handleSize;
    double v = value.doubleValue();

    // Round value to resolution
    if (resolution > 0) {
      v = Math.round(v * Math.pow(10, resolution));
      v = v / Math.pow(10, resolution);
    } else {
      v = Math.round(v);
    }
    final double valueRange = max - min;
    double p = 0;
    if (valueRange > 0) {
      p = range * ((v - min) / valueRange);
    }
    if (p < 0) {
      p = 0;
    }
    if (isVertical()) {
      p = range - p;
    }
    final double pos = p;

    handle.getStyle().setPropertyPx(styleAttribute, (int) Math.round(pos));

    // Update value
    this.value = new Double(v);
    setFeedbackValue(v);
  }
Beispiel #3
0
 /**
  * Returns the offsetWidth element property.
  *
  * @param elem the element
  * @return the offsetWidth property
  */
 static final int getOffsetWidth(Element elem) {
   return elem.getPropertyInt("offsetWidth");
 }
Beispiel #4
0
 /**
  * Returns the offsetHeight element property.
  *
  * @param elem the element
  * @return the offsetHeight property
  */
 static final int getOffsetHeight(Element elem) {
   return elem.getPropertyInt("offsetHeight");
 }
Beispiel #5
0
  /** For internal use only. May be removed or replaced in the future. */
  public void buildBase() {
    final String styleAttribute = isVertical() ? "height" : "width";
    final String oppositeStyleAttribute = isVertical() ? "width" : "height";
    final String domProperty = isVertical() ? "offsetHeight" : "offsetWidth";

    // clear unnecessary opposite style attribute
    base.getStyle().clearProperty(oppositeStyleAttribute);

    /*
     * To resolve defect #13681 we should not return from method buildBase()
     * if slider has no parentElement, because such operations as
     * buildHandle() and setValues(), which are needed for Slider, are
     * called at the end of method buildBase(). And these methods will not
     * be called if there is no parentElement. So, instead of returning from
     * method buildBase() if there is no parentElement "if condition" is
     * applied to call code for parentElement only in case it exists.
     */
    if (getElement().hasParentElement()) {
      final Element p = getElement();
      if (p.getPropertyInt(domProperty) > MIN_SIZE) {
        if (isVertical()) {
          setHeight();
        } else {
          base.getStyle().clearProperty(styleAttribute);
        }
      } else {
        // Set minimum size and adjust after all components have
        // (supposedly) been drawn completely.
        base.getStyle().setPropertyPx(styleAttribute, MIN_SIZE);
        Scheduler.get()
            .scheduleDeferred(
                new Command() {

                  @Override
                  public void execute() {
                    final Element p = getElement();
                    if (p.getPropertyInt(domProperty) > MIN_SIZE + 5
                        || propertyNotNullOrEmpty(styleAttribute, p)) {
                      if (isVertical()) {
                        setHeight();
                      } else {
                        base.getStyle().clearProperty(styleAttribute);
                      }
                      // Ensure correct position
                      setValue(value, false);
                    }
                  }

                  // Style has non empty property
                  private boolean propertyNotNullOrEmpty(
                      final String styleAttribute, final Element p) {
                    return p.getStyle().getProperty(styleAttribute) != null
                        && !p.getStyle().getProperty(styleAttribute).isEmpty();
                  }
                });
      }
    }

    if (!isVertical()) {
      // Draw handle with a delay to allow base to gain maximum width
      Scheduler.get()
          .scheduleDeferred(
              new Command() {
                @Override
                public void execute() {
                  buildHandle();
                  setValue(value, false);
                }
              });
    } else {
      buildHandle();
      setValue(value, false);
    }

    // TODO attach listeners for focusing and arrow keys
  }