/** * Centers the given window on its parent window or, if it has no parent, on * the screen. * * @param window Window to be centered. */ public static void centerOnParent( @NotNull final Window window ) { centerOnComponent( window, window.getParent() ); }
/** * Loads a windows's geometry from the properties. * The geometry is loaded from the <code><i>name</i>.x</code>, * <code><i>name</i>.y</code>, <code><i>name</i>.width</code> and * <code><i>name</i>.height</code> properties. * * @param win The window to load geometry from * @param name The name of the window */ public static void loadGeometry(Window win, String name) { loadGeometry(win, win.getParent(), name); } //}}}
/** * Saves a window's geometry to the properties. * The geometry is saved to the <code><i>name</i>.x</code>, * <code><i>name</i>.y</code>, <code><i>name</i>.width</code> and * <code><i>name</i>.height</code> properties.<br /> * For Frame's and descendents use {@link #addSizeSaver(Frame,String)} to save the sizes * correct even if the Frame is in maximized or iconified state. * @param win The window to load geometry from * @param name The name of the window * @see #addSizeSaver(Frame,String) */ public static void saveGeometry(Window win, String name) { saveGeometry (win, win.getParent(), name); } //}}}
/** * Gets the visible parent window. * * @param component * the component to start from * @return the visible parent window or null. */ public static Window getVisibleWindow(Component component) { if (component instanceof JWindow) { return (JWindow) component; } Window w = SwingUtilities.getWindowAncestor(component); if (w != null && !w.isVisible() && w.getParent() != null) { return getVisibleWindow(w.getParent()); } return w; }
/** * Center the component to it's parent window. * * @param childToCenter the parent window */ public static void centerWindow(Window childToCenter) { childToCenter.setLocationRelativeTo(childToCenter.getParent()); // Container parentWindow = childToCenter.getParent(); // // int width = (parentWindow.getWidth() - childToCenter.getWidth()) >> 1; // int height = (parentWindow.getHeight() - childToCenter.getHeight()) >> 1; // // // according to javadoc of setLocation, it's relevant to parent window. but it's not the case. // Point location = parentWindow.getLocation(); // width += location.x; // height += location.y; // childToCenter.setLocation(width, height); }
/** * Gets the visible parent window. * * @param component * the component to start from * @return the visible parent window or null. */ public static Window getVisibleWindow(Component component) { if (component instanceof JWindow) { return (JWindow) component; } Window w = SwingUtilities.getWindowAncestor(component); if (w != null && !w.isVisible() && w.getParent() != null) { return getVisibleWindow(w.getParent()); } return w; }
private void filterIfParentIsFiltered(@Nonnull Window w) { if (!filter.isIgnored(w.getParent())) { return; } filter.ignore(w); } }
/** Return the {@link Frame} corresponding to the given object. */ public static Frame getFrame(Object o) { Window w = getWindow(o); while (!(w instanceof Frame) && w != null) { w = (Window)w.getParent(); } return w instanceof Frame ? (Frame)w : JOptionPane.getRootFrame(); }
/** * Returns getParentComposite().getShell(). * @return the shell */ private Window getShell() { if ( getParentComposite() != null ) { return (Window)getParentComposite().getParent(); } else { return null; } }
@Override public void eventDispatched(AWTEvent event) { if (event.getID() == WindowEvent.WINDOW_OPENED) { final Window window = (Window) event.getSource(); if (window.getParent() == frame) { parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { if (parent.isDisposed()) return; Shell shell = parent.getShell(); loadLibrary(); int /*long*/ awtHandle = getAWTHandle(window); if (awtHandle == 0) return; int /*long*/ xWindow; if (OS.GTK3) { xWindow = OS.gdk_x11_window_get_xid (OS.gtk_widget_get_window (shell.handle)); } else { xWindow = OS.gdk_x11_drawable_get_xid(OS.gtk_widget_get_window(OS.gtk_widget_get_toplevel(shell.handle))); } OS.XSetTransientForHint(OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default()), awtHandle, xWindow); } }); } } } };
@Override public void eventDispatched(AWTEvent event) { if (event.getID() == WindowEvent.WINDOW_OPENED) { final Window window = (Window) event.getSource(); if (window.getParent() == frame) { parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { if (parent.isDisposed()) return; Shell shell = parent.getShell(); loadLibrary(); int /*long*/ awtHandle = getAWTHandle(window); if (awtHandle == 0) return; int /*long*/ xWindow; if (OS.GTK3) { xWindow = OS.gdk_x11_window_get_xid (OS.gtk_widget_get_window (shell.handle)); } else { xWindow = OS.gdk_x11_drawable_get_xid(OS.gtk_widget_get_window(OS.gtk_widget_get_toplevel(shell.handle))); } OS.XSetTransientForHint(OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default()), awtHandle, xWindow); } }); } } } };
@Override public void eventDispatched(AWTEvent event) { if (event.getID() == WindowEvent.WINDOW_OPENED) { final Window window = (Window) event.getSource(); if (window.getParent() == frame) { parent.getDisplay().asyncExec(new Runnable() { @Override public void run() { if (parent.isDisposed()) return; Shell shell = parent.getShell(); loadLibrary(); long /*int*/ awtHandle = getAWTHandle(window); if (awtHandle == 0) return; long /*int*/ xWindow; if (OS.GTK3) { xWindow = OS.gdk_x11_window_get_xid (OS.gtk_widget_get_window (shell.handle)); } else { xWindow = OS.gdk_x11_drawable_get_xid(OS.gtk_widget_get_window(OS.gtk_widget_get_toplevel(shell.handle))); } OS.XSetTransientForHint(OS.gdk_x11_display_get_xdisplay(OS.gdk_display_get_default()), awtHandle, xWindow); } }); } } } };
final Component parent = ancestor.getParent (); if ( parent != null && parent instanceof Window && parent.getBackground ().getAlpha () == 0 )
public static void showOnScreen(Window frame) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gd = ge.getScreenDevices(); final GraphicsDevice frameDevice = frame.getParent().getGraphicsConfiguration().getDevice(); for (GraphicsDevice graphicsDevice : gd) { if (frameDevice.equals(graphicsDevice) || frameDevice.getIDstring().equals(graphicsDevice.getIDstring())) { final Rectangle monitorBounds = graphicsDevice.getDefaultConfiguration().getBounds(); final int x = monitorBounds.x + (monitorBounds.width - frame.getWidth()) /2; final int y = monitorBounds.y + (monitorBounds.height - frame.getHeight()) / 2; frame.setLocation(x, y); } } }
/** * Center a window on screen. * * @param w * the window to center on screen. */ public static void centerInParent(Window w) { Container parent = w.getParent(); if (parent != null) { Dimension parentSize = parent.getSize(); w.setLocation(parent.getX() + (parentSize.width - w.getWidth()) / 2, parent.getY() + (parentSize.height - w.getHeight()) / 2); } }
/** * Center a window on screen. * * @param w * the window to center on screen. */ public static void centerInParent(Window w) { Container parent = w.getParent(); if (parent != null) { Dimension parentSize = parent.getSize(); w.setLocation(parent.getX() + (parentSize.width - w.getWidth()) / 2, parent.getY() + (parentSize.height - w.getHeight()) / 2); } }
else if (isFiltered(w.getParent())) { Log.debug("Parent is filtered, filter " + w.getName()); setFiltered(w, true);
@Wire private Window menu; @Wire private Listbox box; private Listhead lHead; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // get the Listboxhead in which we like to change the the col order lHead = (Listhead) menu.getParent().query("#lbox > #lHead"); // set the model for Listbox box in the pop up box.setModel(new ListModelList<>(lHead.getChildren())); } @Listen("onDrop = listitem") public void onDropInMenu(DropEvent ev) { // get the draged and dropped again Listitem dragged = (Listitem) ev.getDragged(); Listitem droppedOn = (Listitem) ev.getTarget(); // then get their indexes. int from = box.getItems().indexOf(dragged); int to = box.getItems().indexOf(droppedOn); // swap the positions lHead.insertBefore(lHead.getChildren().get(from), lHead.getChildren().get(to)); // swap related Listcell in all Listitem instances for (Listitem item : lHead.getListbox().getItems()) { item.insertBefore(item.getChildren().get(from), item.getChildren().get(to)); } // swap the items in pop up Lisbox as well box.insertBefore(dragged, droppedOn); }