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); }
/* * 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(); }
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(); } } } }