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
15   54   5   15
8   26   0.33   1
1     5  
1    
 
  DisposedWindowMonitor       Line # 32 15 0% 5 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Jun 24, 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.WindowEvent.WINDOW_CLOSED;
19    import static java.awt.event.WindowEvent.WINDOW_CLOSING;
20   
21    import java.awt.AWTEvent;
22    import java.awt.Window;
23    import java.awt.event.WindowEvent;
24    import java.util.Map;
25    import java.util.WeakHashMap;
26   
27    /**
28    * Verifies that a notification of the disposal of a <code>{@link Window}</code> is not duplicated.
29    *
30    * @author Alex Ruiz
31    */
 
32    class DisposedWindowMonitor {
33   
34    final Map<Window, Boolean> disposedWindows = new WeakHashMap<Window, Boolean>();
35   
36    // We want to ignore consecutive event indicating window disposal; it needs to be an intervening SHOWN/OPEN before
37    // we're interested again.
 
38  5210 toggle boolean isDuplicateDispose(AWTEvent event) {
39  5206 if (!(event instanceof WindowEvent)) return false;
40  4 WindowEvent windowEvent = (WindowEvent) event;
41  4 int eventId = windowEvent.getID();
42  1 if (eventId == WINDOW_CLOSING) return false;
43  3 if (eventId == WINDOW_CLOSED) {
44  2 Window w = windowEvent.getWindow();
45  1 if (disposedWindows.containsKey(w)) return true;
46  1 disposedWindows.put(w, true);
47    // execute(addComponentListenerTask(w, new DisposalMonitor(disposedWindows)));
48  1 w.addComponentListener(new DisposalMonitor(disposedWindows));
49  1 return false;
50    }
51  1 disposedWindows.remove(windowEvent.getWindow());
52  1 return false;
53    }
54    }