public DurationValues getDurationValues() {
    DurationValues vals = new DurationValues();

    String displayNone = Display.NONE.getCssName();

    // Days
    if (!displayNone.equals(this.daysListBox.getElement().getStyle().getDisplay())) {
      vals.days =
          Integer.parseInt(this.daysListBox.getItemText(this.daysListBox.getSelectedIndex()));
    }

    // Hours
    if (!displayNone.equals(this.hoursListBox.getElement().getStyle().getDisplay())) {
      vals.hours =
          Integer.parseInt(this.hoursListBox.getItemText(this.hoursListBox.getSelectedIndex()));
    }

    // Minutes
    if (!displayNone.equals(this.minutesListBox.getElement().getStyle().getDisplay())) {
      vals.minutes =
          Integer.parseInt(this.minutesListBox.getItemText(this.minutesListBox.getSelectedIndex()));
    }

    return vals;
  }
Exemple #2
0
 public static void hideElement(Element element) {
   if (!Display.NONE
       .toString()
       .toLowerCase()
       .equals(element.getStyle().getDisplay().toLowerCase())) {
     element.getStyle().setDisplay(Display.NONE);
   }
 }
Exemple #3
0
  /**
   * Returns a position info representing the dimensions of all visible child elements of the given
   * panel (excluding elements with position:absolute). If the panel has no visible child elements,
   * it's outer dimensions are returned.
   *
   * <p>
   *
   * @param panel the panel
   * @param levels the levels to traverse down the DOM tree
   * @param includeSelf <code>true</code> to include the outer dimensions of the given panel
   * @return the position info
   */
  public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) {

    boolean first = true;
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;
    // if overflow is set to hidden, use the outer dimensions
    if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) {
      if (!includeSelf) {
        // check for any text content
        NodeList<Node> children = panel.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
          if ((children.getItem(i).getNodeType() == Node.TEXT_NODE)
              && (children.getItem(i).getNodeValue().trim().length() > 0)) {
            includeSelf = true;
            break;
          }
        }
      }
      if (includeSelf) {
        top = panel.getAbsoluteTop();
        left = panel.getAbsoluteLeft();
        bottom = top + panel.getOffsetHeight();
        right = left + panel.getOffsetWidth();
        first = false;
      }
      Element child = panel.getFirstChildElement();
      while (child != null) {
        String tagName = child.getTagName();
        if (tagName.equalsIgnoreCase("br")
            || tagName.equalsIgnoreCase("tr")
            || tagName.equalsIgnoreCase("thead")
            || tagName.equalsIgnoreCase("tfoot")
            || tagName.equalsIgnoreCase("script")
            || tagName.equalsIgnoreCase("style")) {
          // ignore tags with no relevant position info
          child = child.getNextSiblingElement();
          continue;
        }
        String positioning = DomUtil.getCurrentStyle(child, Style.position);
        if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display))
            && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName())
                || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) {
          PositionBean childDimensions =
              levels > 0
                  ? getInnerDimensions(child, levels - 1, true)
                  : generatePositionInfo(panel);
          if (first) {
            first = false;
            top = childDimensions.getTop();
            left = childDimensions.getLeft();
            bottom = top + childDimensions.getHeight();
            right = left + childDimensions.getWidth();
          } else {
            int wTop = childDimensions.getTop();
            top = top < wTop ? top : wTop;
            int wLeft = childDimensions.getLeft();
            left = left < wLeft ? left : wLeft;
            int wBottom = wTop + childDimensions.getHeight();
            bottom = bottom > wBottom ? bottom : wBottom;
            int wRight = wLeft + childDimensions.getWidth();
            right = right > wRight ? right : wRight;
          }
        }
        child = child.getNextSiblingElement();
      }
    }
    if (!first) {
      PositionBean result = new PositionBean();
      result.setHeight(bottom - top);
      result.setWidth(right - left);
      result.setTop(top);
      result.setLeft(left);
      return result;
    } else {
      return generatePositionInfo(panel);
    }
  }