![JAR search and dependency download from the Maven repository](/logo.png)
com.objogate.wl.swing.driver.JFrameDriver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of windowlicker-swing Show documentation
Show all versions of windowlicker-swing Show documentation
This is the Windowlicker Swing library.
The newest version!
package com.objogate.wl.swing.driver;
import javax.swing.JFrame;
import java.awt.Component;
import static org.hamcrest.CoreMatchers.allOf;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import static org.hamcrest.Matchers.equalTo;
import com.objogate.wl.Prober;
import com.objogate.wl.Query;
import com.objogate.wl.swing.ComponentManipulation;
import com.objogate.wl.swing.ComponentSelector;
import com.objogate.wl.swing.gesture.GesturePerformer;
import com.objogate.wl.swing.probe.RecursiveComponentFinder;
import com.objogate.wl.swing.probe.SingleComponentFinder;
import com.objogate.wl.swing.probe.TopLevelWindowFinder;
public class JFrameDriver extends ComponentDriver {
public JFrameDriver(GesturePerformer gesturePerformer, ComponentSelector componentSelector, Prober prober) {
super(gesturePerformer, componentSelector, prober);
}
public JFrameDriver(ComponentDriver extends Component> parentOrOwner, ComponentSelector componentSelector) {
super(parentOrOwner, componentSelector);
}
public JFrameDriver(ComponentDriver extends Component> parentOrOwner, Class componentType, Matcher super JFrame>... matchers) {
super(parentOrOwner, componentType, matchers);
}
public JFrameDriver(GesturePerformer gesturePerformer, Prober prober, Matcher super JFrame>... withMatchers) {
this(gesturePerformer, topLevelFrame(withMatchers), prober);
}
public JFrameDriver(ComponentDriver extends Component> ownerDriver, Matcher super JFrame>... matchers) {
super(ownerDriver,
new SingleComponentFinder(
new RecursiveComponentFinder(JFrame.class, allOf(matchers),
ownerDriver.component())));
}
/**
* Creates a ComponentSelector that will find a top-level JFrame that conforms
* to the given matchers
*
* @param matchers The matchers to conform to
* @return A ComponentSelector
*/
public static ComponentSelector topLevelFrame(Matcher super JFrame>... matchers) {
return new SingleComponentFinder(
new RecursiveComponentFinder(JFrame.class, allOf(matchers),
new TopLevelWindowFinder()));
}
/**
* Disposes of the frame and also sets the frame's name to null
so that it cannot be found
* by the {@link com.objogate.wl.swing.driver.ComponentDriver#named(String)} named} matcher in a subsequent
* test while it is being garbage collected.
*/
public void dispose() {
perform("disposing", new ComponentManipulation() {
public void manipulate(JFrame component) {
component.dispose();
component.setName(null);
}
});
}
public void hasTitle(String title) {
hasTitle(equalTo(title));
}
public void hasTitle(Matcher matcher) {
has(title(), matcher);
}
private static Query title() {
return new Query() {
public String query(JFrame label) {
return label.getTitle();
}
public void describeTo(Description description) {
description.appendText("frame title");
}
};
}
public JMenuBarDriver menuBar() {
return new JMenuBarDriver(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy