com.objogate.wl.swing.driver.MetalFileChooserUIDriver 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.JButton;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JTextField;
import org.hamcrest.Description;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import com.objogate.wl.gesture.Gestures;
import com.objogate.wl.swing.ComponentManipulation;
import com.objogate.wl.swing.matcher.ComponentMatchers;
import com.objogate.wl.swing.matcher.JLabelTextMatcher;
import com.objogate.wl.swing.probe.NthComponentFinder;
import com.objogate.wl.swing.probe.RecursiveComponentFinder;
class MetalFileChooserUIDriver implements FileChooserUIDriver {
protected JFileChooserDriver parentOrOwner;
public MetalFileChooserUIDriver(JFileChooserDriver jFileChooserDriver) {
parentOrOwner = jFileChooserDriver;
}
public void selectFile(String fileName) {
JListDriver jListDriver = new JListDriver(parentOrOwner, JList.class);
jListDriver.selectItem(JLabelTextMatcher.withLabelText(Matchers.equalTo(fileName)));
}
public void intoDir(String directoryName) {
selectFile(directoryName);
parentOrOwner.performGesture(Gestures.doubleClickMouse());
}
@SuppressWarnings("unchecked")
public void cancel() {
new AbstractButtonDriver(parentOrOwner, JButton.class, ComponentMatchers.withButtonText("Cancel")).click();
}
@SuppressWarnings("unchecked")
public void approve() {
final String[] approveButtonText = new String[1];
parentOrOwner.perform("finding the approve button text", new ComponentManipulation() {
public void manipulate(JFileChooser component) {
approveButtonText[0] = component.getApproveButtonText();
}
});
String text = approveButtonText[0] == null ? "Open" : approveButtonText[0];
new AbstractButtonDriver(parentOrOwner, JButton.class, ComponentMatchers.withButtonText(text), new TypeSafeMatcher() {
@Override
public boolean matchesSafely(JButton jButton) {
return jButton.isVisible();
}
public void describeTo(Description description) {
description.appendText("visible button");
}
}).click();
}
@SuppressWarnings("unchecked")
public JTextFieldDriver textBox() {
// only one textfield in this laf...
return new JTextFieldDriver(parentOrOwner, JTextField.class, Matchers.anything());
}
public void home() {
movementIconNumber(1).click();
}
public void documents() {
throw new UnsupportedOperationException("There is no 'My Documents' button in the Metal L&F");
}
public void desktop() {
throw new UnsupportedOperationException("There is no 'Desktop' button in the Metal L&F");
}
public void createNewFolder(String folderName) {
movementIconNumber(2).click();
JTextFieldDriver folderEntry = new JTextFieldDriver(parentOrOwner, parentOrOwner.the(JTextField.class, ComponentMatchers.withFocus()));
folderEntry.moveMouseToCenter();
folderEntry.typeText(folderName);
folderEntry.typeText("\n");
}
public void upOneFolder() {
movementIconNumber(0).click();
}
private AbstractButtonDriver movementIconNumber(int toChoose) {
NthComponentFinder finder = new NthComponentFinder(new RecursiveComponentFinder(JButton.class, Matchers.anything(), parentOrOwner.component()), toChoose);
return new AbstractButtonDriver(parentOrOwner, finder);
}
}