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
16   138   9   1.78
0   54   0.56   9
9     1  
1    
 
  JScrollBarLocation       Line # 35 16 0% 9 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Feb 2, 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 java.awt.Adjustable.HORIZONTAL;
19    import static java.awt.Adjustable.VERTICAL;
20   
21    import java.awt.Point;
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import javax.swing.JScrollBar;
26   
27    import org.fest.swing.annotation.RunsInCurrentThread;
28   
29    /**
30    * Understands a location in a <code>{@link JScrollBar}</code>.
31    *
32    * @author Yvonne Wang
33    * @author Alex Ruiz
34    */
 
35    public final class JScrollBarLocation {
36    // TODO Test horizontal scroll bar
37   
38    private static final int BLOCK_OFFSET = 4;
39   
40    private static final Map<Integer, JScrollBarLocationStrategy> LOCATIONS = new HashMap<Integer, JScrollBarLocationStrategy>();
41   
 
42  30 toggle static {
43  30 LOCATIONS.put(HORIZONTAL, new HorizontalJScrollBarLocation());
44  30 LOCATIONS.put(VERTICAL, new VerticalJScrollBarLocation());
45    }
46   
47    /**
48    * Returns the location where to move the mouse pointer to scroll to the given position.
49    * <p>
50    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
51    * responsible for calling this method from the EDT.
52    * </p>
53    * @param scrollBar the target <code>JScrollBar</code>.
54    * @param position the position to scroll to.
55    * @return the location where to move the mouse pointer to scroll to the given position.
56    */
 
57  8 toggle @RunsInCurrentThread
58    public Point thumbLocation(JScrollBar scrollBar, int position) {
59  8 double fraction = (double) position / maximumMinusMinimum(scrollBar);
60  8 return locationStrategyFor(scrollBar).thumbLocation(scrollBar, fraction);
61    }
62   
 
63  8 toggle @RunsInCurrentThread
64    private int maximumMinusMinimum(JScrollBar scrollBar) {
65  8 return scrollBar.getMaximum() - scrollBar.getMinimum();
66    }
67   
68    /**
69    * Returns the location where to move the mouse pointer to scroll one block up (or right.)
70    * <p>
71    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
72    * responsible for calling this method from the EDT.
73    * </p>
74    * @param scrollBar the target <code>JScrollBar</code>.
75    * @return the location where to move the mouse pointer to scroll one block up (or right.)
76    */
 
77  8 toggle @RunsInCurrentThread
78    public Point blockLocationToScrollUp(JScrollBar scrollBar) {
79  8 Point p = unitLocationToScrollUp(scrollBar);
80  8 int offset = BLOCK_OFFSET;
81  8 return blockLocation(scrollBar, p, offset);
82    }
83   
84    /**
85    * Returns the location where to move the mouse pointer to scroll one block down (or left.)
86    * <p>
87    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
88    * responsible for calling this method from the EDT.
89    * </p>
90    * @param scrollBar the target <code>JScrollBar</code>.
91    * @return the location where to move the mouse pointer to scroll one block down (or left.)
92    */
 
93  8 toggle @RunsInCurrentThread
94    public Point blockLocationToScrollDown(JScrollBar scrollBar) {
95  8 Point p = unitLocationToScrollDown(scrollBar);
96  8 int offset = -BLOCK_OFFSET;
97  8 return blockLocation(scrollBar, p, offset);
98    }
99   
 
100  16 toggle @RunsInCurrentThread
101    private Point blockLocation(JScrollBar scrollBar, Point unitLocation, int offset) {
102  16 return locationStrategyFor(scrollBar).blockLocation(scrollBar, unitLocation, offset);
103    }
104   
105    /**
106    * Returns the location where to move the mouse pointer to scroll one unit up (or right.)
107    * <p>
108    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
109    * responsible for calling this method from the EDT.
110    * </p>
111    * @param scrollBar the target <code>JScrollBar</code>.
112    * @return the location where to move the mouse pointer to scroll one unit up (or right.)
113    */
 
114  8 toggle @RunsInCurrentThread
115    public Point unitLocationToScrollUp(JScrollBar scrollBar) {
116  8 int arrow = locationStrategyFor(scrollBar).arrow(scrollBar);
117  8 return new Point(arrow / 2, arrow / 2);
118    }
119   
120    /**
121    * Returns the location where to move the mouse pointer to scroll one unit down (or left.)
122    * <p>
123    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
124    * responsible for calling this method from the EDT.
125    * </p>
126    * @param scrollBar the target <code>JScrollBar</code>.
127    * @return the location where to move the mouse pointer to scroll one unit down (or left.)
128    */
 
129  8 toggle @RunsInCurrentThread
130    public Point unitLocationToScrollDown(JScrollBar scrollBar) {
131  8 return locationStrategyFor(scrollBar).unitLocationToScrollDown(scrollBar);
132    }
133   
 
134  40 toggle @RunsInCurrentThread
135    private JScrollBarLocationStrategy locationStrategyFor(JScrollBar scrollBar) {
136  40 return LOCATIONS.get(scrollBar.getOrientation());
137    }
138    }