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.Window; 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.WindowFixture; 024 025 /** 026 * Understands a template for <code>{@link Window}</code> finders. 027 * @param <T> the type of window this finder can search. 028 * 029 * @author Yvonne Wang 030 * @author Alex Ruiz 031 */ 032 public abstract class WindowFinderTemplate<T extends Window> extends ComponentFinderTemplate<T> { 033 034 /** 035 * Creates a new </code>{@link WindowFinderTemplate}</code>. 036 * @param windowName the name of the {@code Window} to find. 037 * @param windowType the type of the {@code Window} to find. 038 */ 039 protected WindowFinderTemplate(String windowName, Class<? extends T> windowType) { 040 super(windowName, windowType); 041 } 042 043 /** 044 * Creates a new </code>{@link WindowFinderTemplate}</code>. 045 * @param matcher specifies the search criteria to use when looking up a {@code Window}. 046 */ 047 protected WindowFinderTemplate(GenericTypeMatcher<? extends T> matcher) { 048 super(matcher); 049 } 050 051 /** 052 * Creates a new </code>{@link WindowFinderTemplate}</code>. 053 * @param windowType the type of the {@code Window} to find. 054 */ 055 protected WindowFinderTemplate(Class<? extends T> windowType) { 056 super(windowType); 057 } 058 059 /** 060 * Sets the timeout for this finder. The <code>{@link Window}</code> to find should be found within the given time 061 * period. 062 * @param timeout the number of milliseconds before stopping the search. 063 * @return this finder. 064 * @throws IllegalArgumentException if the timeout is a negative number. 065 */ 066 @Override protected WindowFinderTemplate<T> withTimeout(long timeout) { 067 super.withTimeout(timeout); 068 return this; 069 } 070 071 /** 072 * Sets the timeout for this finder. The <code>{@link Window}</code> to find should be found within the given time 073 * period. 074 * @param timeout the period of time the search should be performed. 075 * @param unit the time unit for <code>timeout</code>. 076 * @return this finder. 077 * @throws NullPointerException if the time unit is <code>null</code>. 078 * @throws IllegalArgumentException if the timeout is a negative number. 079 */ 080 @Override protected WindowFinderTemplate<T> withTimeout(long timeout, TimeUnit unit) { 081 super.withTimeout(timeout, unit); 082 return this; 083 } 084 085 /** 086 * Finds a window by name or type using the given robot. 087 * @param robot contains the underlying finding to delegate the search to. 088 * @return a fixture capable of managing the found window. 089 * @throws org.fest.swing.exception.WaitTimedOutError if a window with the given name or of the given type could not 090 * be found. 091 */ 092 public abstract WindowFixture<T> using(Robot robot); 093 }