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
7   51   5   1.4
0   23   0.71   5
5     1  
1    
 
  FocusMonitor       Line # 28 7 0% 5 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Feb 23, 2008
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5    * 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 is distributed on
10    * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11    * specific language governing permissions and limitations under the License.
12    *
13    * Copyright @2008-2010 the original author or authors.
14    */
15    package org.fest.swing.core;
16   
17    import static org.fest.swing.core.FocusOwnerFinder.focusOwner;
18   
19    import java.awt.Component;
20    import java.awt.event.FocusAdapter;
21    import java.awt.event.FocusEvent;
22   
23    /**
24    * Understands monitoring when a <code>{@link Component}</code> gets keyboard focus.
25    *
26    * @author Alex Ruiz
27    */
 
28    final class FocusMonitor extends FocusAdapter {
29   
30    private volatile boolean focused = false;
31   
 
32  17 toggle static FocusMonitor attachTo(Component c) {
33  17 FocusMonitor monitor = new FocusMonitor(c);
34  17 c.addFocusListener(monitor);
35  17 return monitor;
36    }
37   
 
38  17 toggle private FocusMonitor(Component c) {
39  17 focused = focusOwner() == c;
40    }
41   
 
42  13 toggle @Override public void focusGained(FocusEvent e) {
43  13 focused = true;
44    }
45   
 
46  3 toggle @Override public void focusLost(FocusEvent e) {
47  3 focused = false;
48    }
49   
 
50  18 toggle boolean hasFocus() { return focused; }
51    }