Java Code Examples for com.intellij.openapi.wm.IdeFrame#getComponent()

The following examples show how to use com.intellij.openapi.wm.IdeFrame#getComponent() . 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: MouseGestureManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void remove(IdeFrame frame) {
  if (!Registry.is("actionSystem.mouseGesturesEnabled")) return;

  if (SystemInfo.isMacOSSnowLeopard) {
    try {
      Object listener = myListeners.get(frame);
      JComponent cmp = frame.getComponent();
      myListeners.remove(frame);
      if (listener != null && cmp != null && cmp.isShowing()) {
        ((MacGestureAdapter)listener).remove(cmp);
      }
    }
    catch (Throwable e) {
      LOG.debug(e);
    }
  }

}
 
Example 2
Source File: PopupUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Component getActiveComponent() {
  Window[] windows = Window.getWindows();
  for (Window each : windows) {
    if (each.isActive()) {
      return each;
    }
  }

  final IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
  if (frame != null) return frame.getComponent();
  return JOptionPane.getRootFrame();
}
 
Example 3
Source File: StatusPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Project getActiveProject() {
  // a better way of finding a project would be great
  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    IdeFrame ideFrame = WindowManager.getInstance().getIdeFrame(project);
    if (ideFrame != null) {
      final JComponent frame = ideFrame.getComponent();
      if (SwingUtilities.isDescendingFrom(myTextPanel, frame)) {
        return project;
      }
    }
  }
  return null;
}
 
Example 4
Source File: ModalityHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JDialog getBlockerForFrame(final IdeFrame ideFrame) {
  if (ideFrame == null) return null;
  Component c = ideFrame.getComponent();
  if (c == null) return null;
  Window window = SwingUtilities.getWindowAncestor(c);
  if (window == null) return null;
  if (!isModalBlocked(window)) return null;
  return getModalBlockerFor(window);
}
 
Example 5
Source File: IdeErrorsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean reportMessage(final AbstractMessage logMessage, final boolean dialogClosed) {
  final ErrorReportSubmitter submitter = getSubmitter(logMessage.getThrowable());

  if (submitter != null) {
    logMessage.setSubmitting(true);
    if (!dialogClosed) {
      updateControls();
    }
    Container parentComponent;
    if (dialogClosed) {
      IdeFrame ideFrame = DesktopIdeFrameUtil.findIdeFrameFromParent(getContentPane());
      parentComponent = ideFrame.getComponent();
    }
    else {
      parentComponent = getContentPane();
    }
    return submitter.trySubmitAsync(getEvents(logMessage), logMessage.getAdditionalInfo(), parentComponent, submittedReportInfo -> {
      logMessage.setSubmitting(false);
      logMessage.setSubmitted(submittedReportInfo);
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (!dialogClosed) {
            updateOnSubmit();
          }
        }
      });
    });
  }
  return false;
}
 
Example 6
Source File: MacGestureAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static MouseEvent createMouseEventWrapper(IdeFrame frame) {
  return new MouseEvent(frame.getComponent(), ActionEvent.ACTION_PERFORMED, System.currentTimeMillis(), 0, 0, 0, 0, false, 0);
}
 
Example 7
Source File: DesktopDataManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
private Component getFocusedComponent() {
  Window activeWindow = TargetAWT.to(windowManager().getMostRecentFocusedWindow());
  if (activeWindow == null) {
    activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    if (activeWindow == null) {
      activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
      if (activeWindow == null) return null;
    }
  }

  // In case we have an active floating toolwindow and some component in another window focused,
  // we want this other component to receive key events.
  // Walking up the window ownership hierarchy from the floating toolwindow would have led us to the main IdeFrame
  // whereas we want to be able to type in other frames as well.
  if (activeWindow instanceof ToolWindowFloatingDecorator) {
    IdeFocusManager ideFocusManager = IdeFocusManager.findInstanceByComponent(activeWindow);
    IdeFrame lastFocusedFrame = ideFocusManager.getLastFocusedFrame();
    JComponent frameComponent = lastFocusedFrame != null ? lastFocusedFrame.getComponent() : null;
    Window lastFocusedWindow = frameComponent != null ? SwingUtilities.getWindowAncestor(frameComponent) : null;
    boolean toolWindowIsNotFocused = windowManager().getFocusedComponent(activeWindow) == null;
    if (toolWindowIsNotFocused && lastFocusedWindow != null) {
      activeWindow = lastFocusedWindow;
    }
  }

  // try to find first parent window that has focus
  Window window = activeWindow;
  Component focusedComponent = null;
  while (window != null) {
    focusedComponent = windowManager().getFocusedComponent(window);
    if (focusedComponent != null) {
      break;
    }
    window = window.getOwner();
  }
  if (focusedComponent == null) {
    focusedComponent = activeWindow;
  }

  return focusedComponent;
}