@Override
 public void showAt(int x, int y) {
   if (disabled) return;
   lastActive = new Date();
   clearTimers();
   super.showAt(x, y);
   if (toolTipConfig.getAnchor() != null) {
     anchorEl.show();
     syncAnchor();
   } else {
     anchorEl.hide();
   }
   if (toolTipConfig.getDismissDelay() > 0
       && toolTipConfig.isAutoHide()
       && !toolTipConfig.isCloseable()) {
     dismissTimer =
         new Timer() {
           @Override
           public void run() {
             hide();
           }
         };
     dismissTimer.schedule(toolTipConfig.getDismissDelay());
   }
 }
 protected void syncAnchor() {
   Anchor anchorPos, targetPos;
   int[] offset;
   int anchorOffset = toolTipConfig.getAnchorOffset();
   switch (toolTipConfig.getAnchor()) {
     case TOP:
       anchorPos = Anchor.BOTTOM;
       targetPos = Anchor.TOP_LEFT;
       offset = new int[] {20 + anchorOffset, 2};
       break;
     case RIGHT:
       anchorPos = Anchor.LEFT;
       targetPos = Anchor.TOP_RIGHT;
       offset = new int[] {-2, 11 + anchorOffset};
       break;
     case BOTTOM:
       anchorPos = Anchor.TOP;
       targetPos = Anchor.BOTTOM_LEFT;
       offset = new int[] {20 + anchorOffset, -2};
       break;
     default:
       anchorPos = Anchor.RIGHT;
       targetPos = Anchor.TOP_LEFT;
       offset = new int[] {2, 11 + anchorOffset};
       break;
   }
   anchorEl.alignTo(getElement(), new AnchorAlignment(anchorPos, targetPos, false), offset);
 }
  /** Creates a new tool tip. */
  protected void init() {
    toolTipConfig = new ToolTipConfig();
    lastActive = new Date();
    monitorWindowResize = true;

    anchorEl = XElement.as(DOM.createDiv());
    appearance.applyAnchorStyle(anchorEl);
    getElement().appendChild(anchorEl);
  }
  @Override
  public void show() {
    if (disabled) return;
    Side origAnchor = null;
    boolean origConstrainPosition = false;
    if (toolTipConfig.getAnchor() != null) {
      origAnchor = toolTipConfig.getAnchor();
      // pre-show it off screen so that the el will have dimensions
      // for positioning calcs when getting xy next
      // showAt(-1000, -1000);
      origConstrainPosition = this.constrainPosition;
      constrainPosition = false;
    }
    showAt(getTargetXY(0));

    if (toolTipConfig.getAnchor() != null) {
      anchorEl.show();
      syncAnchor();
      constrainPosition = origConstrainPosition;
      toolTipConfig.setAnchor(origAnchor);
    } else {
      anchorEl.hide();
    }
  }
Example #5
0
  /**
   * 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);
  }
 @Override
 public XElement getContentWrap(XElement parent) {
   return parent.selectNode("." + style.body());
 }
 @Override
 public XElement getButtonWrap(XElement parent) {
   return parent.selectNode("." + style.buttonsContent());
 }
  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);
    }
  }
 @Override
 protected void onAfterFirstAttach() {
   super.onAfterFirstAttach();
   anchorEl.setZIndex(getElement().getZIndex() + 1);
 }
 @Override
 public XElement getStrip(XElement parent) {
   return parent.selectNode("." + style.tabStripBottom());
 }
 @Override
 public XElement getBar(XElement parent) {
   return parent.selectNode("." + style.tabFooter());
 }