@Override protected RelativePoint getPointToShowResults() { Rectangle rect = myEntryTable.getCellRect(myEntryTable.getSelectedRow(), 1, false); Point location = rect.getLocation(); location.y += rect.height; return new RelativePoint(myEntryTable, location); }
@Override public Point getLocationOnScreen() { Dimension headerCorrectionSize = myLocateByContent ? myHeaderPanel.getPreferredSize() : null; Point screenPoint = myContent.getLocationOnScreen(); if (headerCorrectionSize != null) { screenPoint.y -= headerCorrectionSize.height; } return screenPoint; }
private void setSizeAndDimensions( @NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); // table.setPreferredSize(dimension); // table.setMaximumSize(dimension); // table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4 /* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
private RelativePoint relativePointWithDominantRectangle( final JLayeredPane layeredPane, final Rectangle bounds) { Dimension preferredSize = getComponent().getPreferredSize(); if (myDimensionServiceKey != null) { final Dimension dimension = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); if (dimension != null) { preferredSize = dimension; } } final Point leftTopCorner = new Point(bounds.x + bounds.width, bounds.y); final Point leftTopCornerScreen = (Point) leftTopCorner.clone(); SwingUtilities.convertPointToScreen(leftTopCornerScreen, layeredPane); final RelativePoint relativePoint; if (!ScreenUtil.isOutsideOnTheRightOFScreen( new Rectangle( leftTopCornerScreen.x, leftTopCornerScreen.y, preferredSize.width, preferredSize.height))) { relativePoint = new RelativePoint(layeredPane, leftTopCorner); } else { if (bounds.x > preferredSize.width) { relativePoint = new RelativePoint(layeredPane, new Point(bounds.x - preferredSize.width, bounds.y)); } else { setDimensionServiceKey(null); // going to cut width Rectangle screen = ScreenUtil.getScreenRectangle(leftTopCornerScreen.x, leftTopCornerScreen.y); final int spaceOnTheLeft = bounds.x; final int spaceOnTheRight = (screen.x + screen.width) - leftTopCornerScreen.x; if (spaceOnTheLeft > spaceOnTheRight) { relativePoint = new RelativePoint(layeredPane, new Point(0, bounds.y)); myComponent.setPreferredSize( new Dimension(spaceOnTheLeft, Math.max(preferredSize.height, 200))); } else { relativePoint = new RelativePoint(layeredPane, leftTopCorner); myComponent.setPreferredSize( new Dimension(spaceOnTheRight, Math.max(preferredSize.height, 200))); } } } return relativePoint; }
public static Window moveTo( JComponent content, Point screenPoint, final Dimension headerCorrectionSize) { setDefaultCursor(content); final Window wnd = SwingUtilities.getWindowAncestor(content); if (headerCorrectionSize != null) { screenPoint.y -= headerCorrectionSize.height; } wnd.setLocation(screenPoint); return wnd; }
public void show(Component owner, int aScreenX, int aScreenY, final boolean considerForcedXY) { if (ApplicationManagerEx.getApplicationEx() != null && ApplicationManager.getApplication().isHeadlessEnvironment()) return; if (isDisposed()) { throw new IllegalStateException( "Popup was already disposed. Recreate a new instance to show again"); } assert ApplicationManager.getApplication().isDispatchThread(); addActivity(); final boolean shouldShow = beforeShow(); if (!shouldShow) { removeActivity(); return; } prepareToShow(); if (myInStack) { myFocusTrackback = new FocusTrackback(this, owner, true); myFocusTrackback.setMustBeShown(true); } Dimension sizeToSet = null; if (myDimensionServiceKey != null) { sizeToSet = DimensionService.getInstance().getSize(myDimensionServiceKey, myProject); } if (myForcedSize != null) { sizeToSet = myForcedSize; } if (myMinSize == null) { myMinSize = myContent.getMinimumSize(); } if (sizeToSet == null) { sizeToSet = myContent.getPreferredSize(); } if (sizeToSet != null) { sizeToSet.width = Math.max(sizeToSet.width, myMinSize.width); sizeToSet.height = Math.max(sizeToSet.height, myMinSize.height); myContent.setSize(sizeToSet); myContent.setPreferredSize(sizeToSet); } Point xy = new Point(aScreenX, aScreenY); boolean adjustXY = true; if (myDimensionServiceKey != null) { final Point storedLocation = DimensionService.getInstance().getLocation(myDimensionServiceKey, myProject); if (storedLocation != null) { xy = storedLocation; adjustXY = false; } } if (adjustXY) { final Insets insets = myContent.getInsets(); if (insets != null) { xy.x -= insets.left; xy.y -= insets.top; } } if (considerForcedXY && myForcedLocation != null) { xy = myForcedLocation; } if (myLocateByContent) { final Dimension captionSize = myHeaderPanel.getPreferredSize(); xy.y -= captionSize.height; } Rectangle targetBounds = new Rectangle(xy, myContent.getPreferredSize()); Insets insets = myPopupBorder.getBorderInsets(myContent); if (insets != null) { targetBounds.x += insets.left; targetBounds.y += insets.top; } Rectangle original = new Rectangle(targetBounds); if (myLocateWithinScreen) { ScreenUtil.moveRectangleToFitTheScreen(targetBounds); } if (myMouseOutCanceller != null) { myMouseOutCanceller.myEverEntered = targetBounds.equals(original); } myOwner = IdeFrameImpl.findNearestModalComponent(owner); if (myOwner == null) { myOwner = owner; } myRequestorComponent = owner; boolean forcedDialog = (SystemInfo.isMac && !(myOwner instanceof IdeFrame)) || myMayBeParent; PopupComponent.Factory factory = getFactory(myForcedHeavyweight || myResizable, forcedDialog); myNativePopup = factory.isNativePopup(); myPopup = factory.getPopup(myOwner, myContent, targetBounds.x, targetBounds.y); if (myResizable) { final JRootPane root = myContent.getRootPane(); final IdeGlassPaneImpl glass = new IdeGlassPaneImpl(root); root.setGlassPane(glass); final ResizeComponentListener resizeListener = new ResizeComponentListener(this, glass); glass.addMousePreprocessor(resizeListener, this); glass.addMouseMotionPreprocessor(resizeListener, this); } if (myCaption != null && myMovable) { final MoveComponentListener moveListener = new MoveComponentListener(myCaption) { public void mousePressed(final MouseEvent e) { super.mousePressed(e); if (e.isConsumed()) return; if (UIUtil.isCloseClick(e)) { if (myCaption.isWithinPanel(e)) { cancel(); } } } }; ListenerUtil.addMouseListener(myCaption, moveListener); ListenerUtil.addMouseMotionListener(myCaption, moveListener); final MyContentPanel saved = myContent; Disposer.register( this, new Disposable() { public void dispose() { ListenerUtil.removeMouseListener(saved, moveListener); ListenerUtil.removeMouseMotionListener(saved, moveListener); } }); } for (JBPopupListener listener : myListeners) { listener.beforeShown(new LightweightWindowEvent(this)); } myPopup.setRequestFocus(myRequestFocus); myPopup.show(); final Window window = SwingUtilities.getWindowAncestor(myContent); myWindowListener = new MyWindowListener(); window.addWindowListener(myWindowListener); if (myFocusable) { window.setFocusableWindowState(true); window.setFocusable(true); } myWindow = updateMaskAndAlpha(window); if (myWindow instanceof JWindow) { ((JWindow) myWindow).getRootPane().putClientProperty(KEY, this); } if (myWindow != null) { // dialogwrapper-based popups do this internally through peer, // for other popups like jdialog-based we should exclude them manually, but // we still have to be able to use IdeFrame as parent if (!myMayBeParent && !(myWindow instanceof Frame)) { WindowManager.getInstance().doNotSuggestAsParent(myWindow); } } final Runnable afterShow = new Runnable() { public void run() { if (myPreferredFocusedComponent != null && myInStack && myFocusable) { myFocusTrackback.registerFocusComponent(myPreferredFocusedComponent); } removeActivity(); afterShow(); } }; if (myRequestFocus) { getFocusManager() .requestFocus( new FocusCommand() { @Override public ActionCallback run() { if (isDisposed()) { removeActivity(); return new ActionCallback.Done(); } _requestFocus(); final ActionCallback result = new ActionCallback(); final Runnable afterShowRunnable = new Runnable() { @Override public void run() { afterShow.run(); result.setDone(); } }; if (myNativePopup) { final FocusRequestor furtherRequestor = getFocusManager().getFurtherRequestor(); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (isDisposed()) { result.setRejected(); return; } furtherRequestor .requestFocus( new FocusCommand() { @Override public ActionCallback run() { if (isDisposed()) { return new ActionCallback.Rejected(); } _requestFocus(); afterShowRunnable.run(); return new ActionCallback.Done(); } }, true) .notify(result) .doWhenProcessed( new Runnable() { @Override public void run() { removeActivity(); } }); } }); } else { afterShowRunnable.run(); } return result; } }, true) .doWhenRejected( new Runnable() { @Override public void run() { afterShow.run(); } }); } else { SwingUtilities.invokeLater( new Runnable() { @Override public void run() { if (isDisposed()) { removeActivity(); return; } afterShow.run(); } }); } }
@Override @SuppressWarnings("deprecation") public void show() { myFocusTrackback = new FocusTrackback(getDialogWrapper(), getParent(), true); final DialogWrapper dialogWrapper = getDialogWrapper(); boolean isAutoAdjustable = dialogWrapper.isAutoAdjustable(); Point location = null; if (isAutoAdjustable) { pack(); Dimension packedSize = getSize(); Dimension minSize = getMinimumSize(); setSize( Math.max(packedSize.width, minSize.width), Math.max(packedSize.height, minSize.height)); setSize( (int) (getWidth() * dialogWrapper.getHorizontalStretch()), (int) (getHeight() * dialogWrapper.getVerticalStretch())); // Restore dialog's size and location myDimensionServiceKey = dialogWrapper.getDimensionKey(); if (myDimensionServiceKey != null) { final Project projectGuess = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this)); location = DimensionService.getInstance().getLocation(myDimensionServiceKey, projectGuess); Dimension size = DimensionService.getInstance().getSize(myDimensionServiceKey, projectGuess); if (size != null) { myInitialSize = new Dimension(size); _setSizeForLocation(myInitialSize.width, myInitialSize.height, location); } } if (myInitialSize == null) { myInitialSize = getSize(); } } if (location == null) { location = dialogWrapper.getInitialLocation(); } if (location != null) { setLocation(location); } else { setLocationRelativeTo(getOwner()); } if (isAutoAdjustable) { final Rectangle bounds = getBounds(); ScreenUtil.fitToScreen(bounds); setBounds(bounds); } addWindowListener( new WindowAdapter() { @Override public void windowActivated(WindowEvent e) { final DialogWrapper wrapper = getDialogWrapper(); if (wrapper != null && myFocusTrackback != null) { myFocusTrackback.cleanParentWindow(); myFocusTrackback.registerFocusComponent( new FocusTrackback.ComponentQuery() { @Override public Component getComponent() { return wrapper.getPreferredFocusedComponent(); } }); } } @Override public void windowDeactivated(WindowEvent e) { if (!isModal()) { final Ref<IdeFocusManager> focusManager = new Ref<IdeFocusManager>(null); Project project = getProject(); if (project != null && !project.isDisposed()) { focusManager.set(getFocusManager()); focusManager .get() .doWhenFocusSettlesDown( new Runnable() { @Override public void run() { disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get()); } }); } else { disposeFocusTrackbackIfNoChildWindowFocused(focusManager.get()); } } } @Override public void windowOpened(WindowEvent e) { if (!SystemInfo.isMacOSLion) return; Window window = e.getWindow(); if (window instanceof Dialog) { ID _native = MacUtil.findWindowForTitle(((Dialog) window).getTitle()); if (_native != null && _native.intValue() > 0) { // see MacMainFrameDecorator // NSCollectionBehaviorFullScreenAuxiliary = 1 << 8 Foundation.invoke(_native, "setCollectionBehavior:", 1 << 8); } } } }); if (Registry.is("actionSystem.fixLostTyping")) { final IdeEventQueue queue = IdeEventQueue.getInstance(); if (queue != null) { queue.getKeyEventDispatcher().resetState(); } // if (myProject != null) { // Project project = myProject.get(); // if (project != null && !project.isDisposed() && project.isInitialized()) { // // IdeFocusManager.findInstanceByComponent(this).requestFocus(new // MyFocusCommand(dialogWrapper), true); // } // } } if (SystemInfo.isMac && myProject != null && Registry.is("ide.mac.fix.dialog.showing") && !dialogWrapper.isModalProgress()) { final IdeFrame frame = WindowManager.getInstance().getIdeFrame(myProject.get()); AppIcon.getInstance().requestFocus(frame); } setBackground(UIUtil.getPanelBackground()); final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); if (app != null && !app.isLoaded() && Splash.BOUNDS != null) { final Point loc = getLocation(); loc.y = Splash.BOUNDS.y + Splash.BOUNDS.height; setLocation(loc); } super.show(); }