📄 panel.java
字号:
return new NumberSpinner((JSpinner) component.getAwtComponent());
}
public NumberSpinner getNumberSpinner(String componentName) {
ComponentMatcher matcher = ComponentMatchers.intersection(new ComponentMatcher[]{
Spinner.getSpinnerMatcherByModel(SpinnerNumberModel.class), getMatcherFromName(componentName)
});
Spinner component = (Spinner) getComponent(finder, matcher);
return new NumberSpinner((JSpinner) component.getAwtComponent());
}
public NumberSpinner getNumberSpinner(ComponentMatcher matcher) {
ComponentMatcher intersection = ComponentMatchers.intersection(new ComponentMatcher[]{
Spinner.getSpinnerMatcherByModel(SpinnerNumberModel.class), matcher
});
Spinner component = (Spinner) getComponent(finder, intersection);
return new NumberSpinner((JSpinner) component.getAwtComponent());
}
public Slider getSlider() throws ItemNotFoundException, ComponentAmbiguityException {
return (Slider)getComponent(finder, Slider.class, null);
}
public Slider getSlider(String name) throws ItemNotFoundException, ComponentAmbiguityException {
return (Slider)getComponent(finder, Slider.class, name);
}
public Slider getSlider(ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return (Slider)getComponent(finder, getMatcherByClass(Slider.class, matcher));
}
public Table getTable(String name) throws ItemNotFoundException, ComponentAmbiguityException {
return (Table) getComponent(finder, Table.class, name);
}
public Table getTable() throws ItemNotFoundException, ComponentAmbiguityException {
return (Table) getComponent(finder, Table.class, null);
}
public Table getTable(ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return (Table) getComponent(finder, getMatcherByClass(Table.class, matcher));
}
public Tree getTree(String name) throws ItemNotFoundException, ComponentAmbiguityException {
return (Tree) getComponent(finder, Tree.class, name);
}
public Tree getTree() throws ItemNotFoundException, ComponentAmbiguityException {
return (Tree) getComponent(finder, Tree.class, null);
}
public Tree getTree(ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return (Tree) getComponent(finder, getMatcherByClass(Tree.class, matcher));
}
public RadioButton getRadioButton(String name) throws ItemNotFoundException, ComponentAmbiguityException {
return (RadioButton) getComponent(finder, RadioButton.class, name);
}
public RadioButton getRadioButton() throws ItemNotFoundException, ComponentAmbiguityException {
return (RadioButton) getComponent(finder, RadioButton.class, null);
}
public RadioButton getRadioButton(ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return (RadioButton) getComponent(finder, getMatcherByClass(RadioButton.class, matcher));
}
public ListBox getListBox(String name) throws ItemNotFoundException, ComponentAmbiguityException {
return (ListBox) getComponent(finder, ListBox.class, name);
}
public ListBox getListBox() throws ItemNotFoundException, ComponentAmbiguityException {
return (ListBox) getComponent(finder, ListBox.class, null);
}
public ListBox getListBox(ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return (ListBox) getComponent(finder, getMatcherByClass(ListBox.class, matcher));
}
public PasswordField getPasswordField() throws ItemNotFoundException, ComponentAmbiguityException {
return (PasswordField) getComponent(finder, PasswordField.class, null);
}
public PasswordField getPasswordField(ComponentMatcher matcher) {
return (PasswordField) getComponent(finder, getMatcherByClass(PasswordField.class, matcher));
}
public PasswordField getPasswordField(String componentName) {
return (PasswordField) getComponent(finder, PasswordField.class, componentName);
}
public UIComponent[] getUIComponents(Class uiComponentClass) {
return getComponents(finder, uiComponentClass, null);
}
public UIComponent[] getUIComponents(Class uiComponentClass, String name) {
return getComponents(finder, uiComponentClass, name);
}
public UIComponent[] getUIComponents(ComponentMatcher matcher) {
return getComponents(finder, matcher);
}
public UIComponent findUIComponent(Class uiComponentClass) throws ComponentAmbiguityException {
return findComponent(finder, uiComponentClass, null);
}
public UIComponent findUIComponent(Class uiComponentClass, String name) throws ComponentAmbiguityException {
return findComponent(finder, uiComponentClass, name);
}
public UIComponent findUIComponent(ComponentMatcher matcher) throws ComponentAmbiguityException {
Component swingComponent = finder.findComponent(matcher);
if (swingComponent == null) {
return null;
}
return UIComponentFactory.createUIComponent(swingComponent);
}
public Component[] getSwingComponents(Class swingComponentClass) {
return finder.getComponents(null, new Class[]{swingComponentClass});
}
public Component[] getSwingComponents(Class swingComponentClass, String name) {
return finder.getComponents(name, new Class[]{swingComponentClass});
}
public Component[] getSwingComponents(ComponentMatcher matcher) {
return finder.getComponents(matcher);
}
public Component findSwingComponent(Class swingComponentClass) throws ComponentAmbiguityException {
return finder.findComponent(null, new Class[]{swingComponentClass}, swingComponentClass.getName());
}
public Component findSwingComponent(Class swingComponentClass, String componentName) throws ComponentAmbiguityException {
return finder.findComponent(componentName, new Class[]{swingComponentClass}, swingComponentClass.getName());
}
public Component findSwingComponent(ComponentMatcher matcher) throws ComponentAmbiguityException {
return finder.findComponent(matcher);
}
private ComponentMatcher getMatcherByClass(final Class uiComponentClass, final ComponentMatcher matcher) {
final Class[] swingClasses = UIComponentAnalyzer.getSwingClasses(uiComponentClass);
ComponentMatcher[] classMatchers = new ComponentMatcher[swingClasses.length];
for (int i = 0; i < classMatchers.length; i++) {
classMatchers[i] = ComponentMatchers.fromClass(swingClasses[i]);
}
return ComponentMatchers.intersection(new ComponentMatcher[]{matcher, ComponentMatchers.union(classMatchers)});
}
private static UIComponent getComponent(ComponentFinder finder, ComponentMatcher matcher) throws ItemNotFoundException, ComponentAmbiguityException {
return UIComponentFactory.createUIComponent(finder.getComponent(matcher));
}
private static UIComponent getComponent(ComponentFinder finder, Class uiComponentClass, String componentName)
throws ComponentAmbiguityException, ItemNotFoundException {
Class[] swingClasses = UIComponentAnalyzer.getSwingClasses(uiComponentClass);
return getComponent(finder, uiComponentClass, swingClasses, componentName);
}
private static UIComponent getComponent(ComponentFinder finder, Class uiComponentClass, Class[] swingClasses, String componentName)
throws ComponentAmbiguityException, ItemNotFoundException {
String typeName = UIComponentAnalyzer.getTypeName(uiComponentClass);
Component swingComponent = finder.getComponent(componentName, swingClasses, typeName);
return UIComponentFactory.createUIComponent(swingComponent);
}
private static UIComponent findComponent(ComponentFinder finder, Class uiComponentClass, String name)
throws ComponentAmbiguityException {
Class[] swingClasses = UIComponentAnalyzer.getSwingClasses(uiComponentClass);
String typeName = UIComponentAnalyzer.getTypeName(uiComponentClass);
Component swingComponent = finder.findComponent(name, swingClasses, typeName);
return (swingComponent == null) ? null : UIComponentFactory.createUIComponent(swingComponent);
}
private static UIComponent[] getComponents(ComponentFinder finder, ComponentMatcher matcher) {
Component[] components = finder.getComponents(matcher);
return UIComponentFactory.createUIComponents(components);
}
private static UIComponent[] getComponents(ComponentFinder finder, Class uiComponentClass, String name) {
Class[] swingClasses = UIComponentAnalyzer.getSwingClasses(uiComponentClass);
Component[] swingComponents = finder.getComponents(name, swingClasses);
return UIComponentFactory.createUIComponents(swingComponents);
}
public Assertion containsUIComponent(final Class uicomponentClass) {
return new Assertion() {
public void check() throws Exception {
UIComponent[] uiComponents = getUIComponents(uicomponentClass);
Assert.assertTrue(uiComponents.length > 0);
}
};
}
public Assertion containsSwingComponent(final Class swingComponentClass) {
return new Assertion() {
public void check() throws Exception {
Component[] swingComponents = getSwingComponents(swingComponentClass);
Assert.assertTrue(swingComponents.length > 0);
}
};
}
public Assertion containsUIComponent(final Class uiComponentClass, final String name) {
return new Assertion() {
public void check() throws Exception {
UIComponent[] uiComponents = getUIComponents(uiComponentClass, name);
Assert.assertTrue(uiComponents.length > 0);
}
};
}
public Assertion containsSwingComponent(final Class swingComponentClass, final String name) {
return new Assertion() {
public void check() throws Exception {
Component[] swingComponents = getSwingComponents(swingComponentClass, name);
Assert.assertTrue(swingComponents.length > 0);
}
};
}
public Assertion containsComponent(final ComponentMatcher matcher) {
return new Assertion() {
public void check() throws Exception {
Assert.assertTrue(getSwingComponents(matcher).length > 0);
}
};
}
/**
* Checks that the panel contains a given non-editable text.
* This method is mainly suited for checking displayed messages in popped-up dialogs.
* NB: Only JLabel components are taken into account.
*/
public Assertion containsLabel(final String text) {
return new Assertion() {
public void check() throws Exception {
Component[] result = getSwingComponents(ComponentMatchers.intersection(
new ComponentMatcher[]{
ComponentMatchers.fromClass(JLabel.class),
ComponentMatchers.displayedNameSubstring(text)
}));
if (result.length == 0) {
throw new AssertionFailedError("No label found with text '" + text + "'");
}
}
};
}
private static ComponentMatcher getMatcherFromName(String componentName) {
return ComponentMatchers.union(new ComponentMatcher[]{
ComponentMatchers.innerNameIdentity(componentName),
ComponentMatchers.innerNameSubstring(componentName),
ComponentMatchers.innerNameRegexp(componentName)
});
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -