| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 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 |
|
@link |
| 34 |
|
|
| 35 |
|
@author |
| 36 |
|
@author |
| 37 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 9 |
Complexity Density: 0.64 |
|
| 38 |
|
public class JTabbedPaneLocation { |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@param |
| 47 |
|
@param |
| 48 |
|
@return |
| 49 |
|
@throws |
| 50 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 51 |
2
|
@RunsInCurrentThread... |
| 52 |
|
public int indexOf(JTabbedPane tabbedPane, String title) { |
| 53 |
2
|
return indexOf(tabbedPane, new StringTextMatcher(title)); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
@link |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
@param |
| 63 |
|
@param |
| 64 |
|
@return |
| 65 |
|
@throws |
| 66 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 67 |
4
|
@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 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@param |
| 82 |
|
@param |
| 83 |
|
@return |
| 84 |
|
@throws |
| 85 |
|
@throws |
| 86 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 87 |
10
|
@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 |
|
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 97 |
24
|
@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 |
|
} |