Java Code Examples for com.intellij.ui.ScreenUtil#getScreenRectangle()
The following examples show how to use
com.intellij.ui.ScreenUtil#getScreenRectangle() .
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: JBPopupMenu.java From consulo with Apache License 2.0 | 5 votes |
private int getMaxHeight() { GraphicsConfiguration configuration = myTarget.getGraphicsConfiguration(); if (configuration == null && myTarget.getInvoker() != null) { configuration = myTarget.getInvoker().getGraphicsConfiguration(); } if (configuration == null) return Short.MAX_VALUE; Rectangle screenRectangle = ScreenUtil.getScreenRectangle(configuration); return screenRectangle.height; }
Example 2
Source File: EditorFragmentComponent.java From consulo with Apache License 2.0 | 5 votes |
private static int getWidthLimit(@Nonnull Editor editor) { Component component = editor.getComponent(); int screenWidth = ScreenUtil.getScreenRectangle(component).width; if (screenWidth > 0) return screenWidth; Window window = SwingUtilities.getWindowAncestor(component); return window == null ? Integer.MAX_VALUE : window.getWidth(); }
Example 3
Source File: WizardPopup.java From consulo with Apache License 2.0 | 5 votes |
private Dimension computeNotBiggerDimension(Dimension ofContent, final Point locationOnScreen) { int resultHeight = ofContent.height > MAX_SIZE.height + 50 ? MAX_SIZE.height : ofContent.height; if (locationOnScreen != null) { final Rectangle r = ScreenUtil.getScreenRectangle(locationOnScreen); resultHeight = ofContent.height > r.height - (r.height / 4) ? r.height - (r.height / 4) : ofContent.height; } int resultWidth = ofContent.width > MAX_SIZE.width ? MAX_SIZE.width : ofContent.width; if (ofContent.height > MAX_SIZE.height) { resultWidth += ScrollPaneFactory.createScrollPane().getVerticalScrollBar().getPreferredSize().getWidth(); } return new Dimension(resultWidth, resultHeight); }
Example 4
Source File: FramelessNotificationPopup.java From consulo with Apache License 2.0 | 5 votes |
public FramelessNotificationPopup(final JComponent owner, final JComponent content, Color backgroud, boolean useDefaultPreferredSize, final ActionListener listener) { myBackgroud = backgroud; myUseDefaultPreferredSize = useDefaultPreferredSize; myContent = new ContentComponent(content); myActionListener = listener; myFadeInTimer = UIUtil.createNamedTimer("Frameless fade in",10, myFadeTracker); myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myContent, null) .setRequestFocus(false) .setResizable(false) .setMovable(true) .setLocateWithinScreenBounds(false) .setAlpha(0.2f).addListener(new JBPopupAdapter() { public void onClosed(LightweightWindowEvent event) { if (myFadeInTimer.isRunning()) { myFadeInTimer.stop(); } myFadeInTimer.removeActionListener(myFadeTracker); } }) .createPopup(); final Point p = RelativePoint.getSouthEastOf(owner).getScreenPoint(); Rectangle screen = ScreenUtil.getScreenRectangle(p.x, p.y); final Point initial = new Point(screen.x + screen.width - myContent.getPreferredSize().width - 50, screen.y + screen.height - 5); myPopup.showInScreenCoordinates(owner, initial); myFadeInTimer.setRepeats(true); myFadeInTimer.start(); }
Example 5
Source File: SdkComboBox.java From consulo with Apache License 2.0 | 5 votes |
@Override public Dimension getPreferredSize() { final Rectangle rec = ScreenUtil.getScreenRectangle(0, 0); final Dimension size = super.getPreferredSize(); final int maxWidth = rec.width / 4; if (size.width > maxWidth) { size.width = maxWidth; } return size; }
Example 6
Source File: SearchEverywhereManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
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 7
Source File: FlatWelcomeFrame.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess public FlatWelcomeFrame(Runnable clearInstance) { myClearInstance = clearInstance; final JRootPane rootPane = getRootPane(); FlatWelcomeScreen screen = new FlatWelcomeScreen(this); final IdeGlassPaneImpl glassPane = new IdeGlassPaneImpl(rootPane); setGlassPane(glassPane); glassPane.setVisible(false); //setUndecorated(true); setContentPane(screen); setDefaultTitle(); AppUIUtil.updateWindowIcon(this); SwingUIDecorator.apply(SwingUIDecorator::decorateWindowTitle, rootPane); setSize(TargetAWT.to(WelcomeFrameManager.getDefaultWindowSize())); setResizable(false); Point location = WindowStateService.getInstance().getLocation(WelcomeFrameManager.DIMENSION_KEY); Rectangle screenBounds = ScreenUtil.getScreenRectangle(location != null ? location : new Point(0, 0)); setLocation(new Point(screenBounds.x + (screenBounds.width - getWidth()) / 2, screenBounds.y + (screenBounds.height - getHeight()) / 3)); myBalloonLayout = new WelcomeDesktopBalloonLayoutImpl(rootPane, JBUI.insets(8), screen.getMainWelcomePanel().myEventListener, screen.getMainWelcomePanel().myEventLocation); setupCloseAction(this); MnemonicHelper.init(this); Disposer.register(ApplicationManager.getApplication(), this); }
Example 8
Source File: DocumentFragmentTooltipRenderer.java From consulo with Apache License 2.0 | 4 votes |
@Override public LightweightHint show(@Nonnull final Editor editor, @Nonnull Point p, boolean alignToRight, @Nonnull TooltipGroup group, @Nonnull HintHint intInfo) { LightweightHint hint; final JComponent editorComponent = editor.getComponent(); TextRange range = myDocumentFragment.getTextRange(); int startOffset = range.getStartOffset(); int endOffset = range.getEndOffset(); Document doc = myDocumentFragment.getDocument(); int endLine = doc.getLineNumber(endOffset); int startLine = doc.getLineNumber(startOffset); JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane(); // There is a possible case that collapsed folding region is soft wrapped, hence, we need to anchor // not logical but visual line start. VisualPosition visual = editor.offsetToVisualPosition(startOffset); p = editor.visualPositionToXY(visual); p = SwingUtilities.convertPoint( ((EditorEx)editor).getGutterComponentEx(), p, layeredPane ); p.x -= 3; p.y += editor.getLineHeight(); Point screenPoint = new Point(p); SwingUtilities.convertPointToScreen(screenPoint, layeredPane); int maxLineCount = (ScreenUtil.getScreenRectangle(screenPoint).height - screenPoint.y) / editor.getLineHeight(); if (endLine - startLine > maxLineCount) { endOffset = doc.getLineEndOffset(Math.max(0, Math.min(startLine + maxLineCount, doc.getLineCount() - 1))); } if (endOffset < startOffset) return null; FoldingModelEx foldingModel = (FoldingModelEx)editor.getFoldingModel(); foldingModel.setFoldingEnabled(false); TextRange textRange = new TextRange(startOffset, endOffset); hint = EditorFragmentComponent.showEditorFragmentHintAt(editor, textRange, p.y, false, false, true, true, true); foldingModel.setFoldingEnabled(true); return hint; }
Example 9
Source File: WindowStateServiceImpl.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static Rectangle getScreenRectangle(@Nullable GraphicsConfiguration configuration) { return configuration != null ? ScreenUtil.getScreenRectangle(configuration) : ScreenUtil.getMainScreenBounds(); }
Example 10
Source File: WindowStateServiceImpl.java From consulo with Apache License 2.0 | 4 votes |
void updateScreenRectangle(@Nullable GraphicsConfiguration configuration) { myScreen = myLocation == null ? getScreenRectangle(configuration) : mySize == null ? ScreenUtil.getScreenRectangle(myLocation) : ScreenUtil.getScreenRectangle(myLocation.x + mySize.width / 2, myLocation.y + mySize.height / 2); }
Example 11
Source File: CtrlMouseHandler.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private Dimension getMaxPopupSize(@Nonnull Editor editor) { Rectangle rectangle = ScreenUtil.getScreenRectangle(editor.getContentComponent()); return new Dimension((int)(0.9 * Math.max(640, rectangle.width)), (int)(0.33 * Math.max(480, rectangle.height))); }
Example 12
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 13
Source File: PopupPositionManager.java From consulo with Apache License 2.0 | 4 votes |
public PositionAdjuster(final Component relativeTo, int gap) { myRelativeTo = relativeTo; myRelativeOnScreen = relativeTo.getLocationOnScreen(); myScreenRect = ScreenUtil.getScreenRectangle(myRelativeOnScreen); myGap = gap; }
Example 14
Source File: ChooseByNamePopup.java From consulo with Apache License 2.0 | 4 votes |
@Override protected void showList() { if (ApplicationManager.getApplication().isUnitTestMode()) return; ListModel<Object> model = myList.getModel(); if (model == null || model.getSize() == 0) return; final JLayeredPane layeredPane = myTextField.getRootPane().getLayeredPane(); Point location = layeredPane.getLocationOnScreen(); location.y += layeredPane.getHeight(); final Dimension preferredScrollPaneSize = myListScrollPane.getPreferredSize(); preferredScrollPaneSize.width = Math.max(myTextFieldPanel.getWidth(), preferredScrollPaneSize.width); // in 'focus follows mouse' mode, to avoid focus escaping to editor, don't reduce popup size when list size is reduced if (myDropdownPopup != null && !isCloseByFocusLost()) { Dimension currentSize = myDropdownPopup.getSize(); if (preferredScrollPaneSize.width < currentSize.width) preferredScrollPaneSize.width = currentSize.width; if (preferredScrollPaneSize.height < currentSize.height) preferredScrollPaneSize.height = currentSize.height; } // calculate maximal size for the popup window Rectangle screen = ScreenUtil.getScreenRectangle(location); if (preferredScrollPaneSize.width > screen.width) { preferredScrollPaneSize.width = screen.width; if (model.getSize() <= myList.getVisibleRowCount()) { JScrollBar hsb = myListScrollPane.getHorizontalScrollBar(); if (hsb != null && (!SystemInfo.isMac || hsb.isOpaque())) { Dimension size = hsb.getPreferredSize(); if (size != null) preferredScrollPaneSize.height += size.height; } } } if (preferredScrollPaneSize.height > screen.height) preferredScrollPaneSize.height = screen.height; location.x = Math.min(location.x, screen.x + screen.width - preferredScrollPaneSize.width); location.y = Math.min(location.y, screen.y + screen.height - preferredScrollPaneSize.height); String adText = getAdText(); if (myDropdownPopup == null) { ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myListScrollPane, myList); builder.setFocusable(false).setLocateWithinScreenBounds(false).setRequestFocus(false).setCancelKeyEnabled(false).setFocusOwners(new JComponent[]{myTextField}).setBelongsToGlobalPopupStack(false) .setModalContext(false).setAdText(adText).setMayBeParent(true); builder.setCancelCallback(() -> Boolean.TRUE); myDropdownPopup = builder.createPopup(); myDropdownPopup.setSize(preferredScrollPaneSize); myDropdownPopup.showInScreenCoordinates(layeredPane, location); } else { myDropdownPopup.setLocation(location); myDropdownPopup.setSize(preferredScrollPaneSize); } }
Example 15
Source File: ExpandableSupport.java From consulo with Apache License 2.0 | 4 votes |
@Override public final void expand() { if (popup != null || !source.isEnabled()) return; Content content = prepare(source, onShow); JComponent component = content.getContentComponent(); Dimension size = component.getPreferredSize(); if (size.width - 50 < source.getWidth()) size.width = source.getWidth(); if (size.height < 2 * source.getHeight()) size.height = 2 * source.getHeight(); Point location = new Point(0, 0); SwingUtilities.convertPointToScreen(location, source); Rectangle screen = ScreenUtil.getScreenRectangle(source); int bottom = screen.y - location.y + screen.height; if (bottom < size.height) { int top = location.y - screen.y + source.getHeight(); if (top < bottom) { size.height = bottom; } else { if (size.height > top) size.height = top; location.y -= size.height - source.getHeight(); } } component.setPreferredSize(size); popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, content.getFocusableComponent()).setMayBeParent(true) // this creates a popup as a dialog with alwaysOnTop=false .setFocusable(true).setRequestFocus(true).setTitle(title).setAdText(comment).setLocateByContent(true).setCancelOnWindowDeactivation(false) .setKeyboardActions(singletonList(Pair.create(event -> { collapse(); Window window = UIUtil.getWindow(source); if (window != null) { window.dispatchEvent(new KeyEvent(source, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), CTRL_MASK, KeyEvent.VK_ENTER, '\r')); } }, getKeyStroke(KeyEvent.VK_ENTER, CTRL_MASK)))).setCancelCallback(() -> { try { content.cancel(onHide); popup = null; return true; } catch (Exception ignore) { return false; } }).createPopup(); popup.show(new RelativePoint(location)); }