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