001 /* 002 * Created on Oct 19, 2008 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 * 014 * Copyright @2008-2010 the original author or authors. 015 */ 016 package org.fest.swing.core; 017 018 import java.awt.Component; 019 020 import org.fest.swing.annotation.RunsInCurrentThread; 021 022 /** 023 * Understands a base class for implementations of <code>{@link ResettableComponentMatcher}</code>. 024 * 025 * @author Yvonne Wang 026 * @author Alex Ruiz 027 */ 028 public abstract class AbstractComponentMatcher implements ResettableComponentMatcher { 029 030 private boolean requireShowing; 031 032 /** 033 * Creates a new </code>{@link AbstractComponentMatcher}</code>. 034 */ 035 public AbstractComponentMatcher() { 036 this(false); 037 } 038 039 /** 040 * Creates a new </code>{@link AbstractComponentMatcher}</code>. 041 * @param requireShowing indicates if the component to match should be showing or not. 042 */ 043 public AbstractComponentMatcher(boolean requireShowing) { 044 requireShowing(requireShowing); 045 } 046 047 /** 048 * Indicates whether the component to match has to be showing. 049 * @return <code>true</code> if the component to find has to be showing, <code>false</code> otherwise. 050 */ 051 protected final boolean requireShowing() { return requireShowing; } 052 053 /** 054 * Updates the value of the flag that indicates if the component to match should be showing or not. 055 * @param shouldBeShowing the new value to set. 056 */ 057 protected final void requireShowing(boolean shouldBeShowing) { 058 requireShowing = shouldBeShowing; 059 } 060 061 /** 062 * Indicates if the value of the "showing" property of the given component matches the value specified in this 063 * matcher. 064 * <p> 065 * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are 066 * responsible for calling this method from the EDT. 067 * </p> 068 * @param c the component to verify. 069 * @return <code>true</code> if the value of the "isShowing" property of the given component matches the value 070 * specified in this matcher, <code>false</code> otherwise. 071 */ 072 @RunsInCurrentThread 073 protected final boolean requireShowingMatches(Component c) { 074 return !requireShowing || c.isShowing(); 075 } 076 077 /** 078 * Resets the internal state of this matcher. 079 * @param matchFound indicates whether a match has been found before resetting. 080 * @since 1.2 081 */ 082 public void reset(boolean matchFound) {} 083 }