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

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

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

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JList;
import java.awt.Component;
import org.hamcrest.Matcher;
import com.objogate.exception.Defect;
import com.objogate.wl.Prober;
import com.objogate.wl.swing.ComponentSelector;
import com.objogate.wl.swing.gesture.GesturePerformer;

/**
 * Simple wrapper for list operations on either JComboBox or JList.
 * 

* Some UI components (notably JOptionPane) dynamically choose whether to use a JList or * JComboBox at runtime. *

* This is a wrapper so simple operations on these components can be generalised. */ public class GeneralListDriver extends JComponentDriver implements ListDriver { public GeneralListDriver(GesturePerformer gesturePerformer, ComponentSelector componentSelector, Prober prober) { super(gesturePerformer, componentSelector, prober); } public GeneralListDriver(ComponentDriver parentOrOwner, ComponentSelector componentSelector) { super(parentOrOwner, componentSelector); } public GeneralListDriver(ComponentDriver parentOrOwner, Class componentType, Matcher... matchers) { super(parentOrOwner, componentType, matchers); } public void selectItem(int index) { getDriver().selectItem(index); } public void selectItem(Matcher item) { getDriver().selectItem(item); } public void hasSelectedIndex(int index) { getDriver().hasSelectedIndex(index); } public ListDriver getDriver() { isShowingOnScreen(); JComponent component = component().component(); if (component instanceof JList) { return new JListDriver(this, JList.class); } else if (component instanceof JComboBox) { return new JComboBoxDriver(this, JComboBox.class); } else { throw new Defect("Only support JList & JComboBox, not " + component.getClass().getName()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy