예제 #1
0
파일: Header.java 프로젝트: Rebelo/GXT-ADMZ
  /**
   * Creates a header with the specified appearance.
   *
   * @param appearance the appearance of the header
   */
  public Header(HeaderAppearance appearance) {
    this.appearance = appearance;

    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    this.appearance.render(sb);

    setElement((Element) XDOM.create(sb.toSafeHtml()));

    addStyleName("x-small-editor");

    widgetPanel = new HorizontalPanel();
    widgetPanel.addStyleName("x-panel-toolbar");

    XElement barElem = appearance.getBarElem(getElement());
    barElem.appendChild(widgetPanel.getElement());

    if (tools.size() > 0) {
      for (int i = 0; i < tools.size(); i++) {
        widgetPanel.add(tools.get(i));
      }
    } else {
      widgetPanel.setVisible(false);
    }

    ComponentHelper.setParent(this, widgetPanel);

    appearance.getTextElem(getElement()).setId(getId() + "-label");

    setText(text);

    if (icon != null) {
      setIcon(icon);
    }

    getFocusSupport().setIgnore(true);
  }
  private Point getTargetXY(int targetCounter) {
    if (toolTipConfig.getAnchor() != null) {
      targetCounter++;
      int[] offsets = getOffsets();
      Point xy =
          (toolTipConfig.isAnchorToTarget() && !toolTipConfig.isTrackMouse())
              ? getElement().getAlignToXY(target.getElement(), getAnchorAlign(), null)
              : targetXY;

      int dw = XDOM.getViewWidth(false) - 5;
      int dh = XDOM.getViewHeight(false) - 5;
      int scrollX = XDOM.getBodyScrollLeft() + 5;
      int scrollY = XDOM.getBodyScrollTop() + 5;

      int[] axy = new int[] {xy.getX() + offsets[0], xy.getY() + offsets[1]};
      Size sz = getElement().getSize();
      Region r = XElement.as(target.getElement()).getRegion();

      appearance.removeAnchorStyle(anchorEl);

      // if we are not inside valid ranges we try to switch the anchor
      if (!((toolTipConfig.getAnchor() == Side.TOP
                  && (sz.getHeight() + offsets[1] + scrollY < dh - r.getBottom()))
              || (toolTipConfig.getAnchor() == Side.RIGHT
                  && (sz.getWidth() + offsets[0] + scrollX < r.getLeft()))
              || (toolTipConfig.getAnchor() == Side.BOTTOM
                  && (sz.getHeight() + offsets[1] + scrollY < r.getTop()))
              || (toolTipConfig.getAnchor() == Side.LEFT
                  && (sz.getWidth() + offsets[0] + scrollX < dw - r.getRight())))
          && targetCounter < 4) {
        if (sz.getWidth() + offsets[0] + scrollX < dw - r.getRight()) {
          toolTipConfig.setAnchor(Side.LEFT);
          return getTargetXY(targetCounter);
        }
        if (sz.getWidth() + offsets[0] + scrollX < r.getLeft()) {
          toolTipConfig.setAnchor(Side.RIGHT);
          return getTargetXY(targetCounter);
        }
        if (sz.getHeight() + offsets[1] + scrollY < dh - r.getBottom()) {
          toolTipConfig.setAnchor(Side.TOP);
          return getTargetXY(targetCounter);
        }
        if (sz.getHeight() + offsets[1] + scrollY < r.getTop()) {
          toolTipConfig.setAnchor(Side.BOTTOM);
          return getTargetXY(targetCounter);
        }
      }

      appearance.applyAnchorDirectionStyle(anchorEl, toolTipConfig.getAnchor());

      targetCounter = 0;
      return new Point(axy[0], axy[1]);

    } else {
      int x = targetXY.getX();
      int y = targetXY.getY();

      int[] mouseOffset = toolTipConfig.getMouseOffset();
      if (mouseOffset != null) {
        x += mouseOffset[0];
        y += mouseOffset[1];
      }
      return new Point(x, y);
    }
  }