001 /*
002 * Created on Jul 31, 2007
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 @2007-2010 the original author or authors.
015 */
016 package org.fest.swing.finder;
017
018 import java.awt.*;
019 import java.util.concurrent.TimeUnit;
020
021 import org.fest.swing.core.GenericTypeMatcher;
022 import org.fest.swing.core.Robot;
023 import org.fest.swing.fixture.FrameFixture;
024
025 /**
026 * Understands a finder for <code>{@link Frame}</code>s. This class cannot be used directly, please see
027 * <code>{@link WindowFinder}</code>.
028 *
029 * @author Alex Ruiz
030 * @author Yvonne Wang
031 */
032 public class FrameFinder extends WindowFinderTemplate<Frame> {
033
034 /**
035 * Creates a new </code>{@link FrameFinder}</code>.
036 * @param frameName the name of the {@code Frame} to look for.
037 */
038 protected FrameFinder(String frameName) {
039 super(frameName, Frame.class);
040 }
041
042 /**
043 * Creates a new </code>{@link FrameFinder}</code>.
044 * @param matcher specifies the search criteria to use when looking up a {@code Frame}.
045 */
046 protected FrameFinder(GenericTypeMatcher<? extends Frame> matcher) {
047 super(matcher);
048 }
049
050 /**
051 * Creates a new </code>{@link FrameFinder}</code>.
052 * @param frameType the type of {@code Frame} to look for.
053 */
054 protected FrameFinder(Class<? extends Frame> frameType) {
055 super(frameType);
056 }
057
058 /**
059 * Sets the timeout for this finder. The window to search should be found within the given time period.
060 * @param timeout the number of milliseconds before stopping the search.
061 * @return this finder.
062 */
063 @Override public FrameFinder withTimeout(long timeout) {
064 super.withTimeout(timeout);
065 return this;
066 }
067
068 /**
069 * Sets the timeout for this finder. The window to search should be found within the given time period.
070 * @param timeout the period of time the search should be performed.
071 * @param unit the time unit for <code>timeout</code>.
072 * @return this finder.
073 */
074 @Override public FrameFinder withTimeout(long timeout, TimeUnit unit) {
075 super.withTimeout(timeout, unit);
076 return this;
077 }
078
079 /**
080 * Finds a <code>{@link Frame}</code> by name or type.
081 * @param robot contains the underlying finding to delegate the search to.
082 * @return a <code>FrameFixture</code> managing the found <code>Frame</code>.
083 * @throws org.fest.swing.exception.WaitTimedOutError if a <code>Frame</code> could not be found.
084 */
085 public FrameFixture using(Robot robot) {
086 return new FrameFixture(robot, findComponentWith(robot));
087 }
088
089 /**
090 * Casts the given {@code Component} to <code>{@link Frame}</code>.
091 * @return the given {@code Component}, casted to {@code Frame}.
092 */
093 protected Frame cast(Component c) { return (Frame) c; }
094 }