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
18   73   11   3.6
10   40   0.61   5
5     2.2  
1    
 
  TransientWindowListener       Line # 31 18 0% 11 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Oct 31, 2007
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 @2007-2010 the original author or authors.
14    */
15    package org.fest.swing.hierarchy;
16   
17    import static javax.swing.SwingUtilities.invokeLater;
18    import static org.fest.swing.util.AWTEvents.*;
19   
20    import java.awt.AWTEvent;
21    import java.awt.Window;
22    import java.awt.event.AWTEventListener;
23   
24    import org.fest.swing.annotation.RunsInEDT;
25   
26    /**
27    * Understands automatic filtering of auto-generated Swing dialogs.
28    *
29    * @author Alex Ruiz
30    */
 
31    public final class TransientWindowListener implements AWTEventListener {
32   
33    private final WindowFilter filter;
34   
 
35  1610 toggle TransientWindowListener(WindowFilter filter) {
36  1610 this.filter = filter;
37    }
38   
39    /** {@inheritDoc} */
 
40  121376 toggle @RunsInEDT
41    public void eventDispatched(AWTEvent e) {
42  121376 if (windowOpened(e) || windowShown(e)) {
43  8013 filter(sourceOf(e));
44  8013 return;
45    }
46  113363 if (windowClosed(e)) {
47  17852 final Window w = sourceOf(e);
48    // *Any* window disposal should result in the window being ignored, at least until it is again displayed.
49  4813 if (filter.isIgnored(w)) return;
50  13039 filter.implicitlyIgnore(w);
51    // Filter this window only *after* any handlers for this event have finished.
52  13039 invokeLater(new IgnoreWindowTask(w, filter));
53    }
54    }
55   
 
56  25865 toggle private Window sourceOf(AWTEvent e) {
57  25865 return (Window) e.getSource();
58    }
59   
 
60  8013 toggle private void filter(Window w) {
61  8013 if (filter.isImplicitlyIgnored(w)) {
62  2 filter.recognize(w);
63  2 return;
64    }
65    // Catch new sub-windows of filtered windows (i.e. dialogs generated by a test harness UI).
66  8011 filterIfParentIsFiltered(w);
67    }
68   
 
69  8011 toggle private void filterIfParentIsFiltered(Window w) {
70  8009 if (!filter.isIgnored(w.getParent())) return;
71  2 filter.ignore(w);
72    }
73    }