All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.objogate.wl.swing.probe.TopLevelWindowFinder Maven / Gradle / Ivy

The newest version!
package com.objogate.wl.swing.probe;

import java.awt.Frame;
import java.awt.Window;
import java.util.*;
import org.hamcrest.Description;
import com.objogate.wl.swing.ComponentFinder;

public class TopLevelWindowFinder implements ComponentFinder {
    private List found = Collections.emptyList();

    public boolean isSatisfied() {
        return true;
    }

    public List components() {
        return found;
    }

    public void probe() {
        Set topLevelWindows = new HashSet();

        for (Frame frame : Frame.getFrames()) {
            topLevelWindows.add(ownershipRoot(frame));
        }

        found = new ArrayList(topLevelWindows);
    }

    private static Window ownershipRoot(Window w) {
        return w.getOwner() == null
                ? w
                : ownershipRoot(w.getOwner());
    }

    public void describeTo(Description description) {
        description.appendText("all top level windows");
    }

    public void describeFailureTo(Description description) {
        describeTo(description);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy