/** * Positions the specified dialog at a position relative to its parent. * * @param dialog the dialog to be positioned. * @param horizontalPercent the relative location. * @param verticalPercent the relative location. */ public static void positionDialogRelativeToParent( final Dialog dialog, final double horizontalPercent, final double verticalPercent) { final Container parent = dialog.getParent(); if (parent == null || (parent.isVisible() == false)) { positionFrameOnScreen(dialog, horizontalPercent, verticalPercent); return; } final Dimension d = dialog.getSize(); final Dimension p = parent.getSize(); final int baseX = parent.getX(); final int baseY = parent.getY(); final int parentPointX = baseX + (int) (horizontalPercent * p.width); final int parentPointY = baseY + (int) (verticalPercent * p.height); final int dialogPointX = parentPointX - (int) (horizontalPercent * d.width); final int dialogPointY = parentPointY - (int) (verticalPercent * d.height); // make sure the dialog fits completely on the screen... final Rectangle s = parent.getGraphicsConfiguration().getBounds(); final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height); final Rectangle intersectedDialogBounds = r.intersection(s); if (intersectedDialogBounds.width < d.width) { r.x = s.width - d.width; r.width = d.width; } if (intersectedDialogBounds.height < d.height) { r.y = s.height - d.height; r.height = d.height; } final Rectangle finalIntersection = r.intersection(s); dialog.setBounds(finalIntersection); }
/** * Add a component in the list of components that should be refreshed. If <i>c</i> already has a * dirty region, the rectangle <i>(x,y,w,h)</i> will be unioned with the region that should be * redrawn. * * @param c Component to repaint, null results in nothing happening. * @param x X coordinate of the region to repaint * @param y Y coordinate of the region to repaint * @param w Width of the region to repaint * @param h Height of the region to repaint * @see JComponent#repaint */ @Override public void addDirtyRegion(JComponent c, int x, int y, int w, int h) { Rectangle dirtyRegion = getDirtyRegion(c); if (dirtyRegion.width == 0 && dirtyRegion.height == 0) { int lastDeltaX = c.getX(); int lastDeltaY = c.getY(); Container parent = c.getParent(); while (parent instanceof JComponent) { if (!parent.isVisible() || !parent.isDisplayable()) { return; } if (parent instanceof JXPanel && (((JXPanel) parent).getAlpha() < 1f || !parent.isOpaque())) { x += lastDeltaX; y += lastDeltaY; lastDeltaX = lastDeltaY = 0; c = (JComponent) parent; } lastDeltaX += parent.getX(); lastDeltaY += parent.getY(); parent = parent.getParent(); } } super.addDirtyRegion(c, x, y, w, h); }
private void disposeAndUpdate(boolean update) { if (myView != null) { boolean visible = myView.isVisible(); myView.setVisible(false); Container container = myContent.getParent(); if (container != null) { container.remove(myContent); } if (myView instanceof Window) { myViewBounds = myView.getBounds(); Window window = (Window) myView; if (!push(UIUtil.getWindow(myOwner), window)) { window.dispose(); } } else { Container parent = myView.getParent(); if (parent == null) { myViewBounds = new Rectangle(myContent.getPreferredSize()); } else { myViewBounds = new Rectangle(myView.getBounds()); parent.remove(myView); Point point = new Point(myViewBounds.x, myViewBounds.y); SwingUtilities.convertPointToScreen(point, parent); myViewBounds.x = point.x; myViewBounds.y = point.y; } } myView = null; if (update && visible) { setVisible(true); } } }
/** see: http://www.javakey.net/4-java-gui/686df4a3d194cade.htm */ private synchronized void startModal() { if (this.isVisible() && !this.isShowing()) { Container parent = this.getParent(); while (parent != null) { if (parent.isVisible() == false) { parent.setVisible(true); } parent = parent.getParent(); } } try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = getToolkit().getSystemEventQueue(); while (this.isVisible()) { AWTEvent event = theQueue.getNextEvent(); Object source = event.getSource(); if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else if (source instanceof Component) { ((Component) source).dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { System.err.println("Unable to dispatch: " + event); } } } else { while (this.isVisible()) { wait(); } } } catch (InterruptedException e) { e.printStackTrace(); } }
public void paintComponent(Graphics g) { if (!useAnimation || c.isVisible()) { super.paintComponent(g); } else { // within netbeans, it happens we arrive here and the image has not been // created yet. We ensure it is. if (img == null) { makeImage(); } // and we paint it only if it has been created and only if we have a // valid graphics if (g != null && img != null) { // draw the image with y being height - imageHeight g.drawImage(img, 0, getHeight() - img.getHeight(), null); } } }
private void setBounds(Point location, Dimension size) { if (myView != null) { if (size == null) { size = myView.getSize(); } if (location == null) { location = myView.getLocation(); } else { Component parent = myView instanceof Window ? null : myView.getParent(); if (parent != null) { SwingUtilities.convertPointFromScreen(location, parent); } } myView.setBounds(location.x, location.y, size.width, size.height); if (myView.isVisible()) { myView.invalidate(); myView.validate(); myView.repaint(); } } }
/** Determines whether this popup should be visible. */ public boolean isVisible() { return myView != null && myView.isVisible(); }