Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
24   229   15   1.6
0   89   0.62   15
15     1  
1    
 
  JTableHeaderDriver       Line # 50 24 0% 15 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Mar 16, 2008
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 @2008-2010 the original author or authors.
15    */
16    package org.fest.swing.driver;
17   
18    import static org.fest.swing.core.MouseButton.LEFT_BUTTON;
19    import static org.fest.swing.driver.ComponentStateValidator.validateIsEnabledAndShowing;
20    import static org.fest.swing.edt.GuiActionRunner.execute;
21    import static org.fest.swing.timing.Pause.pause;
22   
23    import java.awt.Point;
24    import java.util.regex.Pattern;
25   
26    import javax.swing.JPopupMenu;
27    import javax.swing.table.JTableHeader;
28   
29    import org.fest.swing.annotation.RunsInEDT;
30    import org.fest.swing.core.MouseButton;
31    import org.fest.swing.core.Robot;
32    import org.fest.swing.edt.GuiQuery;
33    import org.fest.swing.exception.ComponentLookupException;
34    import org.fest.swing.exception.LocationUnavailableException;
35    import org.fest.swing.util.*;
36   
37    /**
38    * Understands functional testing of <code>{@link JTableHeader}</code>s:
39    * <ul>
40    * <li>user input simulation</li>
41    * <li>state verification</li>
42    * <li>property value query</li>
43    * </ul>
44    * This class is intended for internal use only. Please use the classes in the package
45    * <code>{@link org.fest.swing.fixture}</code> in your tests.
46    *
47    * @author Yvonne Wang
48    * @author Alex Ruiz
49    */
 
50    public class JTableHeaderDriver extends JComponentDriver {
51   
52    private final JTableHeaderLocation location = new JTableHeaderLocation();
53   
54    /**
55    * Creates a new </code>{@link JTableHeaderDriver}</code>.
56    * @param robot the robot to use to simulate user input.
57    */
 
58  40 toggle public JTableHeaderDriver(Robot robot) {
59  40 super(robot);
60    }
61   
62    /**
63    * Clicks the column under the given index.
64    * @param tableHeader the target <code>JTableHeader</code>.
65    * @param columnIndex the given index.
66    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
67    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
68    * @throws IndexOutOfBoundsException if the index is out of bounds.
69    */
 
70  9 toggle @RunsInEDT
71    public void clickColumn(JTableHeader tableHeader, int columnIndex) {
72  9 clickColumn(tableHeader, columnIndex, LEFT_BUTTON, 1);
73    }
74   
75    /**
76    * Clicks the column under the given index using the given mouse button the given number of times.
77    * @param tableHeader the target <code>JTableHeader</code>.
78    * @param columnIndex the given index.
79    * @param button the mouse button to use.
80    * @param times the number of times to click.
81    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
82    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
83    * @throws IndexOutOfBoundsException if the index is out of bounds.
84    */
 
85  9 toggle @RunsInEDT
86    public void clickColumn(JTableHeader tableHeader, int columnIndex, MouseButton button, int times) {
87  9 Point p = pointAtIndex(tableHeader, columnIndex, location);
88  5 robot.click(tableHeader, p, button, times);
89  5 pause(300); // needs more time when sorting a column (JDK 1.6)
90    }
91   
92    /**
93    * Clicks the column which name matches the given value.
94    * @param tableHeader the target <code>JTableHeader</code>.
95    * @param columnName the column name to match. It can be a regular expression.
96    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
97    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
98    * @throws LocationUnavailableException if a column with a matching name cannot be found.
99    */
 
100  5 toggle @RunsInEDT
101    public void clickColumn(JTableHeader tableHeader, String columnName) {
102  5 clickColumn(tableHeader, columnName, LEFT_BUTTON, 1);
103    }
104   
105    /**
106    * Clicks the column which name matches the given regular expression pattern.
107    * @param tableHeader the target <code>JTableHeader</code>.
108    * @param columnNamePattern the the regular expression pattern to match.
109    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
110    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
111    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
112    * @throws LocationUnavailableException if a column with a matching name cannot be found.
113    * @since 1.2
114    */
 
115  2 toggle @RunsInEDT
116    public void clickColumn(JTableHeader tableHeader, Pattern columnNamePattern) {
117  2 clickColumn(tableHeader, columnNamePattern, LEFT_BUTTON, 1);
118    }
119   
120    /**
121    * Clicks the column which name matches the given one using the given mouse button the given number of times.
122    * @param tableHeader the target <code>JTableHeader</code>.
123    * @param columnName the column name to match. It can be a regular expression.
124    * @param button the mouse button to use.
125    * @param times the number of times to click.
126    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
127    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
128    * @throws LocationUnavailableException if a column with a matching name cannot be found.
129    */
 
130  7 toggle @RunsInEDT
131    public void clickColumn(JTableHeader tableHeader, String columnName, MouseButton button, int times) {
132  7 clickColumn(tableHeader, new StringTextMatcher(columnName), button, times);
133    }
134   
135    /**
136    * Clicks the column which name matches the given regular expression pattern using the given mouse button the given
137    * number of times.
138    * @param tableHeader the target <code>JTableHeader</code>.
139    * @param columnNamePattern the regular expression pattern to match.
140    * @param button the mouse button to use.
141    * @param times the number of times to click.
142    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
143    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
144    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
145    * @throws LocationUnavailableException if a column with a matching name cannot be found.
146    * @since 1.2
147    */
 
148  3 toggle @RunsInEDT
149    public void clickColumn(JTableHeader tableHeader, Pattern columnNamePattern, MouseButton button, int times) {
150  3 clickColumn(tableHeader, new PatternTextMatcher(columnNamePattern), button, times);
151    }
152   
 
153  10 toggle @RunsInEDT
154    private void clickColumn(JTableHeader tableHeader, TextMatcher matcher, MouseButton button, int times) {
155  10 Point p = pointAtName(tableHeader, matcher, location);
156  6 robot.click(tableHeader, p, button, times);
157    }
158   
159    /**
160    * Shows a pop-up menu at the given column.
161    * @param tableHeader the target <code>JTableHeader</code>.
162    * @param columnIndex the index of the column.
163    * @return the displayed pop-up menu.
164    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
165    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
166    * @throws IndexOutOfBoundsException if the index is out of bounds.
167    * @throws ComponentLookupException if a pop-up menu cannot be found.
168    */
 
169  1 toggle @RunsInEDT
170    public JPopupMenu showPopupMenu(JTableHeader tableHeader, int columnIndex) {
171  1 return robot.showPopupMenu(tableHeader, pointAtIndex(tableHeader, columnIndex, location));
172    }
173   
 
174  10 toggle @RunsInEDT
175    private static Point pointAtIndex(final JTableHeader tableHeader, final int columnIndex,
176    final JTableHeaderLocation location) {
177  10 return execute(new GuiQuery<Point>() {
 
178  10 toggle protected Point executeInEDT() {
179  10 Point p = location.pointAt(tableHeader, columnIndex);
180  8 validateIsEnabledAndShowing(tableHeader);
181  6 tableHeader.getTable().scrollRectToVisible(tableHeader.getHeaderRect(columnIndex));
182  6 return p;
183    }
184    });
185    }
186   
187    /**
188    * Shows a pop-up menu at the given column.
189    * @param tableHeader the target <code>JTableHeader</code>.
190    * @param columnName the name of the column. It can be a regular expression.
191    * @return the displayed pop-up menu.
192    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
193    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
194    * @throws ComponentLookupException if a pop-up menu cannot be found.
195    */
 
196  2 toggle @RunsInEDT
197    public JPopupMenu showPopupMenu(JTableHeader tableHeader, String columnName) {
198  2 return robot.showPopupMenu(tableHeader, pointAtName(tableHeader, new StringTextMatcher(columnName), location));
199    }
200   
201    /**
202    * Shows a pop-up menu at the column whose name matches the given regular expression pattern.
203    * @param tableHeader the target <code>JTableHeader</code>.
204    * @param pattern the regular expression pattern to match.
205    * @return the displayed pop-up menu.
206    * @throws IllegalStateException if the <code>JTableHeader</code> is disabled.
207    * @throws IllegalStateException if the <code>JTableHeader</code> is not showing on the screen.
208    * @throws NullPointerException if the given regular expression pattern is <code>null</code>.
209    * @throws ComponentLookupException if a pop-up menu cannot be found.
210    * @since 1.2
211    */
 
212  1 toggle @RunsInEDT
213    public JPopupMenu showPopupMenu(JTableHeader tableHeader, Pattern pattern) {
214  1 return robot.showPopupMenu(tableHeader, pointAtName(tableHeader, new PatternTextMatcher(pattern), location));
215    }
216   
 
217  13 toggle @RunsInEDT
218    private static Point pointAtName(final JTableHeader tableHeader, final TextMatcher matcher,
219    final JTableHeaderLocation location) {
220  13 return execute(new GuiQuery<Point>() {
 
221  13 toggle protected Point executeInEDT() {
222  13 Pair<Integer, Point> indexAndLocation = location.pointAt(tableHeader, matcher);
223  11 validateIsEnabledAndShowing(tableHeader);
224  9 tableHeader.getTable().scrollRectToVisible(tableHeader.getHeaderRect(indexAndLocation.i));
225  9 return indexAndLocation.ii;
226    }
227    });
228    }
229    }