Search in sources :

Example 1 with LWTopFrame

use of org.vcell.client.logicalwindow.LWTopFrame in project vcell by virtualcell.

the class TopLevelWindowManager method activeManager.

public static TopLevelWindowManager activeManager() {
    LWTopFrame activetf = null;
    Optional<WeakReference<LWTopFrame>> first = LWTopFrame.liveWindows().findFirst();
    if (first.isPresent()) {
        activetf = first.get().get();
    }
    TopLevelWindowManager fallback = null;
    Iterator<WeakReference<TopLevelWindowManager>> iter = allManagers.iterator();
    while (iter.hasNext()) {
        WeakReference<TopLevelWindowManager> wr = iter.next();
        TopLevelWindowManager tlwm = wr.get();
        if (tlwm == null) {
            iter.remove();
            continue;
        }
        if (activetf == null) {
            if (lg.isWarnEnabled()) {
                lg.warn("no active LWTopFrame in TopLevelWindowManager?");
            }
            // guess
            return tlwm;
        }
        if (fallback == null) {
            // return this if can't find the right window
            fallback = tlwm;
        }
        Component cmpt = tlwm.getComponent();
        if (cmpt != null && SwingUtilities.isDescendingFrom(cmpt, activetf)) {
            return tlwm;
        }
    }
    return fallback;
}
Also used : LWTopFrame(org.vcell.client.logicalwindow.LWTopFrame) WeakReference(java.lang.ref.WeakReference) Component(java.awt.Component)

Aggregations

Component (java.awt.Component)1 WeakReference (java.lang.ref.WeakReference)1 LWTopFrame (org.vcell.client.logicalwindow.LWTopFrame)1