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
12   95   8   1.71
0   49   0.67   7
7     1.14  
1    
5% of code in this file is excluded from these metrics.
 
  FocusOwnerFinder       Line # 36 12 5% 8 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Mar 30, 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.core;
17   
18    import static org.fest.swing.edt.GuiActionRunner.execute;
19    import static org.fest.util.Collections.list;
20   
21    import java.awt.Component;
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import org.fest.swing.annotation.RunsInCurrentThread;
26    import org.fest.swing.annotation.RunsInEDT;
27    import org.fest.swing.edt.GuiQuery;
28    import org.fest.util.VisibleForTesting;
29   
30    /**
31    * Understands lookup of a <code>{@link Component}</code> owning the input focus.
32    *
33    * @author Yvonne Wang
34    * @author Alex Ruiz
35    */
 
36    public final class FocusOwnerFinder {
37   
38    private static final List<FocusOwnerFinderStrategy> STRATEGIES = new ArrayList<FocusOwnerFinderStrategy>();
39   
 
40  56 toggle static {
41  56 initializeStrategies();
42    }
43   
 
44  58 toggle @VisibleForTesting
45    static void initializeStrategies() {
46  58 replaceStrategiesWith(new ReflectionBasedFocusOwnerFinder(), new HierarchyBasedFocusOwnerFinder());
47    }
48   
 
49  60 toggle @VisibleForTesting
50    static void replaceStrategiesWith(FocusOwnerFinderStrategy...strategies) {
51  60 STRATEGIES.clear();
52  60 STRATEGIES.addAll(list(strategies));
53    }
54   
 
55  1 toggle @VisibleForTesting
56    static List<FocusOwnerFinderStrategy> strategies() {
57  1 return new ArrayList<FocusOwnerFinderStrategy>(STRATEGIES);
58    }
59   
60    /**
61    * Returns the focus owner. This method is executed in the event dispatch thread.
62    * @return the focus owner.
63    */
 
64  177 toggle @RunsInEDT
65    public static Component inEdtFocusOwner() {
66  177 return execute(new GuiQuery<Component>() {
 
67  177 toggle protected Component executeInEDT() {
68  177 return focusOwner();
69    }
70    });
71    }
72   
73    /**
74    * Returns the focus owner. <b>Note:</b> this method is <b>not</b> executed in the event dispatch thread. Callers are
75    * responsible for calling this method in the event dispatch thread.
76    * <p>
77    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
78    * responsible for calling this method from the EDT.
79    * </p>
80    * @return the focus owner.
81    */
 
82  300 toggle @RunsInCurrentThread
83    public static Component focusOwner() {
84  300 for (FocusOwnerFinderStrategy strategy : STRATEGIES) {
85  302 try {
86  302 return strategy.focusOwner();
87    } catch (Exception e) {
88  3 continue;
89    }
90    }
91  1 return null;
92    }
93   
 
94    toggle private FocusOwnerFinder() {}
95    }