Ejemplo n.º 1
0
  public static Point getRelLocation(Component c) {
    if (c == null || !c.isShowing()) {
      return new Point(0, 0);
    }

    Container parent = getRootContainer(c);
    if ((parent != null) && parent.isShowing()) {
      Point p1 = c.getLocationOnScreen();
      Point p2 = parent.getLocationOnScreen();
      return new Point(p1.x - p2.x, p1.y - p2.y);
    }

    return new Point(0, 0);
  }
  public void cancel(InputEvent e) {
    if (isDisposed()) return;

    if (myPopup != null) {
      if (!canClose()) {
        return;
      }
      storeDimensionSize(myContent.getSize());
      if (myUseDimServiceForXYLocation) {
        final JRootPane root = myComponent.getRootPane();
        if (root != null) {
          final Container popupWindow = root.getParent();
          if (popupWindow != null && popupWindow.isShowing()) {
            storeLocation(popupWindow.getLocationOnScreen());
          }
        }
      }

      if (e instanceof MouseEvent) {
        IdeEventQueue.getInstance().blockNextEvents(((MouseEvent) e));
      }

      myPopup.hide(false);

      if (ApplicationManagerEx.getApplicationEx() != null) {
        StackingPopupDispatcher.getInstance().onPopupHidden(this);
      }

      if (myInStack) {
        myFocusTrackback.setForcedRestore(!myOk && myFocusable);
        myFocusTrackback.restoreFocus();
      }

      disposePopup();

      if (myListeners != null) {
        for (JBPopupListener each : myListeners) {
          each.onClosed(new LightweightWindowEvent(this, myOk));
        }
      }
    }

    Disposer.dispose(this, false);
  }
Ejemplo n.º 3
0
 /**
  * Traverse to the next forward or backward component using the container's FocusTraversalPolicy.
  *
  * @param comp the assumed current focuse component
  * @param forward if true, returns the next focus component, otherwise the previous one.
  * @return
  */
 public static Component getNextFocus(Component comp, boolean forward) {
   Container focusContainer = comp.getFocusCycleRootAncestor();
   while (focusContainer != null
       && (!focusContainer.isShowing()
           || !focusContainer.isFocusable()
           || !focusContainer.isEnabled())) {
     comp = focusContainer;
     focusContainer = comp.getFocusCycleRootAncestor();
   }
   Component next = null;
   if (focusContainer != null) {
     final FocusTraversalPolicy policy = focusContainer.getFocusTraversalPolicy();
     next =
         forward
             ? policy.getComponentAfter(focusContainer, comp)
             : policy.getComponentBefore(focusContainer, comp);
     if (next == null) {
       next = policy.getDefaultComponent(focusContainer);
     }
   }
   return next;
 }