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
35   181   16   2.5
4   86   0.46   14
14     1.14  
1    
 
  Windows       Line # 33 35 0% 16 0 100% 1.0
 
No Tests
 
1    /*
2    * Created on Oct 8, 2007
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 @2007-2010 the original author or authors.
15    */
16    package org.fest.swing.monitor;
17   
18    import java.awt.Component;
19    import java.awt.Window;
20    import java.util.*;
21   
22    import net.jcip.annotations.GuardedBy;
23    import net.jcip.annotations.ThreadSafe;
24   
25    import org.fest.swing.annotation.RunsInCurrentThread;
26   
27    /**
28    * Understands the information collected by the monitors in this package.
29    *
30    * @author Alex Ruiz
31    */
32    @ThreadSafe
 
33    class Windows {
34   
35    static int WINDOW_READY_DELAY = 10000;
36   
37    /** <code>{@link Window#isShowing() isShowing}</code> is true but are not yet ready for input. */
38    @GuardedBy("lock") final Map<Window, TimerTask> pending = new WeakHashMap<Window, TimerTask>();
39   
40    /** Considered to be ready to use. */
41    @GuardedBy("lock") final Map<Window, Boolean> open = new WeakHashMap<Window, Boolean>();
42   
43    /** Have sent a <code>{@link java.awt.event.WindowEvent#WINDOW_CLOSED WINDOW_CLOSED}</code> event. */
44    @GuardedBy("lock") final Map<Window, Boolean> closed = new WeakHashMap<Window, Boolean>();
45   
46    /** Not visible. */
47    @GuardedBy("lock") final Map<Window, Boolean> hidden = new WeakHashMap<Window, Boolean>();
48   
49    private final Timer windowReadyTimer;
50   
51    private final Object lock = new Object();
52   
 
53  636 toggle Windows() {
54  636 windowReadyTimer = new Timer("Window Ready Timer", true);
55    }
56   
57    /**
58    * Creates a new <code>{@link WindowVisibilityMonitor}</code> and attaches it to the given
59    * <code>{@link Window}</code>.
60    * @param target the <code>Window</code> to attach the new monitor to.
61    */
 
62  1314 toggle void attachNewWindowVisibilityMonitor(Window target) {
63  1314 WindowVisibilityMonitor monitor = new WindowVisibilityMonitor(this);
64  1314 target.addWindowListener(monitor);
65  1314 target.addComponentListener(monitor);
66    }
67   
68    /**
69    * Marks the given window as "ready to use" and if not showing, as "hidden."
70    * @param w the given window.
71    */
 
72  24 toggle @RunsInCurrentThread
73    void markExisting(Window w) {
74  24 synchronized(lock) {
75  24 addWindowTo(w, open);
76  18 if (!w.isShowing()) addWindowTo(w, hidden);
77    }
78    }
79   
80    /**
81    * Marks the given window as "hidden."
82    * @param w the given window.
83    */
 
84  112 toggle void markAsHidden(Window w) {
85  112 synchronized(lock) {
86  112 addWindowTo(w, hidden);
87  112 removeWindowFrom(w, pending);
88    }
89    }
90   
91    /**
92    * Marks the given window as "showing."
93    * @param w the given window.
94    */
 
95  1550 toggle void markAsShowing(final Window w) {
96  1550 synchronized(lock) {
97  1550 TimerTask task = new TimerTask() {
 
98  134 toggle public void run() { markAsReady(w); }
99    };
100  1550 windowReadyTimer.schedule(new ProtectingTimerTask(task), WINDOW_READY_DELAY);
101  1550 pending.put(w, task);
102    }
103    }
104   
105    /**
106    * Marks the given window as "ready to receive OS-level event input."
107    * @param w the given window.
108    */
 
109  4503 toggle void markAsReady(Window w) {
110  4503 synchronized(lock) {
111  3661 if (!pending.containsKey(w)) return;
112  842 removeWindowFrom(w, closed, hidden, pending);
113  842 addWindowTo(w, open);
114    }
115    }
116   
117    /**
118    * Marks the given window as "closed."
119    * @param w the given window.
120    */
 
121  5073 toggle void markAsClosed(Window w) {
122  5073 synchronized(lock) {
123  5073 removeWindowFrom(w, open, hidden, pending);
124  5073 addWindowTo(w, closed);
125    }
126    }
127   
 
128  6069 toggle private void addWindowTo(Window w, Map<Window, Boolean> map) {
129  6069 map.put(w, true);
130    }
131   
 
132  6027 toggle private void removeWindowFrom(Window w, Map<?, ?>... maps) {
133  17857 for (Map<?, ?> map : maps) map.remove(w);
134    }
135   
136    /**
137    * Returns <code>true</code> if the given component is a closed window.
138    * @param c the given component.
139    * @return <code>true</code> if the given component is a closed window, <code>false</code> otherwise.
140    */
 
141  4143 toggle boolean isClosed(Component c) {
142  4143 synchronized(lock) {
143  4143 return closed.containsKey(c);
144    }
145    }
146   
147    /**
148    * Returns <code>true</code> if the given window is ready to receive OS-level event input.
149    * @param w the given window.
150    * @return <code>true</code> if the given window is ready to receive OS-level event input, <code>false</code>
151    * otherwise.
152    */
 
153  3774 toggle boolean isReady(Window w) {
154  3774 synchronized(lock) {
155  3774 return open.containsKey(w) && !hidden.containsKey(w);
156    }
157    }
158   
159    /**
160    * Returns <code>true</code> if the given window is hidden.
161    * @param w the given window.
162    * @return <code>true</code> if the given window is hidden, <code>false</code> otherwise.
163    */
 
164  2 toggle boolean isHidden(Window w) {
165  2 synchronized(lock) {
166  2 return hidden.containsKey(w);
167    }
168    }
169   
170    /**
171    * Returns <code>true</code> if the given window is showing but not ready to receive OS-level event input.
172    * @param w the given window.
173    * @return <code>true</code> if the given window is showing but not not ready to receive OS-level event input,
174    * <code>false</code> otherwise.
175    */
 
176  2690 toggle boolean isShowingButNotReady(Window w) {
177  2690 synchronized(lock) {
178  2690 return pending.containsKey(w);
179    }
180    }
181    }