Example usage for java.awt Dialog isModal

List of usage examples for java.awt Dialog isModal

Introduction

In this page you can find the example usage for java.awt Dialog isModal.

Prototype

public boolean isModal() 

Source Link

Document

Indicates whether the dialog is modal.

Usage

From source file:Main.java

public static Window getOwnerForChildWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (w != null) {
        return w;
    }//from  w  w  w .  j a va  2s .co  m
    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  a  v  a2  s .  c  o 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;
}