コード例 #1
0
  public static final Component getChildAtLine(
      Container container, Point point, boolean horizontal) {
    if (horizontal) {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.x >= component.getX() && point.x < component.getX() + component.getWidth())
          return component;
      }
    } else {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.y >= component.getY() && point.y < component.getY() + component.getHeight())
          return component;
      }
    }

    return null;
  }
コード例 #2
0
  public static final Component getVisibleChildAt(Container container, Point point) {
    for (int i = 0; i < container.getComponentCount(); i++) {
      Component component = container.getComponent(i);
      if (component.isVisible()
          && component.contains(point.x - component.getX(), point.y - component.getY()))
        return component;
    }

    return null;
  }
コード例 #3
0
  static Point getLocationInQueryTextArea(Component childComp) {
    Point ret = new Point(0, 0);

    Component comp = childComp;

    while (false == comp instanceof QueryTextArea) {
      ret.translate(comp.getX(), comp.getY());
      comp = comp.getParent();
    }

    return ret;
  }
コード例 #4
0
ファイル: Utils.java プロジェクト: hathix/cabra-desktop
  /**
   * Centers the given component in relation to its owner.
   *
   * @param component the component to center
   * @param owner the parent frame
   */
  public static void centerComponent(Component component, Component owner) {
    // find the difference in width to see the offsets
    int widthDifference = owner.getWidth() - component.getWidth();
    int heightDifference = owner.getHeight() - component.getHeight();

    // we can divide the differences by 2 and add that to the owner's top left
    // and then make that the top left of the component
    // to center the frame
    int leftOffset = widthDifference / 2;
    int topOffset = heightDifference / 2;

    // these are the new locations
    int left = owner.getX() + leftOffset;
    int top = owner.getY() + topOffset;

    Utils.changeFrameLocation(component, left, top);
  }
コード例 #5
0
  private void paintOnComponentUnderViewport(Component component, Graphics g) {
    JBViewport viewport = ObjectUtils.tryCast(myOwner, JBViewport.class);
    if (viewport == null || viewport.getView() != component || viewport.isPaintingNow()) return;

    // We're painting a component which has a viewport as it's ancestor.
    // As the viewport paints status text, we'll erase it, so we need to schedule a repaint for the
    // viewport with status text's bounds.
    // But it causes flicker, so we paint status text over the component first and then schedule the
    // viewport repaint.

    Rectangle textBoundsInViewport = getTextComponentBound();

    int xInOwner = textBoundsInViewport.x - component.getX();
    int yInOwner = textBoundsInViewport.y - component.getY();
    Rectangle textBoundsInOwner =
        new Rectangle(xInOwner, yInOwner, textBoundsInViewport.width, textBoundsInViewport.height);
    doPaintStatusText(g, textBoundsInOwner);

    viewport.repaint(textBoundsInViewport);
  }