private static boolean willPopupBeContained(JPopupMenu popup, Point origin) { if (!popup.isShowing()) { return false; } Window w = SwingUtilities.windowForComponent(popup.getInvoker()); Rectangle r = new Rectangle(origin, popup.getSize()); return (w != null) && w.getBounds().contains(r); }
/** Tries to resize wizard wisely if needed. Keeps "display inertia" so that * wizard is only enlarged, not shrinked, and location is changed only when * wizard window exceeds screen bounds after resize. */ private void resizeWizard(Window parentWindow, Dimension prevSize) { assert SwingUtilities.isEventDispatchThread () : "getComponent() must be called in EQ only."; Dimension curSize = data.getIterator(this).current().getComponent().getPreferredSize(); // only enlarge if needed, don't shrink if ((curSize.width > prevSize.width) || (curSize.height > prevSize.height)) { Rectangle origBounds = parentWindow.getBounds(); int newWidth = Math.max(origBounds.width + (curSize.width - prevSize.width), origBounds.width); int newHeight = Math.max(origBounds.height + (curSize.height - prevSize.height), origBounds.height); Rectangle screenBounds = Utilities.getUsableScreenBounds(); Rectangle newBounds; // don't allow to exceed screen size, center if needed if (((origBounds.x + newWidth) > screenBounds.width) || ((origBounds.y + newHeight) > screenBounds.height)) { newWidth = Math.min(screenBounds.width, newWidth); newHeight = Math.min(screenBounds.height, newHeight); newBounds = Utilities.findCenterBounds(new Dimension(newWidth, newHeight)); } else { newBounds = new Rectangle(origBounds.x, origBounds.y, newWidth, newHeight); } parentWindow.setBounds(newBounds); parentWindow.invalidate(); parentWindow.validate(); parentWindow.repaint(); } }
private boolean getShouldPaintGrip() { Rectangle rect = window.getBounds(); Dimension dim = getToolkit().getScreenSize(); if((rect.x == rect.y) && (rect.x <= 0) && (rect.x>-20) && (dim.width-20<rect.width) && (dim.width +20 > rect.width)) return false; return true; }
@Override public Rectangle getBounds() { return getOwner().getBounds(); } }
button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); Window window = SwingUtilities.windowForComponent(button); JDialog dialog = new JDialog(); dialog.setBounds( window.getBounds() ); dialog.setVisible(true); } });
public Rectangle getBounds() { return getOwner().getBounds(); } }
/** * Sets the location of the window to the middle of the screen * * @param window - component whos location is set. */ private static void setLocation(Window window) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle bounds = window.getBounds(); window.setLocation((screenDim.width - bounds.width) / 2, (screenDim.height - bounds.height) / 2); }
/** Centers the given window within the specified parent window. */ public static void centerWindow(final Window parent, final Window window) { centerWindow(parent.getBounds(), window); }
private void store(Window w) { String bounds = (String)ConverterRegistry.instance().convert( String.class, w.getBounds()); node().node("Windows").put(w.getName() + ".bounds", bounds); } };
/** * Center the window at the top of the main screen. */ public static void centerTopWindow (Window win) { Rectangle devBounds = mainBounds (); Rectangle winBounds = win.getBounds (); int lmargin = (devBounds.width - winBounds.width) / 2; // Don't go off the edge if (lmargin < 0) { lmargin = 0; } win.setLocation (lmargin, 0); }
private static boolean willPopupBeContained(JPopupMenu popup, Point origin) { if (!popup.isShowing()) { return false; } Window w = SwingUtilities.windowForComponent (popup.getInvoker()); Rectangle r = new Rectangle (origin, popup.getSize ()); return w != null && w.getBounds ().contains (r); }
/** * Center the window on the main screen. */ public static void centerWindow (Window win) { Rectangle devBounds = mainBounds (); Rectangle winBounds = win.getBounds (); int lmargin = (devBounds.width - winBounds.width) / 2; int tmargin = (devBounds.height - winBounds.height) / 2; // Don't go off the edge if (lmargin < 0) { lmargin = 0; } if (tmargin < 0) { tmargin = 0; } win.setLocation (lmargin, tmargin); }
private static boolean willPopupBeContained(JPopupMenu popup, Point origin) { if (!popup.isShowing()) { return false; } Window w = SwingUtilities.windowForComponent (popup.getInvoker()); Rectangle r = new Rectangle (origin, popup.getSize ()); return w != null && w.getBounds ().contains (r); }
@Override public void componentMoved(ComponentEvent evt) { if(System.currentTimeMillis() - start < 1000L) { Rectangle r = win.getBounds(); if(!windowOpened && r.equals(required)) return; if(!r.equals(desired)) { Log.log(Log.DEBUG,GUIUtilities.class, "Window resize blocked: " + win.getBounds()); win.setBounds(desired); } } win.removeComponentListener(this); } //}}}
@Override public void actionPerformed(ActionEvent e) { LayerSourceAssistantPane pane = new LayerSourceAssistantPane(SwingUtilities.getWindowAncestor(control), "Add Layer"); final Map<String, LayerSourceDescriptor> layerSourceDescriptors1 = LayerManager.getDefault().getLayerSourceDescriptors(); final LayerSourceDescriptor[] layerSourceDescriptors2 = layerSourceDescriptors1.values().toArray(new LayerSourceDescriptor[layerSourceDescriptors1.size()]); pane.show(new SelectLayerSourceAssistantPage(layerSourceDescriptors2), screenBounds); screenBounds = pane.getWindow().getBounds(); } }
public static void show(@NotNull Project project, @NotNull List<ServerConfig> configs, @NotNull ChooseListener listener) { ChooseLabelDialog dialog = new ChooseLabelDialog(project, configs, listener); dialog.pack(); final Dimension bounds = dialog.getSize(); final Rectangle parentBounds = dialog.getOwner().getBounds(); dialog.setLocation(parentBounds.x + (parentBounds.width - bounds.width) / 2, parentBounds.y + (parentBounds.height - bounds.height) / 2); dialog.setVisible(true); }
private void centreOnOwner() { Dimension frameSize = this.getSize(); Rectangle mainrect = getOwner().getBounds(); int x = mainrect.x + (mainrect.width - frameSize.width) / 2; int y = mainrect.y + (mainrect.height - frameSize.height) / 2; this.setLocation(x, y); }
/** * Centers a frame on parent frame. * * @param parent parent frame * @param frame the frame to center */ public static void centerOnWindow(Window parent, Window frame) { Rectangle screenBounds = parent.getBounds(); int x = screenBounds.x + screenBounds.width / 2 - frame.getWidth() / 2; int y = screenBounds.y + screenBounds.height / 2 - frame.getHeight() / 2; frame.setLocation(x, y); }
@Override public void actionPerformed(ActionEvent e) { LayerSourceAssistantPane pane = new LayerSourceAssistantPane(SwingUtilities.getWindowAncestor(control), "Add Layer", getAppContext()); LayerSourceDescriptor[] layerSourceDescriptors = BeamUiActivator.getInstance().getLayerSources(); pane.show(new SelectLayerSourceAssistantPage(layerSourceDescriptors), screenBounds); screenBounds = pane.getWindow().getBounds(); } }
public static void center(final Window window) { if (window == null) { return; } final Window owner = window.getOwner(); if (owner == null || owner.getBounds().equals(new Rectangle(0, 0, 0, 0))) { centerToScreen(window); return; } final int x = owner.getX() + owner.getWidth() / 2 - window.getWidth() / 2; final int y = owner.getY() + owner.getHeight() / 2 - window.getHeight() / 2; window.setLocation(x < 0 ? 0 : x, y < 0 ? 0 : y); }