Java Code Examples for com.intellij.util.ui.UIUtil#getWindow()
The following examples show how to use
com.intellij.util.ui.UIUtil#getWindow() .
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: WindowResizeListener.java From consulo with Apache License 2.0 | 6 votes |
public ToolkitListener(Component content, Insets border, Icon corner) { super(content, border, corner); myHelper = new ToolkitListenerHelper(this); myMinSize.set(content.getMinimumSize()); Window window = UIUtil.getWindow(content); if (window != null) window.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent e) { if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED) { myMinSize.set(content.getMinimumSize()); } else if (e.getID() == HierarchyEvent.SHOWING_CHANGED && !window.isShowing()) { window.removeHierarchyListener(this); } } }); }
Example 2
Source File: WindowMouseListener.java From consulo with Apache License 2.0 | 6 votes |
public void addTo(Component comp) { if (methodsNotAvailable()) return; final Window window = UIUtil.getWindow(comp); if (window == null) return; final boolean wasShown = getPeer(window) != null; if (wasShown) addToImpl(window); window.removeComponentListener(pendingListener); window.addComponentListener(pendingListener = new ComponentAdapter() { @Override public void componentShown(ComponentEvent event) { if (!wasShown) addToImpl(window); } @Override public void componentHidden(ComponentEvent e) { window.removeComponentListener(this); removeFrom(window); } }); }
Example 3
Source File: PopupLocationTracker.java From consulo with Apache License 2.0 | 6 votes |
public static boolean canRectangleBeUsed(@Nonnull Component parent, @Nonnull Rectangle desiredScreenBounds, @Nullable ScreenAreaConsumer excludedConsumer) { if (!Registry.is("ide.use.screen.area.tracker", false)) { return true; } Window window = UIUtil.getWindow(parent); if (window != null) { for (ScreenAreaConsumer consumer : ourAreaConsumers) { if (consumer == excludedConsumer) continue; if (window == consumer.getUnderlyingWindow()) { Rectangle area = consumer.getConsumedScreenBounds(); if (area.intersects(desiredScreenBounds)) { return false; } } } } return true; }
Example 4
Source File: ColorAndFontOptions.java From consulo with Apache License 2.0 | 6 votes |
private static boolean edit(DataContext context, String search, Function<ColorAndFontOptions, SearchableConfigurable> function) { ColorAndFontOptions options = new ColorAndFontOptions(); SearchableConfigurable page = function.apply(options); Configurable[] configurables = options.getConfigurables(); try { if (page != null) { Runnable runnable = search == null ? null : page.enableSearch(search); Window window = UIUtil.getWindow(context.getData(PlatformDataKeys.CONTEXT_COMPONENT)); if (window != null) { ShowSettingsUtil.getInstance().editConfigurable(window, page, runnable); } else { ShowSettingsUtil.getInstance().editConfigurable(context.getData(CommonDataKeys.PROJECT), page, runnable); } } } finally { for (Configurable configurable : configurables) configurable.disposeUIResources(); options.disposeUIResources(); } return page != null; }
Example 5
Source File: JBPopupMenu.java From consulo with Apache License 2.0 | 5 votes |
private void updateShift(int increment) { int maxHeight = super.preferredLayoutSize(myTarget).height - getMaxHeight(); int newShift = Math.max(0, Math.min(maxHeight, myShift + increment)); if (newShift != myShift) { myShift = newShift; myTarget.revalidate(); myTarget.repaint(); Window w = UIUtil.getWindow(myTarget.getComponent()); if (w != null) { for (Window window : w.getOwnedWindows()) { window.dispose(); } } } }
Example 6
Source File: IdeMouseEventDispatcher.java From consulo with Apache License 2.0 | 5 votes |
private static void requestFocusInNonFocusedWindow(@Nullable Component component) { Window window = UIUtil.getWindow(component); if (window != null && !UIUtil.isFocusAncestor(window)) { Component focusable = UIUtil.isFocusable(component) ? component : findDefaultFocusableComponent(component); if (focusable != null) focusable.requestFocus(); } }
Example 7
Source File: WindowMouseListener.java From consulo with Apache License 2.0 | 5 votes |
public void removeFrom(Component comp) { if (methodsNotAvailable()) return; comp = UIUtil.getWindow(comp); if (getPeer(comp) != null) { removeMouseListenerMethod.invoke(getPeer(comp), myListener); removeMouseMotionListenerMethod.invoke(getPeer(comp), myListener); } if (comp != null) comp.removeComponentListener(pendingListener); }
Example 8
Source File: AnnotateDiffViewerAction.java From consulo with Apache License 2.0 | 5 votes |
private static void showNotification(@Nonnull DiffViewerBase viewer, @Nonnull Notification notification) { JComponent component = viewer.getComponent(); Window awtWindow = UIUtil.getWindow(component); if (awtWindow != null) { consulo.ui.Window uiWindow = TargetAWT.from(awtWindow); IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY); if (ideFrame != null && NotificationsManagerImpl.findWindowForBalloon(viewer.getProject()) == awtWindow) { notification.notify(viewer.getProject()); return; } } Balloon balloon = NotificationsManagerImpl.createBalloon(component, notification, false, true, null, viewer); Dimension componentSize = component.getSize(); Dimension balloonSize = balloon.getPreferredSize(); int width = Math.min(balloonSize.width, componentSize.width); int height = Math.min(balloonSize.height, componentSize.height); // top-right corner, 20px to the edges RelativePoint point = new RelativePoint(component, new Point(componentSize.width - 20 - width / 2, 20 + height / 2)); balloon.show(point, Balloon.Position.above); }
Example 9
Source File: DesktopApplicationImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override @Nonnull public ModalityState getModalityStateForComponent(@Nonnull Component c) { if (!isDispatchThread()) LOG.debug("please, use application dispatch thread to get a modality state"); Window window = UIUtil.getWindow(c); if (window == null) return getNoneModalityState(); return LaterInvocator.modalityStateForWindow(window); }
Example 10
Source File: IdeGlassPaneImpl.java From consulo with Apache License 2.0 | 4 votes |
private boolean preprocess(final MouseEvent e, final boolean motion, JRootPane eventRootPane) { try { if (UIUtil.getWindow(this) != UIUtil.getWindow(e.getComponent())) return false; final MouseEvent event = MouseEventAdapter.convert(e, eventRootPane); if (event.isAltDown() && SwingUtilities.isLeftMouseButton(event) && event.getID() == MouseEvent.MOUSE_PRESSED) { Component c = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); Balloon balloon = JBPopupFactory.getInstance().getParentBalloonFor(c); if (balloon instanceof BalloonImpl) { JComponent component = ((BalloonImpl)balloon).getComponent(); component.getToolkit().getSystemClipboard().setContents(new StringSelection(UIUtil.getDebugText(component)), EmptyClipboardOwner.INSTANCE); } } if (!IdeGlassPaneUtil.canBePreprocessed(e)) { return false; } for (EventListener each : mySortedMouseListeners) { if (motion && each instanceof MouseMotionListener) { fireMouseMotion((MouseMotionListener)each, event); } else if (!motion && each instanceof MouseListener) { fireMouseEvent((MouseListener)each, event); } if (event.isConsumed()) { e.consume(); return true; } } return false; } finally { if (eventRootPane == myRootPane) { Cursor cursor; if (!myListener2Cursor.isEmpty()) { cursor = myListener2Cursor.values().iterator().next(); final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), myRootPane.getContentPane()); Component target = SwingUtilities.getDeepestComponentAt(myRootPane.getContentPane().getParent(), point.x, point.y); if (canProcessCursorFor(target)) { target = getCompWithCursor(target); restoreLastComponent(target); if (target != null) { if (myLastCursorComponent != target) { myLastCursorComponent = target; myLastOriginalCursor = target.getCursor(); } if (cursor != null && !cursor.equals(target.getCursor())) { if (target instanceof JComponent) { ((JComponent)target).putClientProperty(PREPROCESSED_CURSOR_KEY, Boolean.TRUE); } target.setCursor(cursor); } } getRootPane().setCursor(cursor); } } else if (!e.isConsumed() && e.getID() != MouseEvent.MOUSE_DRAGGED) { cursor = Cursor.getDefaultCursor(); JRootPane rootPane = getRootPane(); if (rootPane != null) { rootPane.setCursor(cursor); } else { LOG.warn("Root pane is null. Event: " + e); } restoreLastComponent(null); myLastOriginalCursor = null; myLastCursorComponent = null; } myListener2Cursor.clear(); } } }
Example 11
Source File: IdeKeyEventDispatcher.java From consulo with Apache License 2.0 | 4 votes |
/** * @return <code>true</code> if and only if the <code>component</code> represents * modal context. * @throws IllegalArgumentException if <code>component</code> is <code>null</code>. */ public static boolean isModalContext(@Nonnull Component component) { Window awtWindow = UIUtil.getWindow(component); consulo.ui.Window uiWindow = TargetAWT.from(awtWindow); IdeFrame ideFrame = uiWindow == null ? null : uiWindow.getUserData(IdeFrame.KEY); if (IdeFrameUtil.isRootFrame(ideFrame)) { RootPaneContainer rootPaneContainer = (RootPaneContainer)awtWindow; Component glassPane = rootPaneContainer.getGlassPane(); if (glassPane instanceof IdeGlassPaneEx) { return ((IdeGlassPaneEx)glassPane).isInModalContext(); } } if (awtWindow instanceof JDialog) { final JDialog dialog = (JDialog)awtWindow; if (!dialog.isModal()) { final Window owner = dialog.getOwner(); return owner != null && isModalContext(owner); } } if (awtWindow instanceof JFrame) { return false; } boolean isFloatingDecorator = awtWindow instanceof ToolWindowFloatingDecorator; boolean isPopup = !(component instanceof JFrame) && !(component instanceof JDialog); if (isPopup) { if (component instanceof JWindow) { JBPopup popup = (JBPopup)((JWindow)component).getRootPane().getClientProperty(JBPopup.KEY); if (popup != null) { return popup.isModalContext(); } } } return !isFloatingDecorator; }
Example 12
Source File: StackingPopupDispatcherImpl.java From consulo with Apache License 2.0 | 4 votes |
private boolean dispatchMouseEvent(AWTEvent event) { if (event.getID() != MouseEvent.MOUSE_PRESSED) { return false; } if (myStack.isEmpty()) { return false; } AbstractPopup popup = (AbstractPopup)findPopup(); final MouseEvent mouseEvent = (MouseEvent)event; Point point = (Point)mouseEvent.getPoint().clone(); SwingUtilities.convertPointToScreen(point, mouseEvent.getComponent()); while (true) { if (popup != null && !popup.isDisposed()) { Window window = UIUtil.getWindow(mouseEvent.getComponent()); if (window != null && window != popup.getPopupWindow() && SwingUtilities.isDescendingFrom(window, popup.getPopupWindow())) { return false; } final Component content = popup.getContent(); if (!content.isShowing()) { popup.cancel(); return false; } final Rectangle bounds = new Rectangle(content.getLocationOnScreen(), content.getSize()); if (bounds.contains(point) || !popup.isCancelOnClickOutside()) { return false; } if (!popup.canClose()) { return false; } //click on context menu item if (MenuSelectionManager.defaultManager().getSelectedPath().length > 0) { return false; } popup.cancel(mouseEvent); } if (myStack.isEmpty()) { return false; } popup = (AbstractPopup)myStack.peek(); if (popup == null || popup.isDisposed()) { myStack.pop(); } } }
Example 13
Source File: LookupUi.java From consulo with Apache License 2.0 | 4 votes |
Rectangle calculatePosition() { final JComponent lookupComponent = myLookup.getComponent(); Dimension dim = lookupComponent.getPreferredSize(); int lookupStart = myLookup.getLookupStart(); Editor editor = myLookup.getTopLevelEditor(); if (lookupStart < 0 || lookupStart > editor.getDocument().getTextLength()) { LOG.error(lookupStart + "; offset=" + editor.getCaretModel().getOffset() + "; element=" + myLookup.getPsiElement()); } LogicalPosition pos = editor.offsetToLogicalPosition(lookupStart); Point location = editor.logicalPositionToXY(pos); location.y += editor.getLineHeight(); location.x -= myLookup.myCellRenderer.getTextIndent(); // extra check for other borders final Window window = UIUtil.getWindow(lookupComponent); if (window != null) { final Point point = SwingUtilities.convertPoint(lookupComponent, 0, 0, window); location.x -= point.x; } SwingUtilities.convertPointToScreen(location, editor.getContentComponent()); final Rectangle screenRectangle = ScreenUtil.getScreenRectangle(editor.getContentComponent()); if (!isPositionedAboveCaret()) { int shiftLow = screenRectangle.y + screenRectangle.height - (location.y + dim.height); myPositionedAbove = shiftLow < 0 && shiftLow < location.y - dim.height && location.y >= dim.height; } if (isPositionedAboveCaret()) { location.y -= dim.height + editor.getLineHeight(); if (pos.line == 0) { location.y += 1; //otherwise the lookup won't intersect with the editor and every editor's resize (e.g. after typing in console) will close the lookup } } if (!screenRectangle.contains(location)) { location = ScreenUtil.findNearestPointOnBorder(screenRectangle, location); } Rectangle candidate = new Rectangle(location, dim); ScreenUtil.cropRectangleToFitTheScreen(candidate); JRootPane rootPane = editor.getComponent().getRootPane(); if (rootPane != null) { SwingUtilities.convertPointFromScreen(location, rootPane.getLayeredPane()); } else { LOG.error("editor.disposed=" + editor.isDisposed() + "; lookup.disposed=" + myLookup.isLookupDisposed() + "; editorShowing=" + editor.getContentComponent().isShowing()); } myMaximumHeight = candidate.height; return new Rectangle(location.x, location.y, dim.width, candidate.height); }
Example 14
Source File: WindowMouseListener.java From consulo with Apache License 2.0 | 2 votes |
/** * Finds a movable/resizable view for the specified content. * By default, it returns the first window ancestor. * It can be overridden to return something else, * for example, a layered component. */ protected Component getView(Component component) { return UIUtil.getWindow(component); }