Java Code Examples for com.intellij.util.ui.UIUtil#findUltimateParent()

The following examples show how to use com.intellij.util.ui.UIUtil#findUltimateParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JBTabsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
void revalidateAndRepaint(final boolean layoutNow) {

    if (myVisibleInfos.isEmpty()) {
      setOpaque(false);
      final Component nonOpaque = UIUtil.findUltimateParent(this);
      if (nonOpaque != null && getParent() != null) {
        final Rectangle toRepaint = SwingUtilities.convertRectangle(getParent(), getBounds(), nonOpaque);
        nonOpaque.repaint(toRepaint.x, toRepaint.y, toRepaint.width, toRepaint.height);
      }
    }
    else {
      setOpaque(true);
    }

    if (layoutNow) {
      validate();
    }
    else {
      revalidate();
    }

    repaint();
  }
 
Example 2
Source File: IdeMouseEventDispatcher.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private static JRootPane findRoot(MouseEvent e) {
  final Component parent = UIUtil.findUltimateParent(e.getComponent());
  JRootPane root = null;

  if (parent instanceof JWindow) {
    root = ((JWindow)parent).getRootPane();
  }
  else if (parent instanceof JDialog) {
    root = ((JDialog)parent).getRootPane();
  }
  else if (parent instanceof JFrame) {
    root = ((JFrame)parent).getRootPane();
  }

  return root;
}
 
Example 3
Source File: IdeEventQueue.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void storeLastFocusedComponent(@Nonnull WindowEvent we) {
  final Window eventWindow = we.getWindow();

  if (we.getID() == WindowEvent.WINDOW_DEACTIVATED || we.getID() == WindowEvent.WINDOW_LOST_FOCUS) {
    Component frame = UIUtil.findUltimateParent(eventWindow);
    Component focusOwnerInDeactivatedWindow = eventWindow.getMostRecentFocusOwner();
    IdeFrame[] allProjectFrames = WindowManager.getInstance().getAllProjectFrames();

    if (focusOwnerInDeactivatedWindow != null) {
      for (IdeFrame ideFrame : allProjectFrames) {
        Window aFrame = TargetAWT.to(WindowManager.getInstance().getWindow(ideFrame.getProject()));
        if (aFrame.equals(frame)) {
          IdeFocusManager focusManager = IdeFocusManager.getGlobalInstance();
          if (focusManager instanceof FocusManagerImpl) {
            ((FocusManagerImpl)focusManager).setLastFocusedAtDeactivation(ideFrame, focusOwnerInDeactivatedWindow);
          }
        }
      }
    }
  }
}
 
Example 4
Source File: IdeHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Find current window element of given project.
 * Use this to find a component for new dialogs without using JBPopupFactory
 *
 * @see com.intellij.ui.popup.AbstractPopup#showCenteredInCurrentWindow
 */
@Nullable
public static Window getWindowComponentFromProject(@NotNull Project project) {
    WindowManagerEx windowManager = getWindowManager();
    if(windowManager == null) {
        return null;
    }

    Window window = null;

    Component focusedComponent = windowManager.getFocusedComponent(project);
    if (focusedComponent != null) {
        Component parent = UIUtil.findUltimateParent(focusedComponent);
        if (parent instanceof Window) {
            window = (Window)parent;
        }
    }

    if (window == null) {
        window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    }

    if (window != null && window.isShowing()) {
        return window;
    }

    return window;
}
 
Example 5
Source File: IdeFocusManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static IdeFocusManager findByComponent(Component c) {
  final Component parent = UIUtil.findUltimateParent(c);
  if (parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame == null) {
      return null;
    }
    return getInstanceSafe(ideFrame.getProject());
  }
  return null;
}
 
Example 6
Source File: FocusManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void delayedApplicationDeactivated(@Nonnull IdeFrame ideFrame) {
  final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
  Component parent = UIUtil.findUltimateParent(owner);

  if (parent == ideFrame) {
    myLastFocusedAtDeactivation.put(ideFrame, owner);
  }
}
 
Example 7
Source File: IdeKeyEventDispatcher.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean hasMnemonicInBalloons(Container container, int code) {
  final Component parent = UIUtil.findUltimateParent(container);
  if (parent instanceof RootPaneContainer) {
    final JLayeredPane pane = ((RootPaneContainer)parent).getLayeredPane();
    for (Component component : pane.getComponents()) {
      if (component instanceof ComponentWithMnemonics && component instanceof Container && hasMnemonic((Container)component, code)) {
        return true;
      }
    }
  }
  return false;
}
 
Example 8
Source File: ActionPopupMenuImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void show(final Component component, int x, int y) {
  if (!component.isShowing()) {
    //noinspection HardCodedStringLiteral
    throw new IllegalArgumentException("component must be shown on the screen");
  }

  removeAll();

  // Fill menu. Only after filling menu has non zero size.

  int x2 = Math.max(0, Math.min(x, component.getWidth() - 1)); // fit x into [0, width-1]
  int y2 = Math.max(0, Math.min(y, component.getHeight() - 1)); // fit y into [0, height-1]

  myContext = myDataContextProvider != null ? myDataContextProvider.get() : DataManager.getInstance().getDataContext(component, x2, y2);
  Utils.fillMenu(myGroup, this, true, myPresentationFactory, myContext, myPlace, false, false, LaterInvocator.isInModalContext());
  if (getComponentCount() == 0) {
    return;
  }
  if (myApp != null) {
    if (myApp.isActive()) {
      Component frame = UIUtil.findUltimateParent(component);
      if (frame instanceof Window) {
        consulo.ui.Window uiWindow = TargetAWT.from((Window)frame);
        myFrame = uiWindow.getUserData(IdeFrame.KEY);
      }
      myConnection = myApp.getMessageBus().connect();
      myConnection.subscribe(ApplicationActivationListener.TOPIC, ActionPopupMenuImpl.this);
    }
  }

  super.show(component, x, y);
}
 
Example 9
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public IdeFrame getIdeFrame(DockContainer container) {
  Component parent = UIUtil.findUltimateParent(container.getContainerComponent());
  if(parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    return uiWindow.getUserData(IdeFrame.KEY);
  }
  return null;
}
 
Example 10
Source File: ApplicationActivationStateManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static IdeFrame getIdeFrameFromWindow(Window window) {
  final Component frame = UIUtil.findUltimateParent(window);
  if (!(frame instanceof Window)) {
    return null;
  }

  consulo.ui.Window uiWindow = TargetAWT.from((Window)frame);
  return uiWindow.getUserData(IdeFrame.KEY);
}
 
Example 11
Source File: SearchEverywhereManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void calcPositionAndShow(Project project, JBPopup balloon) {
  Point savedLocation = WindowStateService.getInstance(myProject).getLocation(LOCATION_SETTINGS_KEY);

  //for first show and short mode popup should be shifted to the top screen half
  if (savedLocation == null && mySearchEverywhereUI.getViewType() == SearchEverywhereUI.ViewType.SHORT) {
    Window window = project != null ? TargetAWT.to(WindowManager.getInstance().suggestParentWindow(project)) : KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    Component parent = UIUtil.findUltimateParent(window);

    if (parent != null) {
      JComponent content = balloon.getContent();
      Dimension balloonSize = content.getPreferredSize();

      Point screenPoint = new Point((parent.getSize().width - balloonSize.width) / 2, parent.getHeight() / 4 - balloonSize.height / 2);
      SwingUtilities.convertPointToScreen(screenPoint, parent);

      Rectangle screenRectangle = ScreenUtil.getScreenRectangle(screenPoint);
      Insets insets = content.getInsets();
      int bottomEdge = screenPoint.y + mySearchEverywhereUI.getExpandedSize().height + insets.bottom + insets.top;
      int shift = bottomEdge - (int)screenRectangle.getMaxY();
      if (shift > 0) {
        screenPoint.y = Integer.max(screenPoint.y - shift, screenRectangle.y);
      }

      RelativePoint showPoint = new RelativePoint(screenPoint);
      balloon.show(showPoint);
      return;
    }
  }

  if (project != null) {
    balloon.showCenteredInCurrentWindow(project);
  }
  else {
    balloon.showInFocusCenter();
  }
}
 
Example 12
Source File: IdePopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean dispatch(@Nonnull final AWTEvent e) {
  LOG.assertTrue(isPopupActive());

  if (e.getID() == WindowEvent.WINDOW_LOST_FOCUS || e.getID() == WindowEvent.WINDOW_DEACTIVATED) {
    if (!isPopupActive()) return false;

    Window focused = ((WindowEvent)e).getOppositeWindow();
    if (focused == null) {
      focused = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    }

    Component ultimateParentForFocusedComponent = UIUtil.findUltimateParent(focused);
    Window sourceWindow = ((WindowEvent)e).getWindow();
    Component ultimateParentForEventWindow = UIUtil.findUltimateParent(sourceWindow);

    boolean shouldCloseAllPopup = false;
    if (ultimateParentForEventWindow == null || ultimateParentForFocusedComponent == null) {
      shouldCloseAllPopup = true;
    }

    consulo.ui.Window uiWindow = TargetAWT.from((Window)ultimateParentForEventWindow);
    IdeFrame ultimateParentWindowForEvent = IdeFrameUtil.findRootIdeFrame(uiWindow);

    if (!shouldCloseAllPopup && ultimateParentWindowForEvent != null) {
      if (ultimateParentWindowForEvent.isInFullScreen() && !ultimateParentForFocusedComponent.equals(ultimateParentForEventWindow)) {
        shouldCloseAllPopup = true;
      }
    }

    if (shouldCloseAllPopup) {
      closeAllPopups();
    }
  }
  else if (e instanceof KeyEvent) {
    // the following is copied from IdeKeyEventDispatcher
    KeyEvent keyEvent = (KeyEvent)e;
    Object source = keyEvent.getSource();
    if (myIgnoreNextKeyTypedEvent) {
      if (KeyEvent.KEY_TYPED == e.getID()) return true;
      myIgnoreNextKeyTypedEvent = false;
    }
    else if (SystemInfo.isMac && InputEvent.ALT_DOWN_MASK == keyEvent.getModifiersEx() && Registry.is("ide.mac.alt.mnemonic.without.ctrl") && source instanceof Component) {
      // the myIgnoreNextKeyTypedEvent changes event processing to support Alt-based mnemonics on Mac only
      if (KeyEvent.KEY_TYPED == e.getID() && !IdeEventQueue.getInstance().isInputMethodEnabled() || IdeKeyEventDispatcher.hasMnemonicInWindow((Component)source, keyEvent)) {
        myIgnoreNextKeyTypedEvent = true;
        return false;
      }
    }
  }

  if (e instanceof KeyEvent || e instanceof MouseEvent) {
    for (int i = myDispatchStack.size() - 1; i >= 0 && i < myDispatchStack.size(); i--) {
      final boolean dispatched = myDispatchStack.get(i).dispatch(e);
      if (dispatched) return true;
    }
  }

  return false;
}
 
Example 13
Source File: PsiViewerDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private AutoExpandFocusListener(final JComboBox comboBox) {
  myComboBox = comboBox;
  myParent = UIUtil.findUltimateParent(myComboBox);
}
 
Example 14
Source File: DesktopToolWindowManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent e) {
  if (e.getKeyCode() != KeyEvent.VK_CONTROL && e.getKeyCode() != KeyEvent.VK_ALT && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_META) {
    if (e.getModifiers() == 0) {
      resetHoldState();
    }
    return false;
  }
  if (e.getID() != KeyEvent.KEY_PRESSED && e.getID() != KeyEvent.KEY_RELEASED) return false;

  Component parent = UIUtil.findUltimateParent(e.getComponent());
  if(parent instanceof Window) {
    consulo.ui.Window uiWindow = TargetAWT.from((Window)parent);

    IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY);
    if (ideFrame != null && ideFrame.getProject() != myProject) {
      resetHoldState();
      return false;
    }
  }

  Set<Integer> vks = getActivateToolWindowVKs();

  if (vks.isEmpty()) {
    resetHoldState();
    return false;
  }

  if (vks.contains(e.getKeyCode())) {
    boolean pressed = e.getID() == KeyEvent.KEY_PRESSED;
    int modifiers = e.getModifiers();

    int mouseMask = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON3_DOWN_MASK;
    if ((e.getModifiersEx() & mouseMask) == 0) {
      if (areAllModifiersPressed(modifiers, vks) || !pressed) {
        processState(pressed);
      }
      else {
        resetHoldState();
      }
    }
  }


  return false;
}