com.intellij.ui.ScreenUtil Java Examples
The following examples show how to use
com.intellij.ui.ScreenUtil.
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: DimensionService.java From consulo with Apache License 2.0 | 6 votes |
@Nullable public synchronized Point getLocation(@Nonnull String key, Project project) { Point point = project == null ? null : WindowStateService.getInstance(project).getLocation(key); if (point != null) return point; Pair<String, Float> pair = keyPair(key, project); point = myKey2Location.get(pair.first); if (point != null) { point = (Point)point.clone(); float scale = pair.second; point.setLocation(point.x / scale, point.y / scale); } if (point != null && !ScreenUtil.getScreenRectangle(point).contains(point)) { point = null; } return point; }
Example #2
Source File: DockManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
public void createNewDockContainerFor(DockableContent content, RelativePoint point) { DockContainer container = getFactory(content.getDockContainerType()).createContainer(content); register(container); final DockWindow window = createWindowFor(null, container); Dimension size = content.getPreferredSize(); Point showPoint = point.getScreenPoint(); showPoint.x -= size.width / 2; showPoint.y -= size.height / 2; Rectangle target = new Rectangle(showPoint, size); ScreenUtil.moveRectangleToFitTheScreen(target); ScreenUtil.cropRectangleToFitTheScreen(target); window.setLocation(target.getLocation()); window.myDockContentUiContainer.setPreferredSize(target.getSize()); window.show(false); window.getFrame().pack(); container.add(content, new RelativePoint(target.getLocation())); SwingUtilities.invokeLater(() -> window.myUiContainer.setPreferredSize(null)); }
Example #3
Source File: DesktopFloatingDecorator.java From consulo with Apache License 2.0 | 6 votes |
@Override public final void dispose() { if (ScreenUtil.isStandardAddRemoveNotify(getParent())) { Disposer.dispose(myDelayAlarm); Disposer.dispose(myDisposable); } else { if (isShowing()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { show(); } }); } } super.dispose(); }
Example #4
Source File: DebuggerTreeWithHistoryPopup.java From consulo with Apache License 2.0 | 6 votes |
private void resize(final TreePath path, JTree tree) { if (myPopup == null || !myPopup.isVisible()) return; final Window popupWindow = SwingUtilities.windowForComponent(myPopup.getContent()); if (popupWindow == null) return; final Dimension size = tree.getPreferredSize(); final Point location = popupWindow.getLocation(); final Rectangle windowBounds = popupWindow.getBounds(); final Rectangle bounds = tree.getPathBounds(path); if (bounds == null) return; final Rectangle targetBounds = new Rectangle(location.x, location.y, Math.max(Math.max(size.width, bounds.width) + 20, windowBounds.width), Math.max(tree.getRowCount() * bounds.height + 55, windowBounds.height)); ScreenUtil.cropRectangleToFitTheScreen(targetBounds); popupWindow.setBounds(targetBounds); popupWindow.validate(); popupWindow.repaint(); }
Example #5
Source File: HelpTooltip.java From consulo with Apache License 2.0 | 6 votes |
@Override public Point getPointFor(Component owner, Dimension popupSize, Point mouseLocation) { Point location = mouseLocation.getLocation(); location.y += CURSOR_OFFSET.get(); SwingUtilities.convertPointToScreen(location, owner); Rectangle r = new Rectangle(location, popupSize); ScreenUtil.fitToScreen(r); location = r.getLocation(); SwingUtilities.convertPointFromScreen(location, owner); r.setLocation(location); if (r.contains(mouseLocation)) { location.y = -popupSize.height - JBUI.scale(1); } return location; }
Example #6
Source File: WindowStateServiceImpl.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private static GraphicsConfiguration getConfiguration(@Nullable Object object) { if (object instanceof Project) { Project project = (Project)object; object = WindowManager.getInstance().getFrame(project); if (object == null) LOG.warn("cannot find a project frame for " + project); } if (object instanceof Window) { Window window = (Window)object; GraphicsConfiguration configuration = window.getGraphicsConfiguration(); if (configuration != null) return configuration; object = ScreenUtil.getScreenDevice(window.getBounds()); if (object == null) LOG.warn("cannot find a device for " + window); } if (object instanceof GraphicsDevice) { GraphicsDevice device = (GraphicsDevice)object; object = device.getDefaultConfiguration(); if (object == null) LOG.warn("cannot find a configuration for " + device); } if (object instanceof GraphicsConfiguration) return (GraphicsConfiguration)object; if (object != null) LOG.warn("unexpected object " + object.getClass()); return null; }
Example #7
Source File: DesktopWindowManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
public void showFrame() { final DesktopIdeFrameImpl frame = new DesktopIdeFrameImpl(myActionManager, myDataManager, ApplicationManager.getApplication()); myProject2Frame.put(null, frame); if (myFrameBounds == null || !ScreenUtil.isVisible(myFrameBounds)) { //avoid situations when IdeFrame is out of all screens myFrameBounds = ScreenUtil.getMainScreenBounds(); int xOff = myFrameBounds.width / 8; int yOff = myFrameBounds.height / 8; JBInsets.removeFrom(myFrameBounds, new Insets(yOff, xOff, yOff, xOff)); } JFrame jWindow = (JFrame)TargetAWT.to(frame.getWindow()); jWindow.setBounds(myFrameBounds); jWindow.setExtendedState(myFrameExtendedState); jWindow.setVisible(true); }
Example #8
Source File: DesktopSplash.java From consulo with Apache License 2.0 | 5 votes |
private void setLocationInTheCenterOfScreen() { Rectangle bounds = getGraphicsConfiguration().getBounds(); if (SystemInfo.isWindows) { Insets insets = ScreenUtil.getScreenInsets(getGraphicsConfiguration()); int x = insets.left + (bounds.width - insets.left - insets.right - getWidth()) / 2; int y = insets.top + (bounds.height - insets.top - insets.bottom - getHeight()) / 2; setLocation(x, y); } else { setLocation((bounds.width - getWidth()) / 2, (bounds.height - getHeight()) / 2); } }
Example #9
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 #10
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 #11
Source File: DebuggerTreeWithHistoryPopup.java From consulo with Apache License 2.0 | 5 votes |
private void updateInitialBounds(final Tree tree) { final Window popupWindow = SwingUtilities.windowForComponent(myPopup.getContent()); final Dimension size = tree.getPreferredSize(); final Point location = popupWindow.getLocation(); final Rectangle windowBounds = popupWindow.getBounds(); final Rectangle targetBounds = new Rectangle(location.x, location.y, Math.max(size.width + 250, windowBounds.width), Math.max(size.height, windowBounds.height)); ScreenUtil.cropRectangleToFitTheScreen(targetBounds); popupWindow.setBounds(targetBounds); popupWindow.validate(); popupWindow.repaint(); }
Example #12
Source File: DebuggerUIUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void showValuePopup(@Nonnull XFullValueEvaluator evaluator, @Nonnull MouseEvent event, @Nonnull Project project, @Nullable Editor editor) { EditorTextField textArea = new TextViewer("Evaluating...", project); textArea.setBackground(HintUtil.INFORMATION_COLOR); final FullValueEvaluationCallbackImpl callback = new FullValueEvaluationCallbackImpl(textArea); evaluator.startEvaluation(callback); Dimension size = DimensionService.getInstance().getSize(FULL_VALUE_POPUP_DIMENSION_KEY, project); if (size == null) { Dimension frameSize = TargetAWT.to(WindowManager.getInstance().getWindow(project)).getSize(); size = new Dimension(frameSize.width / 2, frameSize.height / 2); } textArea.setPreferredSize(size); JBPopup popup = createValuePopup(project, textArea, callback); if (editor == null) { Rectangle bounds = new Rectangle(event.getLocationOnScreen(), size); ScreenUtil.fitToScreenVertical(bounds, 5, 5, true); if (size.width != bounds.width || size.height != bounds.height) { size = bounds.getSize(); textArea.setPreferredSize(size); } popup.showInScreenCoordinates(event.getComponent(), bounds.getLocation()); } else { popup.showInBestPositionFor(editor); } }
Example #13
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 #14
Source File: ImplementationViewComponent.java From consulo with Apache License 2.0 | 5 votes |
@Override public void removeNotify() { super.removeNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; EditorFactory.getInstance().releaseEditor(myEditor); disposeNonTextEditor(); }
Example #15
Source File: RunnerContentUi.java From consulo with Apache License 2.0 | 5 votes |
@Override public void removeNotify() { super.removeNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; if (Disposer.isDisposed(RunnerContentUi.this)) return; saveUiState(); }
Example #16
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 #17
Source File: ShowUsagesAction.java From otto-intellij-plugin with Apache License 2.0 | 5 votes |
private static Rectangle fitToScreen(@NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int)rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int)rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
Example #18
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 #19
Source File: DesktopToolWindowPanelImpl.java From consulo with Apache License 2.0 | 5 votes |
/** * Invoked when enclosed frame is being disposed. */ @Override public final void removeNotify() { if (ScreenUtil.isStandardAddRemoveNotify(this)) { Disposer.dispose(myDisposable); } super.removeNotify(); }
Example #20
Source File: DesktopStripePanelImpl.java From consulo with Apache License 2.0 | 5 votes |
/** * Invoked when enclosed frame is being shown. */ @Override public void addNotify() { super.addNotify(); updatePresentation(); KeymapManagerEx.getInstanceEx().addWeakListener(myWeakKeymapManagerListener); if (ScreenUtil.isStandardAddRemoveNotify(this)) { UISettings.getInstance().addUISettingsListener(myUISettingsListener, myDisposable); } }
Example #21
Source File: DesktopStripePanelImpl.java From consulo with Apache License 2.0 | 5 votes |
/** * Invoked when enclosed frame is being disposed. */ @Override public void removeNotify() { KeymapManagerEx.getInstanceEx().removeWeakListener(myWeakKeymapManagerListener); if (ScreenUtil.isStandardAddRemoveNotify(this)) { Disposer.dispose(myDisposable); } super.removeNotify(); }
Example #22
Source File: LafManagerImpl.java From consulo with Apache License 2.0 | 5 votes |
private static Point fixPopupLocation(final Component contents, final int x, final int y) { if (!(contents instanceof JToolTip)) return new Point(x, y); final PointerInfo info; try { info = MouseInfo.getPointerInfo(); } catch (InternalError e) { // http://www.jetbrains.net/jira/browse/IDEADEV-21390 // may happen under Mac OSX 10.5 return new Point(x, y); } int deltaY = 0; if (info != null) { final Point mouse = info.getLocation(); deltaY = mouse.y - y; } final Dimension size = contents.getPreferredSize(); final Rectangle rec = new Rectangle(new Point(x, y), size); ScreenUtil.moveRectangleToFitTheScreen(rec); if (rec.y < y) { rec.y += deltaY; } return rec.getLocation(); }
Example #23
Source File: ShowUsagesAction.java From dagger-intellij-plugin with Apache License 2.0 | 5 votes |
private static Rectangle fitToScreen(@NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int) rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
Example #24
Source File: WindowStateServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
private static boolean isVisible(Point location, Dimension size) { if (location == null) { return size != null; } if (ScreenUtil.isVisible(location)) { return true; } if (size == null) { return false; } return ScreenUtil.isVisible(new Rectangle(location, size)); }
Example #25
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 #26
Source File: JBTabsImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void removeNotify() { super.removeNotify(); setFocused(false); removeTimerUpdate(); if (ScreenUtil.isStandardAddRemoveNotify(this) && myGlassPane != null) { myGlassPane.removeMouseMotionPreprocessor(myTabActionsAutoHideListener); myGlassPane = null; } }
Example #27
Source File: JBTabbedPane.java From consulo with Apache License 2.0 | 5 votes |
@Override public void removeNotify() { super.removeNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; for (int i = 0; i < getTabCount(); i++) { getComponentAt(i).removeHierarchyListener(this); } }
Example #28
Source File: LinkLabel.java From consulo with Apache License 2.0 | 5 votes |
@Override public void removeNotify() { super.removeNotify(); if (ScreenUtil.isStandardAddRemoveNotify(this)) { disableUnderline(); } }
Example #29
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 #30
Source File: IdeFrameDecorator.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isInFullScreen() { JFrame jFrame = getJFrame(); if (jFrame == null) { return false; } Rectangle frameBounds = jFrame.getBounds(); GraphicsDevice device = ScreenUtil.getScreenDevice(frameBounds); return device != null && device.getDefaultConfiguration().getBounds().equals(frameBounds) && jFrame.isUndecorated(); }