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
9   62   5   9
8   22   0.56   1
1     5  
1    
5.3% of code in this file is excluded from these metrics.
 
  WindowAncestorFinder       Line # 34 9 5.3% 5 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.awt.AWT.invokerOf;
19   
20    import java.awt.Component;
21    import java.awt.Window;
22   
23    import javax.swing.MenuElement;
24   
25    import org.fest.swing.annotation.RunsInCurrentThread;
26    import org.fest.swing.hierarchy.ComponentHierarchy;
27    import org.fest.swing.hierarchy.ExistingHierarchy;
28   
29    /**
30    * Understands lookup of a component's <code>{@link java.awt.Window ancestor}</code>.
31    *
32    * @author Yvonne Wang
33    */
 
34    public final class WindowAncestorFinder {
35   
36    private static ComponentHierarchy hierarchy = new ExistingHierarchy();
37   
38    /**
39    * Similar to <code>{@link javax.swing.SwingUtilities#getWindowAncestor(Component)}</code>, but returns the
40    * <code>{@link Component}</code> itself if it is a <code>{@link Window}</code>, or the invoker's <code>Window</code>
41    * if on a pop-up.
42    * <p>
43    * <b>Note:</b> This method is <b>not</b> guaranteed to be executed in the event dispatch thread (EDT.) Clients are
44    * responsible for calling this method from the EDT.
45    * </p>
46    * @param c the <code>Component</code> to get the <code>Window</code> ancestor of.
47    * @return the <code>Window</code> ancestor of the given <code>Component</code>, the <code>Component</code> itself if
48    * it is a <code>Window</code>, or the invoker's <code>Window</code> if on a pop-up.
49    */
 
50  1802 toggle @RunsInCurrentThread
51    public static Window windowAncestorOf(Component c) {
52  2 if (c == null) return null;
53  366 if (c instanceof Window) return (Window) c;
54  1434 if (c instanceof MenuElement) {
55  24 Component invoker = invokerOf(c);
56  11 if (invoker != null) return windowAncestorOf(invoker);
57    }
58  1423 return windowAncestorOf(hierarchy.parentOf(c));
59    }
60   
 
61    toggle private WindowAncestorFinder() {}
62    }