Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart8.png 93% of files have more coverage
23   54   11   7.67
12   35   0.48   3
3     3.67  
1    
2.6% of code in this file is excluded from these metrics.
 
  HorizontalJSplitPaneDividerLocation       Line # 23 23 2.6% 11 8 78.9% 0.7894737
 
No Tests
 
1    /*
2    * Created on Nov 25, 2009
3    *
4    * Copyright @2009-2010 the original author or authors.
5    */
6    package org.fest.swing.driver;
7   
8    import static java.lang.Math.max;
9    import static java.lang.Math.min;
10   
11    import java.awt.Component;
12    import java.awt.Insets;
13   
14    import javax.swing.JSplitPane;
15    import org.fest.swing.annotation.RunsInCurrentThread;
16   
17    /**
18    * Understands calculation of a valid position of a horizontal <code>{@link JSplitPane}</code>'s divider, while
19    * respecting the minimum sizes of the right and left component inside the <code>JSplitPane</code>.
20    *
21    * @author Alex Ruiz
22    */
 
23    final class HorizontalJSplitPaneDividerLocation {
24   
 
25  5 toggle @RunsInCurrentThread
26    static int locationToMoveDividerToHorizontally(final JSplitPane splitPane, final int desiredLocation) {
27  5 int minimum = calculateMinimum(splitPane);
28  5 int maximum = calculateMaximum(splitPane);
29  2 if (maximum < minimum) minimum = maximum = 0;
30  5 return min(maximum, max(minimum, desiredLocation));
31    }
32   
 
33  5 toggle private static int calculateMinimum(JSplitPane splitPane) {
34  5 Component left = splitPane.getLeftComponent();
35  5 if (left == null || !left.isVisible()) return 0;
36  5 int minimum = left.getMinimumSize().width;
37  5 Insets insets = splitPane.getInsets();
38  5 if (insets != null) minimum += insets.left;
39  5 return minimum;
40    }
41   
 
42  5 toggle private static int calculateMaximum(JSplitPane splitPane) {
43  5 Component rightComponent = splitPane.getRightComponent();
44  5 if (splitPane.getLeftComponent() == null || rightComponent == null) return -1; // Don't allow dragging.
45  5 Insets insets = splitPane.getInsets();
46  5 int dividerSize = splitPane.getDividerSize();
47  5 int right = (insets != null) ? insets.right : 0;
48  5 int splitPaneWidth = splitPane.getSize().width;
49  5 if (!rightComponent.isVisible()) return max(0, splitPaneWidth - (dividerSize + right));
50  5 return max(0, splitPaneWidth - (dividerSize + right) - rightComponent.getMinimumSize().width);
51    }
52   
 
53    toggle private HorizontalJSplitPaneDividerLocation() {}
54    }