private boolean noIntersections(Rectangle bounds) { Window owner = SwingUtilities.getWindowAncestor(myComponent); Window popup = SwingUtilities.getWindowAncestor(myTipComponent); Window focus = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow(); if (focus == owner.getOwner()) { focus = null; // do not check intersection with parent } boolean focused = SystemInfo.isWindows || owner.isFocused(); for (Window other : owner.getOwnedWindows()) { if (!focused && !SystemInfo.isWindows) { focused = other.isFocused(); } if (popup != other && other.isVisible() && bounds.x + 10 >= other.getX() && bounds.intersects(other.getBounds())) { return false; } if (focus == other) { focus = null; // already checked } } return focused && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds())); }
@Override public void moveToFitScreen() { if (myPopup == null) return; final Window popupWindow = SwingUtilities.windowForComponent(myContent); Rectangle bounds = popupWindow.getBounds(); ScreenUtil.moveRectangleToFitTheScreen(bounds); setLocation(bounds.getLocation()); setSize(bounds.getSize(), false); }
public boolean isInsideHint(RelativePoint target) { if (myComponent == null || !myComponent.isShowing()) return false; if (myIsRealPopup) { Window wnd = SwingUtilities.getWindowAncestor(myComponent); return wnd.getBounds().contains(target.getScreenPoint()); } else if (myCurrentIdeTooltip != null) { return myCurrentIdeTooltip.isInside(target); } else { return new Rectangle(myComponent.getLocationOnScreen(), myComponent.getSize()) .contains(target.getScreenPoint()); } }
/* * Delegate initialization (create native window and all the * related resources). */ @Override // PlatformWindow public void initialize(Window _target, LWWindowPeer _peer, PlatformWindow _owner) { initializeBase(_target, _peer, _owner, new CPlatformView()); final int styleBits = getInitialStyleBits(); responder = createPlatformResponder(); contentView = createContentView(); contentView.initialize(peer, responder); final long ownerPtr = owner != null ? owner.getNSWindowPtr() : 0L; Rectangle bounds; if (!IS(DECORATED, styleBits)) { // For undecorated frames the move/resize event does not come if the frame is centered on the // screen // so we need to set a stub location to force an initial move/resize. Real bounds would be set // later. bounds = new Rectangle(0, 0, 1, 1); } else { bounds = _peer.constrainBounds(_target.getBounds()); } final long nativeWindowPtr = nativeCreateNSWindow( contentView.getAWTView(), ownerPtr, styleBits, bounds.x, bounds.y, bounds.width, bounds.height); setPtr(nativeWindowPtr); if (target instanceof javax.swing.RootPaneContainer) { final javax.swing.JRootPane rootpane = ((javax.swing.RootPaneContainer) target).getRootPane(); if (rootpane != null) rootpane.addPropertyChangeListener( "ancestor", new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { CLIENT_PROPERTY_APPLICATOR.attachAndApplyClientProperties(rootpane); rootpane.removePropertyChangeListener("ancestor", this); } }); } validateSurface(); }
/** * Enter full-screen mode, or return to windowed mode. The entered full-screen mode may be either * exclusive or simulated. Exclusive mode is only available if <code>isFullScreenSupported</code> * returns <code>true</code>. * * <p>Exclusive mode implies: * * <ul> * <li>Windows cannot overlap the full-screen window. All other application windows will always * appear beneath the full-screen window in the Z-order. * <li>There can be only one full-screen window on a device at any time, so calling this method * while there is an existing full-screen Window will cause the existing full-screen window * to return to windowed mode. * <li>Input method windows are disabled. It is advisable to call <code> * Component.enableInputMethods(false)</code> to make a component a non-client of the input * method framework. * </ul> * * <p>Simulated full-screen mode resizes the window to the size of the screen and positions it at * (0,0). * * <p>When entering full-screen mode, if the window to be used as a full-screen window is not * visible, this method will make it visible. It will remain visible when returning to windowed * mode. * * <p>When entering full-screen mode, all the translucency effects are reset for the window. Its * shape is set to {@code null}, the opacity value is set to 1.0f, and the background color alpha * is set to 255 (completely opaque). These values are not restored when returning to windowed * mode. * * <p>When returning to windowed mode from an exclusive full-screen window, any display changes * made by calling {@code setDisplayMode} are automatically restored to their original state. * * @param w a window to use as the full-screen window; {@code null} if returning to windowed mode. * Some platforms expect the fullscreen window to be a top-level component (i.e., a {@code * Frame}); therefore it is preferable to use a {@code Frame} here rather than a {@code * Window}. * @see #isFullScreenSupported * @see #getFullScreenWindow * @see #setDisplayMode * @see Component#enableInputMethods * @see Component#setVisible * @since 1.4 */ public void setFullScreenWindow(Window w) { if (w != null) { if (w.getShape() != null) { w.setShape(null); } if (w.getOpacity() < 1.0f) { w.setOpacity(1.0f); } if (!w.isOpaque()) { Color bgColor = w.getBackground(); bgColor = new Color(bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 255); w.setBackground(bgColor); } } if (fullScreenWindow != null && windowedModeBounds != null) { // if the window went into fs mode before it was realized it may // have (0,0) dimensions if (windowedModeBounds.width == 0) windowedModeBounds.width = 1; if (windowedModeBounds.height == 0) windowedModeBounds.height = 1; fullScreenWindow.setBounds(windowedModeBounds); } // Set the full screen window synchronized (fsAppContextLock) { // Associate fullscreen window with current AppContext if (w == null) { fullScreenAppContext = null; } else { fullScreenAppContext = AppContext.getAppContext(); } fullScreenWindow = w; } if (fullScreenWindow != null) { windowedModeBounds = fullScreenWindow.getBounds(); // Note that we use the graphics configuration of the device, // not the window's, because we're setting the fs window for // this device. Rectangle screenBounds = getDefaultConfiguration().getBounds(); fullScreenWindow.setBounds( screenBounds.x, screenBounds.y, screenBounds.width, screenBounds.height); fullScreenWindow.setVisible(true); fullScreenWindow.toFront(); } }
boolean overlappedByOwnedWindow() { Component component = getComponent(); if (owner != null && component != null) { Window w = SwingUtilities.getWindowAncestor(owner); if (w == null) { return false; } Window[] ownedWindows = w.getOwnedWindows(); if (ownedWindows != null) { Rectangle bnd = component.getBounds(); for (Window window : ownedWindows) { if (window.isVisible() && bnd.intersects(window.getBounds())) { return true; } } } } return false; }
public void mouseDragged(MouseEvent ev) { Window w = (Window) ev.getSource(); Point pt = ev.getPoint(); if (isMovingWindow) { Point windowPt; try { windowPt = (Point) AccessController.doPrivileged(getLocationAction); windowPt.x = windowPt.x - dragOffsetX; windowPt.y = windowPt.y - dragOffsetY; w.setLocation(windowPt); } catch (PrivilegedActionException e) { } } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust( r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust( r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust( r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } }