コード例 #1
0
ファイル: CbUtil.java プロジェクト: Toadwana/civbuddy
  /**
   * Determine if the given click was inside the boundaries of the given widget.
   *
   * @param pWidget the widget
   * @param pClickEvent the click
   * @return <code>true</code> if yes
   */
  public static boolean isInside(final Widget pWidget, final ClickEvent pClickEvent) {
    LOG.enter("isInside"); // $NON-NLS-1$

    boolean result = false;
    final int cx = pClickEvent.getClientX();
    final int cy = pClickEvent.getClientY();
    final int wleft = pWidget.getAbsoluteLeft();
    final int wtop = pWidget.getAbsoluteTop();

    if (LOG.isDetailEnabled()) {
      LOG.detail(
          "isInside", //$NON-NLS-1$
          "Click at ("
              + cx
              + ','
              + cy //$NON-NLS-1$
              + "), widget pos ("
              + wleft
              + ','
              + wtop //$NON-NLS-1$
              + "), widget dims ["
              + pWidget.getOffsetWidth()
              + ',' //$NON-NLS-1$
              + pWidget.getOffsetHeight()
              + ']');
    }
    if (cx >= wleft
        && cy >= wtop
        && cx < wleft + pWidget.getOffsetWidth()
        && cy < wtop + pWidget.getOffsetHeight()) {
      result = true;
    }

    LOG.exit("isInside", Boolean.valueOf(result)); // $NON-NLS-1$
    return result;
  }