Example usage for java.awt Window getOwnedWindows

List of usage examples for java.awt Window getOwnedWindows

Introduction

In this page you can find the example usage for java.awt Window getOwnedWindows.

Prototype

public Window[] getOwnedWindows() 

Source Link

Document

Return an array containing all the windows this window currently owns.

Usage

From source file:Main.java

/**
 * Updates the componentTreeUI of the given window and all its
 * owned windows, recursively./*from   ww w.ja va 2  s .c om*/
 * 
 * 
 * @param window the window to update
 */
public static void updateAllComponentTreeUIs(Window window) {
    SwingUtilities.updateComponentTreeUI(window);
    for (Window owned : window.getOwnedWindows()) {
        updateAllComponentTreeUIs(owned);
    }
}

From source file:Main.java

public static Window getOwnerForChildWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (w != null) {
        return w;
    }// ww w. j a  va 2s.  c om
    w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
    if (w != null) {
        return w;
    }
    /*
     * Priority level1
     * modal dialog: +200
     * non-modal dialog: +100
     * frame: +0
     *
     * Priority level2
     * no owned windows: +10
     */
    TreeMap<Integer, Window> prioMap = new TreeMap<Integer, Window>();
    for (Window cand : Window.getWindows()) {
        if (cand == null) {
            continue;
        }
        if (!cand.isVisible()) {
            continue;
        }
        if (!cand.isShowing()) {
            continue;
        }
        int prio = 0;
        Window[] children = cand.getOwnedWindows();
        if (children == null || children.length == 0) {
            prio += 10;
        }
        if (cand instanceof Dialog) {
            Dialog dlg = (Dialog) cand;
            if (dlg.isModal()) {
                prio += 200;
            } else {
                prio += 100;
            }
            prioMap.put(prio, cand);
        } else if (cand instanceof Frame) {
            if (!prioMap.containsKey(prio)) {
                prioMap.put(prio, cand);
            }
        }
    }
    if (prioMap.size() > 0) {
        return prioMap.get(prioMap.lastKey());
    }
    //last line of defense
    if (prioMap.size() == 0) {
        for (Window cand : Window.getWindows()) {
            if (cand == null) {
                continue;
            }
            if (cand.isVisible()) {
                return cand;
            }
        }
    }
    return null;
}

From source file:util.ui.UiUtilities.java

/**
 * Gets the last visible modal child dialog of the specified window.
 * <p>//  www.j av  a 2s. co m
 * If there is no visible modal child the window itself will be returned.
 *
 * @param parent
 *          The window to get the child from.
 * @return the last visible modal child dialog of the specified window.
 */
public static Window getLastModalChildOf(Window parent) {
    Window[] children = parent.getOwnedWindows();
    for (Window child : children) {
        if (child instanceof Dialog) {
            Dialog dlg = (Dialog) child;
            if (dlg.isVisible() && dlg.isModal()) {
                return getLastModalChildOf(dlg);
            }
        }
    }

    // this is the last window
    return parent;
}

From source file:util.ui.UiUtilities.java

/**
 * Gets if a dialog child of the given window is modal.
 *
 * @param parent/*from   ww w  .  jav a 2  s.c  om*/
 *          The window to check the children of.
 * @return <code>True</code> if a child is modal, <code>false</code>
 *         otherwise.
 *
 * @since 2.7
 */
public static boolean containsModalDialogChild(Window parent) {
    Window[] children = parent.getOwnedWindows();

    for (Window child : children) {
        if (containsModalDialogChild(child)) {
            return true;
        }
    }

    return (parent instanceof JDialog && parent.isVisible() && ((JDialog) parent).isModal());
}