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

com.objogate.wl.swing.driver.AbstractButtonDriver Maven / Gradle / Ivy

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

import javax.swing.AbstractButton;
import java.awt.Component;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.hamcrest.TypeSafeMatcher;
import com.objogate.wl.Prober;
import com.objogate.wl.Query;
import com.objogate.wl.internal.PropertyQuery;
import com.objogate.wl.swing.ComponentSelector;
import com.objogate.wl.swing.gesture.GesturePerformer;
import com.objogate.wl.swing.internal.query.MnemonicQuery;
import com.objogate.wl.swing.internal.query.TextQuery;


public class AbstractButtonDriver extends JComponentDriver
        implements TextQuery, MnemonicQuery {

    public AbstractButtonDriver(GesturePerformer gesturePerformer, ComponentSelector componentSelector, Prober prober) {
        super(gesturePerformer, componentSelector, prober);
    }

    public AbstractButtonDriver(ComponentDriver parentOrOwner, ComponentSelector componentSelector) {
        super(parentOrOwner, componentSelector);
    }

    public AbstractButtonDriver(ComponentDriver parentOrOwner, Class componentType, Matcher... matchers) {
        super(parentOrOwner, componentType, matchers);
    }

    public void click() {
        leftClickOnComponent();
    }

    public void hasText(Matcher matcher) {
        has(text(), matcher);
    }

    private Query text() {
        return new Query() {
            public String query(T button) {
                return button.getText();
            }

            public void describeTo(Description description) {
                description.appendText("text");
            }
        };
    }

    public void mnemonic(Matcher matcher) {
        has(mnemonic(), matcher);
    }

    private static  Query mnemonic() {
        return new PropertyQuery("mnemonic") {
            public Character query(B button) {
                return (char) button.getMnemonic();
            }
        };
    }

    public void isChecked() {
        is(selected());
    }

    public void isNotChecked() {
        is(Matchers.not(selected()));
    }

    private TypeSafeMatcher selected() {
        return new TypeSafeMatcher() {
            @Override
            public boolean matchesSafely(AbstractButton item) {
                return item.isSelected();
            }

            public void describeTo(Description description) {
                description.appendText("is selected");
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy