|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| JFileChooserFinder | Line # 73 | 11 | 9.1% | 9 | 0 | 100% |
1.0
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| No Tests | |||
| 1 | /* | |
| 2 | * Created on Oct 29, 2007 | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
| 5 | * in compliance with the License. You may obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the License | |
| 10 | * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 11 | * or implied. See the License for the specific language governing permissions and limitations under | |
| 12 | * the License. | |
| 13 | * | |
| 14 | * Copyright @2007-2010 the original author or authors. | |
| 15 | */ | |
| 16 | package org.fest.swing.finder; | |
| 17 | ||
| 18 | import java.awt.Component; | |
| 19 | import java.util.concurrent.TimeUnit; | |
| 20 | ||
| 21 | import javax.swing.JFileChooser; | |
| 22 | ||
| 23 | import org.fest.swing.core.GenericTypeMatcher; | |
| 24 | import org.fest.swing.core.Robot; | |
| 25 | import org.fest.swing.fixture.JFileChooserFixture; | |
| 26 | ||
| 27 | /** | |
| 28 | * Understands a finder for <code>{@link JFileChooser}</code>s. Lookups are performed till a file chooser is found, | |
| 29 | * or until the given time to perform the lookup is over. The default lookup time is 5 seconds. | |
| 30 | * </p> | |
| 31 | * <p> | |
| 32 | * This example illustrates finding a <code>{@link JFileChooser}</code> by name, using the default lookup time (5 | |
| 33 | * seconds): | |
| 34 | * | |
| 35 | * <pre> | |
| 36 | * JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().using(robot); | |
| 37 | * </pre> | |
| 38 | * | |
| 39 | * </p> | |
| 40 | * <p> | |
| 41 | * Where <code>robot</code> is an instance of <code>{@link org.fest.swing.core.Robot}</code>. | |
| 42 | * </p> | |
| 43 | * <p> | |
| 44 | * This example shows how to find a <code>{@link JFileChooser}</code> by type using a lookup time of 10 seconds: | |
| 45 | * | |
| 46 | * <pre> | |
| 47 | * JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().withTimeout(10000).using(robot); | |
| 48 | * </pre> | |
| 49 | * | |
| 50 | * We can also specify the time unit: | |
| 51 | * | |
| 52 | * <pre> | |
| 53 | * JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser().withTimeout(10, {@link java.util.concurrent.TimeUnit#SECONDS SECONDS}).using(robot); | |
| 54 | * </pre> | |
| 55 | * | |
| 56 | * </p> | |
| 57 | * <p> | |
| 58 | * This examples shows how to find a <code>{@link JFileChooser}</code> using a <code>{@link GenericTypeMatcher}</code>: | |
| 59 | * | |
| 60 | * <pre> | |
| 61 | * GenericTypeMatcher<JFileChooser> matcher = new GenericTypeMatcher<JFileChooser>() { | |
| 62 | * protected boolean isMatching(JFileChooser fileChooser) { | |
| 63 | * return fileChooser.getCurrentDirectory().getAbsolutePath().equals("c:\\temp"); | |
| 64 | * } | |
| 65 | * }; | |
| 66 | * JFileChooserFixture fileChooser = JFileChooserFinder.findFileChooser(matcher).using(robot); | |
| 67 | * </pre> | |
| 68 | * | |
| 69 | * </p> | |
| 70 | * | |
| 71 | * @author Alex Ruiz | |
| 72 | */ | |
| 73 | public class JFileChooserFinder extends ComponentFinderTemplate<JFileChooser> { | |
| 74 | ||
| 75 | /** | |
| 76 | * Creates a new </code>{@link JFileChooserFinder}</code>. This finder looks up a <code>{@link JFileChooser}</code> by | |
| 77 | * type. | |
| 78 | */ | |
| 79 |
protected JFileChooserFinder() { |
|
| 80 | super(JFileChooser.class); | |
| 81 | } | |
| 82 | ||
| 83 | /** | |
| 84 | * Creates a new </code>{@link JFileChooserFinder}</code>. | |
| 85 | * @param name the name of the {@code FileChooser} to look for. | |
| 86 | */ | |
| 87 | 6 |
protected JFileChooserFinder(String name) { |
| 88 | 6 | super(name, JFileChooser.class); |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Creates a new </code>{@link JFileChooserFinder}</code>. | |
| 93 | * @param matcher specifies the search criteria to use when looking up a {@code JFileChooser}. | |
| 94 | */ | |
| 95 | 6 |
protected JFileChooserFinder(GenericTypeMatcher<? extends JFileChooser> matcher) { |
| 96 | 6 | super(matcher); |
| 97 | } | |
| 98 | ||
| 99 | /** | |
| 100 | * Creates a new <code>{@link JFileChooserFinder}</code> capable of looking up a <code>{@link JFileChooser}</code>. | |
| 101 | * @return the created finder. | |
| 102 | */ | |
| 103 | 6 |
public static JFileChooserFinder findFileChooser() { |
| 104 | 6 | return new JFileChooserFinder(); |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Creates a new <code>{@link JFileChooserFinder}</code> capable of looking up a <code>{@link JFileChooser}</code> by | |
| 109 | * name. | |
| 110 | * @param name the name of the file chooser to find. | |
| 111 | * @return the created finder. | |
| 112 | */ | |
| 113 | 8 |
public static JFileChooserFinder findFileChooser(String name) { |
| 114 | 8 | return new JFileChooserFinder(name); |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Creates a new <code>{@link JFileChooserFinder}</code> capable of looking up a <code>{@link JFileChooser}</code> | |
| 119 | * using the given matcher. | |
| 120 | * @param matcher the given matcher. | |
| 121 | * @return the created finder. | |
| 122 | */ | |
| 123 | 7 |
public static JFileChooserFinder findFileChooser(GenericTypeMatcher<? extends JFileChooser> matcher) { |
| 124 | 7 | return new JFileChooserFinder(matcher); |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * Finds a <code>{@link JFileChooser}</code> by name or type. | |
| 129 | * @param robot contains the underlying finding to delegate the search to. | |
| 130 | * @return a <code>JFileChooserFixture</code> managing the found {@code JFileChooser}. | |
| 131 | * @throws org.fest.swing.exception.WaitTimedOutError if a {@code JFileChooser} could not be found. | |
| 132 | */ | |
| 133 | 12 |
public JFileChooserFixture using(Robot robot) { |
| 134 | 12 | return new JFileChooserFixture(robot, findComponentWith(robot)); |
| 135 | } | |
| 136 | ||
| 137 | /** | |
| 138 | * Sets the timeout for this finder. The <code>{@link JFileChooser}</code> to find should be found within the given | |
| 139 | * time period. | |
| 140 | * @param timeout the number of milliseconds before stopping the search. | |
| 141 | * @return this finder. | |
| 142 | * @throws IllegalArgumentException if the timeout is a negative number. | |
| 143 | */ | |
| 144 | 9 |
@Override public JFileChooserFinder withTimeout(long timeout) { |
| 145 | 9 | super.withTimeout(timeout); |
| 146 | 6 | return this; |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * Sets the timeout for this finder. The <code>{@link JFileChooser}</code> to find should be found within the given | |
| 151 | * time period. | |
| 152 | * @param timeout the period of time the search should be performed. | |
| 153 | * @param unit the time unit for <code>timeout</code>. | |
| 154 | * @return this finder. | |
| 155 | * @throws NullPointerException if the time unit is <code>null</code>. | |
| 156 | * @throws IllegalArgumentException if the timeout is a negative number. | |
| 157 | */ | |
| 158 | 6 |
@Override public JFileChooserFinder withTimeout(long timeout, TimeUnit unit) { |
| 159 | 6 | super.withTimeout(timeout, unit); |
| 160 | 3 | return this; |
| 161 | } | |
| 162 | ||
| 163 | /** | |
| 164 | * Casts the given {@code Component} to <code>{@link JFileChooser}</code>. | |
| 165 | * @return the given {@code Component}, casted to {@code JFileChooser}. | |
| 166 | */ | |
| 167 | 9 |
protected JFileChooser cast(Component c) { return (JFileChooser) c; } |
| 168 | } | |
|
||||||||||||