Clover Coverage Report - FEST Swing 1.2
Coverage timestamp: Tue Jun 1 2010 15:19:25 PDT
../../../../img/srcFileCovDistChart7.png 95% of files have more coverage
59   156   30   3.47
22   107   0.51   17
17     1.76  
1    
 
  MouseInfo       Line # 33 59 0% 30 38 61.2% 0.6122449
 
No Tests
 
1    /*
2    * Created on Mar 28, 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.input;
17   
18    import static java.awt.event.InputEvent.*;
19    import static java.awt.event.MouseEvent.*;
20    import static org.fest.swing.query.ComponentShowingQuery.isShowing;
21   
22    import java.awt.Component;
23    import java.awt.Point;
24    import java.awt.event.MouseEvent;
25    import java.lang.ref.WeakReference;
26    import java.util.Stack;
27   
28    /**
29    * Understands a description mouse-related operations.
30    *
31    * @author Alex Ruiz
32    */
 
33    class MouseInfo {
34   
35    static final int BUTTON_MASK = BUTTON1_MASK | BUTTON2_MASK | BUTTON3_MASK;
36   
37    /** Current mouse position, in component coordinates. */
38    private Point location = new Point(0, 0);
39   
40    /** Current mouse position, in screen coordinates. */
41    private Point locationOnScreen = new Point(0, 0);
42   
43    private final Stack<WeakReference<Component>> componentStack = new Stack<WeakReference<Component>>();
44    private final Stack<Point> locationStack = new Stack<Point>();
45    private final Stack<Point> screenLocationStack = new Stack<Point>();
46   
47    private int buttons;
48    private int modifiers;
49    private int clickCount;
50   
 
51  0 toggle void clear() {
52  0 buttons = modifiers = clickCount = 0;
53  0 componentStack.clear();
54  0 locationStack.clear();
55  0 screenLocationStack.clear();
56    }
57   
 
58  4353 toggle void update(MouseEvent event, Point eventScreenLocation) {
59    // When a button is released, only that button appears in the modifier mask
60  4353 clickCount(event.getClickCount());
61  4353 updateOnMousePressed(event);
62  4353 updateOnMouseReleased(event);
63  4353 updateOnMouseEntered(event, eventScreenLocation);
64  4353 updateOnMouseExited(event);
65  54 if (eventScreenLocation == null) return;
66  4299 Point where = event.getPoint();
67  4299 location = componentStack.empty() ? null : new Point(where);
68  4299 locationOnScreen.setLocation(eventScreenLocation);
69  4299 locationOnScreen.translate(where.x, where.y);
70    }
71   
 
72  4353 toggle private void updateOnMousePressed(MouseEvent event) {
73  3992 if (event.getID() != MOUSE_PRESSED) return;
74  361 int buttonUsed = buttonUsed(event);
75  361 buttons |= buttonUsed;
76  361 modifiers |= buttonUsed;
77    }
78   
 
79  4353 toggle private void updateOnMouseReleased(MouseEvent event) {
80  4033 if (event.getID() != MOUSE_RELEASED) return;
81  320 int buttonUsed = buttonUsed(event);
82  320 buttons &= ~buttonUsed;
83  320 modifiers &= ~buttonUsed;
84    }
85   
 
86  681 toggle private int buttonUsed(MouseEvent event) {
87  681 return event.getModifiers() & BUTTON_MASK;
88    }
89   
 
90  4353 toggle private void updateOnMouseEntered(MouseEvent event, Point eventScreenLocation) {
91  3266 if (event.getID() != MOUSE_ENTERED) return;
92  1087 componentStack.push(new WeakReference<Component>(event.getComponent()));
93  1087 Point eventPoint = event.getPoint();
94  1087 locationStack.push(eventPoint);
95  1087 screenLocationStack.push(eventScreenLocation != null ? eventScreenLocation : eventPoint);
96    }
97   
 
98  4353 toggle private void updateOnMouseExited(MouseEvent event) {
99  4059 if (event.getID() != MOUSE_EXITED || componentStack.empty()) return;
100  294 componentStack.pop();
101  294 locationStack.pop();
102  294 screenLocationStack.pop();
103    }
104   
 
105  0 toggle public Component component() {
106  0 if (componentStack.empty()) return null;
107  0 Component c = componentStack.peek().get();
108    // Make sure we don't return a component that has gone away.
109  0 if (c != null && isShowing(c)) return c;
110  0 componentStack.pop();
111  0 locationStack.pop();
112  0 screenLocationStack.pop();
113  0 c = component();
114  0 if (c != null) {
115  0 location = locationStack.peek();
116  0 locationOnScreen = screenLocationStack.peek();
117    }
118  0 return c;
119    }
120   
 
121  1611 toggle int buttons() {
122  1611 return buttons;
123    }
124   
 
125  0 toggle void buttons(int newButtons) {
126  0 buttons = newButtons;
127    }
128   
 
129  4353 toggle int modifiers() {
130  4353 return modifiers;
131    }
132   
 
133  4353 toggle void modifiers(int newModifiers) {
134  4353 modifiers = newModifiers;
135    }
136   
 
137  0 toggle int clickCount() {
138  0 return clickCount;
139    }
140   
 
141  4353 toggle void clickCount(int newClickCount) {
142  4353 clickCount = newClickCount;
143    }
144   
 
145  0 toggle Point location() {
146  0 return pointFrom(location);
147    }
148   
 
149  0 toggle Point locationOnScreen() {
150  0 return pointFrom(locationOnScreen);
151    }
152   
 
153  0 toggle private Point pointFrom(Point source) {
154  0 return source != null ? new Point(source) : null;
155    }
156    }