public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl(ApplicationInfoEx.getInstanceEx(), 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)); } fixForOracleBug8007219(frame); frame.setBounds(myFrameBounds); frame.setExtendedState(myFrameExtendedState); frame.setVisible(true); }
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(); }
private static GraphicsDevice getScreen(Object object) { if (object == null) { return null; } 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); return null; } } if (object instanceof Window) { Window window = (Window)object; object = ScreenUtil.getScreenDevice(window.getBounds()); if (object == null) { LOG.warn("cannot find a screen for " + window); return null; } } if (object instanceof GraphicsDevice) { return (GraphicsDevice)object; } LOG.warn("cannot find a screen for " + object); return null; }
public void setMaximized() { if (Registry.is("darcula.fix.maximized.frame.bounds")) return; Component tla = myRootPane.getTopLevelAncestor(); GraphicsConfiguration gc = (currentRootPaneGC != null) ? currentRootPaneGC : tla.getGraphicsConfiguration(); Rectangle screenBounds = gc.getBounds(); screenBounds.x = 0; screenBounds.y = 0; Insets screenInsets = ScreenUtil.getScreenInsets(gc); Rectangle maxBounds = new Rectangle( (screenBounds.x + screenInsets.left), (screenBounds.y + screenInsets.top), screenBounds.width - ((screenInsets.left + screenInsets.right)), screenBounds.height - ((screenInsets.top + screenInsets.bottom))); if (tla instanceof JFrame) { ((JFrame)tla).setMaximizedBounds(maxBounds); } }
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(); }
private static void append(StringBuilder sb, GraphicsDevice device) { append(sb, "id", device.getIDstring()); append(sb, "type", getTypeName(device.getType())); append(sb, device.getDisplayMode()); GraphicsConfiguration configuration = device.getDefaultConfiguration(); append(sb, "outer", configuration.getBounds()); append(sb, "inner", ScreenUtil.getScreenRectangle(configuration)); append(sb, "default image", configuration.getImageCapabilities()); BufferCapabilities capabilities = configuration.getBufferCapabilities(); append(sb, "front buffer image", capabilities.getFrontBufferCapabilities()); append(sb, "back buffer image", capabilities.getBackBufferCapabilities()); sb.append("page flipping: ").append(capabilities.getFlipContents()); if (capabilities.isFullScreenRequired()) { sb.append("; full-screen exclusive mode is required"); } if (capabilities.isMultiBufferAvailable()) { sb.append("; more than two buffers can be used"); } sb.append("\n"); }
@Nullable public synchronized Point getLocation(@NotNull String key, Project project) { key = realKey(key, project); Point point = myKey2Location.get(key); if (point != null) { if (!ScreenUtil.getScreenRectangle(point).contains(point)){ point = null; } } if(point!=null){ return (Point)point.clone(); }else{ return null; } }
public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl(myApplicationInfoEx, myActionManager, myUiSettings, myDataManager, ApplicationManager.getApplication()); myProject2Frame.put(null, frame); if (myFrameBounds == null || !ScreenUtil.isVisible(myFrameBounds)) { //avoid situations when IdeFrame is out of all screens Rectangle rect = ScreenUtil.getMainScreenBounds(); int yParts = rect.height / 6; int xParts = rect.width / 5; myFrameBounds = new Rectangle(xParts, yParts, xParts * 3, yParts * 4); } frame.setBounds(myFrameBounds); frame.setExtendedState(myFrameExtendedState); frame.setVisible(true); }
@Override public void show(final Component owner, final int aScreenX, final int aScreenY, final boolean considerForcedXY) { LOG.assertTrue (!isDisposed()); Rectangle targetBounds = new Rectangle(new Point(aScreenX, aScreenY), getContent().getPreferredSize()); ScreenUtil.moveRectangleToFitTheScreen(targetBounds); if (getParent() != null) { final Rectangle parentBounds = getParent().getBounds(); parentBounds.x += STEP_X_PADDING; parentBounds.width -= STEP_X_PADDING * 2; if (parentBounds.intersects(targetBounds)) { targetBounds.x = getParent().getBounds().x - targetBounds.width - STEP_X_PADDING; } } if (getParent() == null) { PopupDispatcher.setActiveRoot(this); } else { PopupDispatcher.setShowing(this); } LOG.assertTrue (!isDisposed(), "Disposed popup, parent="+getParent()); super.show(owner, targetBounds.x, targetBounds.y, true); }
protected void restoreSizeAndLocation() { // Dialog's size and location: migrate to DialogWrapper to avoid need for our own code Point location = null; Dimension size = null; dimensionKey = getDimensionKey(); if (dimensionKey != null) { location = DimensionService.getInstance().getLocation(dimensionKey, project); size = DimensionService.getInstance().getSize(dimensionKey, project); } if (location != null) { setLocation(location); } else { centerOnOwner(); } if (size != null) { setSize(size.width, size.height); } Rectangle bounds = getBounds(); ScreenUtil.fitToScreen(bounds); setBounds(bounds); }
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)); }
public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl(ApplicationInfoEx.getInstanceEx(), 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)); } frame.setBounds(myFrameBounds); frame.setExtendedState(myFrameExtendedState); frame.setVisible(true); }
@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(); }
@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; }
@NotNull public static Dimension getDefaultDiffWindowSize() { Rectangle screenBounds = ScreenUtil.getMainScreenBounds(); int width = (int)(screenBounds.width * 0.8); int height = (int)(screenBounds.height * 0.8); return new Dimension(width, height); }
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; }
@Nullable public synchronized Point getLocation(@NotNull String key, Project project) { Point point = myKey2Location.get(realKey(key, project)); if (point != null && !ScreenUtil.getScreenRectangle(point).contains(point)) { point = null; } return point != null ? (Point)point.clone() : null; }
@Override public void addNotify() { super.addNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; myGlassPane = IdeGlassPaneUtil.find(this); if (myGlassPane != null) { myGlassPane.addMouseMotionPreprocessor(this, myDisposable); } }
@Override public void removeNotify() { super.removeNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; Disposer.dispose(myDisposable); }
@Override public void removeNotify() { super.removeNotify(); if (!ScreenUtil.isStandardAddRemoveNotify(this)) return; for (int i=0; i<getTabCount(); i++) { getComponentAt(i).removeHierarchyListener(this); } }
@Override public void setupFrame(JFrame frame) { frame.setResizable(false); frame.pack(); Point location = DimensionService.getInstance().getLocation(WelcomeFrame.DIMENSION_KEY, null); Rectangle screenBounds = ScreenUtil.getScreenRectangle(location != null ? location : new Point(0, 0)); frame.setLocation(new Point( screenBounds.x + (screenBounds.width - frame.getWidth()) / 2, screenBounds.y + (screenBounds.height - frame.getHeight()) / 3 )); }
/** * 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); } }
/** * Invoked when enclosed frame is being disposed. */ @Override public void removeNotify() { KeymapManagerEx.getInstanceEx().removeWeakListener(myWeakKeymapManagerListener); if (ScreenUtil.isStandardAddRemoveNotify(this)) { Disposer.dispose(myDisposable); } super.removeNotify(); }
private void fixForOracleBug8007219(IdeFrameImpl frame) { if ((myFrameExtendedState & Frame.MAXIMIZED_BOTH) > 0 && Patches.JDK_BUG_ID_8007219) { final Rectangle screenBounds = ScreenUtil.getMainScreenBounds(); final Insets screenInsets = ScreenUtil.getScreenInsets(frame.getGraphicsConfiguration()); final int leftGap = myFrameBounds.x - screenInsets.left; myFrameBounds.x = leftGap > ORACLE_BUG_8007219_THRESHOLD ? myFrameBounds.x : screenInsets.left + ORACLE_BUG_8007219_THRESHOLD + 1; final int topGap = myFrameBounds.y - screenInsets.top; myFrameBounds.y = topGap > ORACLE_BUG_8007219_THRESHOLD ? myFrameBounds.y : screenInsets.top + ORACLE_BUG_8007219_THRESHOLD + 1; final int maximumFrameWidth = screenBounds.width - screenInsets.right - myFrameBounds.x; final int rightGap = maximumFrameWidth - myFrameBounds.width; myFrameBounds.width = rightGap > ORACLE_BUG_8007219_THRESHOLD ? myFrameBounds.width : maximumFrameWidth - ORACLE_BUG_8007219_THRESHOLD - 1; final int maximumFrameHeight = screenBounds.height - screenInsets.bottom - myFrameBounds.y; final int bottomGap = maximumFrameHeight - myFrameBounds.height; myFrameBounds.height = bottomGap > ORACLE_BUG_8007219_THRESHOLD ? myFrameBounds.height : - ORACLE_BUG_8007219_THRESHOLD - 1; } }
@Override public boolean isInFullScreen() { if (myFrame == null) return false; Rectangle frameBounds = myFrame.getBounds(); GraphicsDevice device = ScreenUtil.getScreenDevice(frameBounds); return device != null && device.getDefaultConfiguration().getBounds().equals(frameBounds) && myFrame.isUndecorated(); }
@Override public ActionCallback toggleFullScreen(boolean state) { if (myFrame == null) return ActionCallback.REJECTED; GraphicsDevice device = ScreenUtil.getScreenDevice(myFrame.getBounds()); if (device == null) return ActionCallback.REJECTED; try { myFrame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, Boolean.TRUE); if (state) { myFrame.getRootPane().putClientProperty("oldBounds", myFrame.getBounds()); } myFrame.dispose(); myFrame.setUndecorated(state); } finally { if (state) { myFrame.setBounds(device.getDefaultConfiguration().getBounds()); } else { Object o = myFrame.getRootPane().getClientProperty("oldBounds"); if (o instanceof Rectangle) { myFrame.setBounds((Rectangle)o); } } myFrame.setVisible(true); myFrame.getRootPane().putClientProperty(ScreenUtil.DISPOSE_TEMPORARY, null); notifyFrameComponents(state); } return ActionCallback.DONE; }
/** * Invoked when enclosed frame is being shown. */ public final void addNotify() { super.addNotify(); if (ScreenUtil.isStandardAddRemoveNotify(this)) { UISettings.getInstance().addUISettingsListener(myUISettingsListener, myDisposable); } }
/** * Invoked when enclosed frame is being disposed. */ public final void removeNotify() { if (ScreenUtil.isStandardAddRemoveNotify(this)) { Disposer.dispose(myDisposable); } super.removeNotify(); }
@Override public void removeNotify() { if (ScreenUtil.isStandardAddRemoveNotify(this)) { if (myAnimator != null) { myAnimator.suspend(); } Disposer.dispose(myDisposable); } super.removeNotify(); }
@Override public void setSize(int width, int height) { Point location = getLocation(); Rectangle rect = new Rectangle(location.x, location.y, width, height); ScreenUtil.fitToScreen(rect); if (location.x != rect.x || location.y != rect.y) { setLocation(rect.x, rect.y); } super.setSize(rect.width, rect.height); }
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)); }
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(new Runnable() { @Override public void run() { window.myUiContainer.setPreferredSize(null); } }); }
@Override public void show(final Component owner, final int aScreenX, final int aScreenY, final boolean considerForcedXY) { LOG.assertTrue (!isDisposed()); Rectangle targetBounds = new Rectangle(new Point(aScreenX, aScreenY), getContent().getPreferredSize()); if (getParent() != null) { final Rectangle parentBounds = getParent().getBounds(); parentBounds.x += STEP_X_PADDING; parentBounds.width -= STEP_X_PADDING * 2; ScreenUtil.moveToFit(targetBounds, ScreenUtil.getScreenRectangle( parentBounds.x + parentBounds.width / 2, parentBounds.y + parentBounds.height / 2), null); if (parentBounds.intersects(targetBounds)) { targetBounds.x = getParent().getBounds().x - targetBounds.width - STEP_X_PADDING; } } else { ScreenUtil.moveToFit(targetBounds, ScreenUtil.getScreenRectangle(aScreenX + 1, aScreenY + 1), null); } if (getParent() == null) { PopupDispatcher.setActiveRoot(this); } else { PopupDispatcher.setShowing(this); } LOG.assertTrue (!isDisposed(), "Disposed popup, parent="+getParent()); super.show(owner, targetBounds.x, targetBounds.y, true); }
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); }
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(); }
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(); }
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(); }
public static void showValuePopup(@NotNull XFullValueEvaluator evaluator, @NotNull MouseEvent event, @NotNull 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 = WindowManager.getInstance().getFrame(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); } }