Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright 2012-2015 the original author or authors.
 
 package org.assertj.swing.conditions;
 
 
 import java.awt.*;

A Condition that requires focus to be inside a component.

Author(s):
Peter Murray
 
 public class ComponentFocusedCondition extends Condition {
 
   private final ComponentFinder _finder;
 
   private final ComponentMatcher _matcher;

  
Creates a new ComponentVisibleCondition

Parameters:
name The name of the component to find in the GUI.
 
   public ComponentFocusedCondition(String name) {
 	this(BasicComponentFinder.finderWithCurrentAwtHierarchy(),
 	     new NameMatcher(nametrue));
   }

  
Creates a new ComponentVisibleCondition

Parameters:
name The name of the component to find in the GUI.
type The type of the component to find.
 
   public ComponentFocusedCondition(String nameClass<? extends Componenttype) {
 	this(BasicComponentFinder.finderWithCurrentAwtHierarchy(),
 	     new NameMatcher(nametypetrue));
   }

  
Creates a new ComponentVisibleCondition

Parameters:
finder performs the component search.
matcher specifies the condition that the component we are looking for needs to match.
 
 	                               ComponentMatcher matcher) {
 	this("Component Focused Condition"findermatcher);
   }

  
Creates a new ComponentVisibleCondition

Parameters:
description the description of this condition.
finder performs the component search.
matcher specifies the condition that the component we are looking for needs to match.
 
   public ComponentFocusedCondition(String description,
 	                               ComponentFinder finder,
 	                               ComponentMatcher matcher) {
 	super(description);
 	 = finder;
 	 = matcher;
   }

  
Returns true if a component that matches the search criteria in this condition's org.assertj.swing.core.ComponentMatcher can be found. Otherwise, this method returns false.

Returns:
true if a matching component can be found, false otherwise.
 
   @Override
   public boolean test() {
 	try {
 	  Component found = .find();
 	  return found.isFocusOwner();
 	} catch (ComponentLookupException e) {
 	  // Ignore the exception and return false
 	}
 	return false;
  }
New to GrepCode? Check out our FAQ X