org.fest.swing.core.matcher
Class JButtonMatcher

java.lang.Object
  extended by org.fest.swing.core.AbstractComponentMatcher
      extended by org.fest.swing.core.GenericTypeMatcher<T>
          extended by org.fest.swing.core.matcher.NamedComponentMatcherTemplate<JButton>
              extended by org.fest.swing.core.matcher.JButtonMatcher
All Implemented Interfaces:
ComponentMatcher, ResettableComponentMatcher

public final class JButtonMatcher
extends NamedComponentMatcherTemplate<JButton>

Understands matching a JButton by name, text and visibility on the screen.

Author:
Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.swing.core.matcher.NamedComponentMatcherTemplate
ANY, name
 
Method Summary
 JButtonMatcher andShowing()
          Indicates that the JButton to match should be showing on the screen.
 JButtonMatcher andText(Pattern textPattern)
          Specifies the text to match.
 JButtonMatcher andText(String newText)
          Specifies the text to match.
static JButtonMatcher any()
          Creates a new JButtonMatcher that matches any JButton.
protected  boolean isMatching(JButton button)
          Indicates whether: the name of the given JButton is equal to the name in this matcher, and the text of the given JButton matches the text (or pattern) in this matcher
 String toString()
           
static JButtonMatcher withName(String name)
          Creates a new JButtonMatcher that matches a JButton that: has a matching name (optionally) has matching text (optionally) is showing on the screen
static JButtonMatcher withText(Pattern textPattern)
          Creates a new JButtonMatcher that matches a JButton by its text.
static JButtonMatcher withText(String text)
          Creates a new JButtonMatcher that matches a JButton by its text.
 
Methods inherited from class org.fest.swing.core.matcher.NamedComponentMatcherTemplate
arePropertyValuesMatching, isNameMatching, quoted, quotedName
 
Methods inherited from class org.fest.swing.core.GenericTypeMatcher
matches, supportedType
 
Methods inherited from class org.fest.swing.core.AbstractComponentMatcher
requireShowing, requireShowing, requireShowingMatches, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

withName

public static JButtonMatcher withName(String name)
Creates a new JButtonMatcher that matches a JButton that:
  1. has a matching name
  2. (optionally) has matching text
  3. (optionally) is showing on the screen
  4. The following code listing shows how to match a JButton by name and text:

     JButtonMatcher m = withName("ok").andText("OK");
     

    The following code listing shows how to match a JButton, that should be showing on the screen, by name and text:

     JButtonMatcher m = withName("ok").andText("OK").andShowing();
     

    Parameters:
    name - the name to match.
    Returns:
    the created matcher.

withText

public static JButtonMatcher withText(String text)
Creates a new JButtonMatcher that matches a JButton by its text.

The following code listing shows how to match a JButton by text:

 JButtonMatcher m = withText("OK");
 

The following code listing shows how to match a JButton, that should be showing on the screen, by text:

 JButtonMatcher m = withText("OK").andShowing();
 

Parameters:
text - the text to match. It can be a regular expression.
Returns:
the created matcher.

withText

public static JButtonMatcher withText(Pattern textPattern)
Creates a new JButtonMatcher that matches a JButton by its text.

The following code listing shows how to match a JButton by text, using a regular expression pattern:

 JButtonMatcher m = withText(Pattern.compile("O.*"));
 

The following code listing shows how to match a JButton, that should be showing on the screen, by text, using a regular expression pattern:

 JButtonMatcher m = withText(Pattern.compile("O.*")).andShowing();
 

Parameters:
textPattern - the regular expression pattern to match.
Returns:
the created matcher.
Since:
1.2

any

public static JButtonMatcher any()
Creates a new JButtonMatcher that matches any JButton.

Returns:
the created matcher.

andText

public JButtonMatcher andText(String newText)
Specifies the text to match. If this matcher was created using withText(String) or withText(Pattern), this method will simply update the text to match.

Parameters:
newText - the new text to match. It can be a regular expression.
Returns:
this matcher.

andText

public JButtonMatcher andText(Pattern textPattern)
Specifies the text to match. If this matcher was created using withText(String) or withText(Pattern), this method will simply update the text to match.

Parameters:
textPattern - the regular expression pattern to match.
Returns:
this matcher.
Since:
1.2

andShowing

public JButtonMatcher andShowing()
Indicates that the JButton to match should be showing on the screen.

Returns:
this matcher.

isMatching

@RunsInCurrentThread
protected boolean isMatching(JButton button)
Indicates whether:

Note: This method is not guaranteed to be executed in the event dispatch thread (EDT.) Clients are responsible for calling this method from the EDT.

Specified by:
isMatching in class GenericTypeMatcher<JButton>
Parameters:
button - the JButton to match.
Returns:
true if the JButton matches the search criteria in this matcher.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.