Example usage for java.awt Window isShowing

List of usage examples for java.awt Window isShowing

Introduction

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

Prototype

public boolean isShowing() 

Source Link

Document

Checks if this Window is showing on screen.

Usage

From source file:Main.java

/**
 * Returns active application window.//from  ww  w .  j  a  va2 s  .  com
 *
 * @return active application window
 */
public static Window getActiveWindow() {
    final Window[] windows = Window.getWindows();
    Window window = null;
    for (final Window w : windows) {
        if (w.isShowing() && w.isActive() && w.isFocused()) {
            window = w;
            break;
        }
    }
    return window;
}

From source file:Main.java

public static JDialog getVisibleDialog(Window owner, String title) {
    for (Window w : Window.getWindows())
        if (w instanceof JDialog && w.isShowing() && ((JDialog) w).getOwner() == owner
                && ((JDialog) w).getTitle().equals(title))
            return (JDialog) w;
    return null;//from w ww.j a  va2  s.  com
}

From source file:Main.java

public static JFrame getOnlyVisibleFrame() {
    JFrame f = null;//from  w ww .j a v  a  2 s.com
    for (Window w : Window.getWindows())
        if (w instanceof JFrame && w.isShowing()) {
            if (f != null)
                throw new IllegalStateException("num frames > 1");
            f = (JFrame) w;
        }
    return f;
}

From source file:Main.java

public static JDialog getOnlyVisibleDialog(Window owner) {
    JDialog d = null;// w w  w. j a  v a  2 s.  c  o  m
    for (Window w : Window.getWindows()) {
        //         System.out.println("found " + w + " " + w.getOwner());
        if (w instanceof JDialog && w.isShowing() && ((JDialog) w).getOwner() == owner) {
            if (d != null)
                throw new IllegalStateException("num dialogs > 1");
            d = (JDialog) w;
        }
    }
    return d;
}

From source file:Main.java

public static Window getOwnerForChildWindow() {
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    if (w != null) {
        return w;
    }/*from ww  w .  java 2 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:de.bwravencl.controllerbuddy.gui.Main.java

private static boolean isModalDialogShowing() {
    final var windows = Window.getWindows();
    if (windows != null)
        for (final Window w : windows)
            if (w.isShowing() && w instanceof Dialog && ((Dialog) w).isModal())
                return true;

    return false;
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Centers view on parent window.//from   w w  w .  java2  s.  c om
 */
protected void centerView() {
    Window parentWindow = parent.getWindow();

    Dimension parentSize = parentWindow.getSize();
    Dimension windowSize = getView().getSize();
    Point parentLocation = new Point(0, 0);
    if (parentWindow.isShowing()) {
        parentLocation = parentWindow.getLocationOnScreen();
    }

    int x = parentLocation.x + parentSize.width / 2 - windowSize.width / 2;
    int y = parentLocation.y + parentSize.height / 2 - windowSize.height / 2;

    getView().setLocation(x, y);
}

From source file:org.eclipse.jubula.rc.swing.components.AUTSwingHierarchy.java

/**
 * Searchs for the component in the AUT with the given
 * <code>componentIdentifier</code>.
 * @param componentIdentifier the identifier created in object mapping mode
 * @throws IllegalArgumentException if the given identifer is null or <br>the hierarchy is not valid: empty or containing null elements
 * @throws InvalidDataException if the hierarchy in the componentIdentifier does not consist of strings
 * @throws ComponentNotManagedException if no component could be found for the identifier
 * @return the instance of the component of the AUT 
 *//*from w ww.  j  av  a2  s. c  om*/
public Component findComponent(IComponentIdentifier componentIdentifier)
        throws IllegalArgumentException, ComponentNotManagedException, InvalidDataException {
    Component comp = (Component) findBP.findComponent(componentIdentifier, ComponentHandler.getAutHierarchy());

    if (comp != null && comp.isShowing()) {
        Window window = SwingUtilities.getWindowAncestor(comp);
        if (window != null && window.isShowing() && !window.isActive()) {
            window.toFront();
        }
        return comp;
    }
    throw new ComponentNotManagedException("unmanaged component with identifier: '" //$NON-NLS-1$
            + componentIdentifier.toString() + "'.", //$NON-NLS-1$ 
            MessageIDs.E_COMPONENT_NOT_MANAGED);
}