001 /*
002 * Created on Sep 1, 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.driver;
017
018 import static org.fest.swing.edt.GuiActionRunner.execute;
019
020 import javax.swing.JScrollBar;
021 import javax.swing.JScrollPane;
022
023 import org.fest.swing.annotation.RunsInEDT;
024 import org.fest.swing.core.Robot;
025 import org.fest.swing.edt.GuiQuery;
026
027 /**
028 * Understands functional testing of <code>{@link JScrollPane}</code>s:
029 * <ul>
030 * <li>user input simulation</li>
031 * <li>state verification</li>
032 * <li>property value query</li>
033 * </ul>
034 * This class is intended for internal use only. Please use the classes in the package
035 * <code>{@link org.fest.swing.fixture}</code> in your tests.
036 *
037 * @author Yvonne Wang
038 */
039 public class JScrollPaneDriver extends JComponentDriver {
040
041 /**
042 * Creates a new </code>{@link JScrollPaneDriver}</code>.
043 * @param robot the robot the robot to use to simulate user input.
044 */
045 public JScrollPaneDriver(Robot robot) {
046 super(robot);
047 }
048
049 /**
050 * Returns the horizontal <code>{@link JScrollBar}</code> in the given <code>{@link JScrollPane}</code>.
051 * @param scrollPane the given <code>JScrollBar</code>.
052 * @return the horizontal scroll bar in the given <code>JScrollBar</code>.
053 */
054 @RunsInEDT
055 public JScrollBar horizontalScrollBarIn(JScrollPane scrollPane) {
056 return horizontalScrollBar(scrollPane);
057 }
058
059 @RunsInEDT
060 private static JScrollBar horizontalScrollBar(final JScrollPane scrollPane) {
061 return execute(new GuiQuery<JScrollBar>() {
062 protected JScrollBar executeInEDT() {
063 return scrollPane.getHorizontalScrollBar();
064 }
065 });
066 }
067
068 /**
069 * Returns the vertical <code>{@link JScrollBar}</code> in the given <code>{@link JScrollPane}</code>.
070 * @param scrollPane the given <code>JScrollBar</code>.
071 * @return the vertical scroll bar in the given <code>JScrollBar</code>.
072 */
073 @RunsInEDT
074 public JScrollBar verticalScrollBarIn(JScrollPane scrollPane) {
075 return verticalScrollBar(scrollPane);
076 }
077
078 @RunsInEDT
079 private static JScrollBar verticalScrollBar(final JScrollPane scrollPane) {
080 return execute(new GuiQuery<JScrollBar>() {
081 protected JScrollBar executeInEDT() {
082 return scrollPane.getVerticalScrollBar();
083 }
084 });
085 }
086 }