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

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

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

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import java.awt.Component;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import com.objogate.wl.Query;

public class JMenuBarDriver extends JComponentDriver {

    public JMenuBarDriver(ComponentDriver parentOrOwner, Matcher... matchers) {
        super(parentOrOwner, JMenuBar.class, matchers);
    }

    @SuppressWarnings("unchecked")
    public JMenuDriver menu(final Matcher matching) {
        has(matching);

        return new JMenuDriver(this, matching);
    }

    public void has(final Matcher matching) {
        has(new Query() {
            public JMenu query(JMenuBar component) {
                for (int i = 0; i < component.getMenuCount(); i++) {
                    JMenu jMenu = component.getMenu(i);
                    if (matching.matches(jMenu)) {
                        return jMenu;
                    }
                }
                return new JMenu();
            }

            public void describeTo(Description description) {
                description.appendText("jmenu");
            }
        }, matching);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy