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
14   105   9   3.5
6   41   0.64   4
4     2.25  
1    
 
  JTabbedPaneLocation       Line # 38 14 0% 9 2 91.7% 0.9166667
 
No Tests
 
1    /*
2    * Created on Jan 27, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * 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 is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2008-2010 the original author or authors.
14    */
15    package org.fest.swing.driver;
16   
17    import static java.lang.String.valueOf;
18    import static org.fest.swing.driver.JTabbedPaneTabIndexQuery.indexOfTab;
19    import static org.fest.util.Strings.concat;
20   
21    import java.awt.Point;
22    import java.awt.Rectangle;
23   
24    import javax.swing.JTabbedPane;
25   
26    import org.fest.swing.annotation.RunsInCurrentThread;
27    import org.fest.swing.exception.LocationUnavailableException;
28    import org.fest.swing.util.StringTextMatcher;
29    import org.fest.swing.util.TextMatcher;
30    import org.fest.util.VisibleForTesting;
31   
32    /**
33    * Understands a location on a <code>{@link JTabbedPane}</code> (notably a tab).
34    *
35    * @author Alex Ruiz
36    * @author Yvonne Wang
37    */
 
38    public class JTabbedPaneLocation {
39   
40    /**
41    * Returns the index of the first tab that matches the given <code>String</code>.
42    * <p>
43    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
44    * responsible for calling this method from the EDT.
45    * </p>
46    * @param tabbedPane the target <code>JTabbedPane</code>.
47    * @param title the title to match.
48    * @return the index of the first tab that matches the given <code>String</code>.
49    * @throws LocationUnavailableException if a tab matching the given title could not be found.
50    */
 
51  2 toggle @RunsInCurrentThread
52    public int indexOf(JTabbedPane tabbedPane, String title) {
53  2 return indexOf(tabbedPane, new StringTextMatcher(title));
54    }
55   
56    /**
57    * Returns the index of the first tab whose title matches the value in the given <code>{@link TextMatcher}</code>.
58    * <p>
59    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
60    * responsible for calling this method from the EDT.
61    * </p>
62    * @param tabbedPane the target <code>JTabbedPane</code>.
63    * @param matcher indicates if the text of the <code>JTabbedPane</code> matches the value we are looking for.
64    * @return the index of the first tab that matches the given <code>String</code>.
65    * @throws LocationUnavailableException if a tab matching the given title could not be found.
66    */
 
67  4 toggle @RunsInCurrentThread
68    public int indexOf(final JTabbedPane tabbedPane, final TextMatcher matcher) {
69  4 int index = indexOfTab(tabbedPane, matcher);
70  3 if (index >= 0) return index;
71  1 throw new LocationUnavailableException(concat(
72    "Unable to find a tab with title matching ", matcher.description(), " ", matcher.formattedValues()));
73    }
74   
75    /**
76    * Returns the coordinates of the tab under the given index.
77    * <p>
78    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
79    * responsible for calling this method from the EDT.
80    * </p>
81    * @param tabbedPane the target <code>JTabbedPane</code>.
82    * @param index the given index.
83    * @return the coordinates of the tab under the given index.
84    * @throws IndexOutOfBoundsException if the given index is negative or out of bounds.
85    * @throws LocationUnavailableException if the tab under the given index is not visible.
86    */
 
87  10 toggle @RunsInCurrentThread
88    public Point pointAt(final JTabbedPane tabbedPane, final int index) {
89  10 validateIndex(tabbedPane, index);
90  10 Rectangle rect = tabbedPane.getUI().getTabBounds(tabbedPane, index);
91    // From Abbot: TODO figure out the effects of tab layout policy sometimes tabs are not directly visible
92  10 if (rect == null || rect.x < 0)
93  0 throw new LocationUnavailableException(concat("The tab '", valueOf(index), "' is not visible"));
94  10 return new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
95    }
96   
 
97  24 toggle @VisibleForTesting
98    @RunsInCurrentThread
99    void validateIndex(JTabbedPane tabbedPane, int index) {
100  24 int max = tabbedPane.getTabCount() - 1;
101  20 if (index >= 0 && index <= max) return;
102  4 throw new IndexOutOfBoundsException(concat(
103    "Index <", valueOf(index), "> is not within the JTabbedPane bounds of <0> and <", valueOf(max), "> (inclusive)"));
104    }
105    }