| 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.awt.BorderLayout.*; |
| 18 |
|
import static java.lang.Math.max; |
| 19 |
|
import static javax.swing.SwingConstants.HORIZONTAL; |
| 20 |
|
import static org.fest.util.Arrays.format; |
| 21 |
|
import static org.fest.util.Strings.concat; |
| 22 |
|
import static org.fest.util.Strings.quote; |
| 23 |
|
|
| 24 |
|
import java.awt.*; |
| 25 |
|
|
| 26 |
|
import javax.swing.JToolBar; |
| 27 |
|
|
| 28 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@link |
| 32 |
|
|
| 33 |
|
@author |
| 34 |
|
@author |
| 35 |
|
|
|
|
|
| 68.8% |
Uncovered Elements: 20 (64) |
Complexity: 17 |
Complexity Density: 0.47 |
|
| 36 |
|
public final class JToolBarLocation { |
| 37 |
|
|
| 38 |
|
private static String[] VALID_CONSTRAINTS = { NORTH, EAST, SOUTH, WEST }; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@link |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@param |
| 47 |
|
@return |
| 48 |
|
|
|
|
|
| 37.5% |
Uncovered Elements: 10 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 49 |
10
|
@RunsInCurrentThread... |
| 50 |
|
public Point pointToGrab(JToolBar toolBar) { |
| 51 |
10
|
Insets insets = toolBar.getInsets(); |
| 52 |
10
|
int width = toolBar.getWidth(); |
| 53 |
10
|
int height = toolBar.getHeight(); |
| 54 |
10
|
if (max(max(max(insets.left, insets.top), insets.right), insets.bottom) == insets.left) |
| 55 |
10
|
return new Point(insets.left / 2, height / 2); |
| 56 |
0
|
if (max(max(insets.top, insets.right), insets.bottom) == insets.top) |
| 57 |
0
|
return new Point(width / 2, insets.top / 2); |
| 58 |
0
|
if (max(insets.right, insets.bottom) == insets.right) |
| 59 |
0
|
return new Point(width - insets.right / 2, height / 2); |
| 60 |
0
|
return new Point(width / 2, height - insets.bottom / 2); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
@link |
| 65 |
|
@link |
| 66 |
|
@link@link |
| 67 |
|
@link |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
@param |
| 73 |
|
@param |
| 74 |
|
@param |
| 75 |
|
@return |
| 76 |
|
@throws |
| 77 |
|
|
|
|
|
| 82.1% |
Uncovered Elements: 5 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
| 78 |
4
|
@RunsInCurrentThread... |
| 79 |
|
public Point dockLocation(JToolBar toolBar, Container dock, String constraint) { |
| 80 |
4
|
validate(constraint); |
| 81 |
4
|
Insets insets = dock.getInsets(); |
| 82 |
|
|
| 83 |
|
|
| 84 |
4
|
int offset = isHorizontal(toolBar) ? toolBar.getHeight() : toolBar.getWidth(); |
| 85 |
4
|
Dimension dockSize = dock.getSize(); |
| 86 |
4
|
if (NORTH.equals(constraint)) |
| 87 |
1
|
return new Point(dockSize.width / 2, insets.top); |
| 88 |
3
|
if (EAST.equals(constraint)) |
| 89 |
1
|
return new Point(dockSize.width - insets.right - 1, verticalDockingYCoordinate(dockSize.height, insets, offset)); |
| 90 |
2
|
if (WEST.equals(constraint)) |
| 91 |
1
|
return new Point(insets.left, verticalDockingYCoordinate(dockSize.height, insets, offset)); |
| 92 |
1
|
int x = dockSize.width / 2; |
| 93 |
|
|
| 94 |
1
|
if (x < insets.left + offset) |
| 95 |
0
|
x = insets.left + offset; |
| 96 |
1
|
else if (x > dockSize.width - insets.right - offset - 1) |
| 97 |
0
|
x = dockSize.width - insets.right - offset - 1; |
| 98 |
1
|
return new Point(x, dockSize.height - insets.bottom - 1); |
| 99 |
|
} |
| 100 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
4
|
@RunsInCurrentThread... |
| 102 |
|
private boolean isHorizontal(JToolBar toolBar) { |
| 103 |
4
|
return toolBar.getOrientation() == HORIZONTAL; |
| 104 |
|
} |
| 105 |
|
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 106 |
4
|
private void validate(String constraint) {... |
| 107 |
4
|
for (String validConstraint : VALID_CONSTRAINTS) |
| 108 |
4
|
if (validConstraint.equals(constraint)) return; |
| 109 |
0
|
throw invalidConstraint(constraint); |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
0
|
private IllegalArgumentException invalidConstraint(String constraint) {... |
| 113 |
0
|
throw new IllegalArgumentException( |
| 114 |
|
concat(quote(constraint), " is not a valid constraint. Valid constraints are ", format(VALID_CONSTRAINTS))); |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 117 |
2
|
private int verticalDockingYCoordinate(int dockHeight, Insets insets, int offset) {... |
| 118 |
2
|
int y = dockHeight / 2; |
| 119 |
|
|
| 120 |
2
|
if (y < insets.top + offset) y = insets.top + offset; |
| 121 |
2
|
return y; |
| 122 |
|
} |
| 123 |
|
} |