Example usage for java.awt Window isVisible

List of usage examples for java.awt Window isVisible

Introduction

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

Prototype

@Transient
public boolean isVisible() 

Source Link

Document

Determines whether this component should be visible when its parent is visible.

Usage

From source file:Main.java

public static boolean allWindowsClosed() {
    for (Window window : Window.getWindows()) {
        if (window.isVisible()) {
            return false;
        }/*from w  ww  . j av a  2 s.c o m*/
    }
    return true;
}

From source file:Main.java

/**
 * Gets the window actual size.//from  ww  w . j  ava2s  .c om
 *
 * @param window
 *            the window
 * @return the window actual size
 */
public static Dimension getWindowActualSize(final Window window) {
    if (window.isVisible()) {
        return window.getSize();
    }
    if (window instanceof Frame) {
        final Frame frame = (Frame) window;
        if (frame.getExtendedState() == Frame.MAXIMIZED_BOTH) {
            return Toolkit.getDefaultToolkit().getScreenSize();
        }
    }
    return window.getSize();
}

From source file:Main.java

/**
 * Checks if is visible on screen.//from  w w w . j  a  v a  2  s . com
 *
 * @param component
 *            the component
 * @return true, if is visible on screen
 */
public static boolean isVisibleOnScreen(final JComponent component) {
    final Window window = getWindow(component);
    if (window != null) {
        return window.isVisible();
    }
    return false;
}

From source file:Main.java

/**
 * Makes a window visible - if invisible - and brings it to front.
 *
 * @param window window/*from   w w  w. ja va2  s. c  o  m*/
 */
public static void show(Window window) {
    if (window == null) {
        throw new NullPointerException("window == null");
    }

    if (!window.isVisible()) {
        window.setVisible(true);
    }

    window.toFront();
}

From source file:Main.java

/**
 * Closes and disposes a given {@link Window}.
 * //  w w w  . j a v a  2 s  . c  om
 * @param aWindow
 *          the window to close, if <code>null</code>, this method doesn't do
 *          anything.
 */
public static void dispose(final Window aWindow) {
    if (aWindow == null) {
        return;
    }
    if (aWindow.isVisible()) {
        aWindow.setVisible(false);
    }
    aWindow.dispose();
}

From source file:Main.java

public static Window getOwnerForChildWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (w != null) {
        return w;
    }//from   w ww. ja va2  s . com
    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:edu.ku.brc.ui.UIRegistry.java

/**
 * Returns the most recent frame to be used, but note that there is no magic here. You
 * must set the the most recent frame in order for it to be used by someone else. The one
 * thing it does do for you, is that if you forgot to set it and someone else uses it it does
 * check to make sure it is not null AND visible. If either of these are true then it returns the TOPFRAME.
 * /*from   ww  w  .j a v  a2s  .  c  o  m*/
 * @return Returns the most recent frame to be used, but note that there is no magic here. You
 * must set the the most recent frame in order for it to be used by someone else. The one
 * thing it does do for you, is that if you forgot to set it and someone else uses it it does
 * check to make sure it is not null AND visible. If either of these are true then it returns the TOPFRAME.
 */
public static Window getMostRecentWindow() {
    Window recent = instance.windowStack.size() > 0 ? instance.windowStack.peek() : null;
    return recent == null || !recent.isVisible() ? instance.topWindow : recent;
}

From source file:corelyzer.ui.CorelyzerApp.java

public void relocateToolMenu(final int id) {
    Point p;/*w  w  w .  jav  a  2 s  . c o m*/
    Window jf;
    jf = windowVec.elementAt(id);
    if ((jf != null) && jf.isVisible()) {
        p = jf.getLocationOnScreen();

        // Dimension screenDim =
        // Toolkit.getDefaultToolkit().getScreenSize();
        int canvasWidth = preferences().screenWidth;
        Dimension toolFrameDim = toolFrame.getSize();
        p.x += canvasWidth / 2 - toolFrameDim.width / 2;

        toolFrame.setLocation(p.x, p.y);
    }
}

From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java

/**
 * Guesses the active window. Returns null if no active window is found.
 * @return the active window/*from w w w  .j  av a2  s  .  c  o m*/
 */
private Window getActiveWindow() {
    return (Window) m_queuer.invokeAndWait("getActiveWindow", //$NON-NLS-1$
            new IRunnable() {
                public Object run() throws StepExecutionException {
                    if (Frame.getFrames().length == 0) {
                        return null;
                    }
                    for (int i = 0; i < Frame.getFrames().length; ++i) {
                        Window window = Frame.getFrames()[i];
                        while (window.getOwner() != null) {
                            window = window.getOwner();
                        }
                        if (window.isVisible()) {
                            return window;
                        }
                    }
                    return null;
                }
            });
}

From source file:util.ui.UiUtilities.java

/**
 * Gets if a dialog child of the given window is modal.
 *
 * @param parent//from w ww.  j  a  v  a2 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());
}