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
25   138   11   2.5
2   67   0.44   5
10     1.1  
2    
 
  WindowMonitor       Line # 32 24 0% 10 0 100% 1.0
  WindowMonitor.SingletonLazyLoader       Line # 131 1 0% 1 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 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.monitor;
16   
17    import static org.fest.swing.edt.GuiActionRunner.execute;
18   
19    import java.awt.*;
20    import java.util.Collection;
21   
22    import org.fest.swing.annotation.RunsInCurrentThread;
23    import org.fest.swing.annotation.RunsInEDT;
24    import org.fest.swing.edt.GuiQuery;
25    import org.fest.util.VisibleForTesting;
26   
27    /**
28    * Understands a monitor that keeps track of all known root windows (showing, hidden, closed.)
29    *
30    * @author Alex Ruiz
31    */
 
32    public class WindowMonitor {
33   
34    private final Context context;
35    private final ContextMonitor contextMonitor;
36    private final Windows windows;
37    private final WindowStatus windowStatus;
38    private final WindowAvailabilityMonitor windowAvailabilityMonitor;
39   
40    /**
41    * Create an instance of WindowTracker which will track all windows coming and going on the current and subsequent
42    * <code>AppContext</code>s.
43    * <p>
44    * <strong>WARNING:</strong> if an applet loads this class, it will only ever see stuff in its own
45    * <code>AppContext</code>.
46    * </p>
47    * @param toolkit the <code>Toolkit</code> to use.
48    */
 
49  621 toggle @RunsInCurrentThread
50    WindowMonitor(Toolkit toolkit) {
51  621 this(toolkit, new Context(toolkit), new WindowStatus(new Windows()));
52    }
53   
 
54  627 toggle @VisibleForTesting
55    @RunsInCurrentThread
56    WindowMonitor(Toolkit toolkit, Context context, WindowStatus windowStatus) {
57  627 this.context = context;
58  627 this.windowStatus = windowStatus;
59  627 windows = windowStatus.windows();
60  627 contextMonitor = new ContextMonitor(context, windows);
61  627 contextMonitor.attachTo(toolkit);
62  627 windowAvailabilityMonitor = new WindowAvailabilityMonitor(windows);
63  627 windowAvailabilityMonitor.attachTo(toolkit);
64  627 populateExistingWindows();
65    }
66   
 
67  627 toggle private void populateExistingWindows() {
68  27 for (Frame f : Frame.getFrames()) examine(f);
69    }
70   
 
71  29 toggle @RunsInCurrentThread
72    private void examine(Window w) {
73  29 windows.attachNewWindowVisibilityMonitor(w);
74  2 for (Window owned : w.getOwnedWindows()) examine(owned);
75  29 windows.markExisting(w);
76  29 context.addContextFor(w);
77    }
78   
79    /**
80    * Returns whether the window is ready to receive OS-level event input. A window's "isShowing" flag may be set
81    * <code>true</code> before the <code>WINDOW_OPENED</code> event is generated, and even after the
82    * <code>WINDOW_OPENED</code> is sent the window peer is not guaranteed to be ready.
83    * @param w the given window.
84    * @return whether the window is ready to receive OS-level event input.
85    */
 
86  3772 toggle public boolean isWindowReady(Window w) {
87  1084 if (windows.isReady(w)) return true;
88  2688 windowStatus.checkIfReady(w);
89  2688 return false;
90    }
91   
92    /**
93    * Returns the event queue corresponding to the given component. In most cases, this is the same as
94    * <code>Component.getToolkit().getSystemEventQueue()</code>, but in the case of applets will bypass the
95    * <code>AppContext</code> and provide the real event queue.
96    * @param c the given component.
97    * @return the event queue corresponding to the given component.
98    */
 
99  7 toggle public EventQueue eventQueueFor(Component c) {
100  7 return context.eventQueueFor(c);
101    }
102   
103    /**
104    * Returns all known event queues.
105    * @return all known event queues.
106    */
 
107  1851 toggle public Collection<EventQueue> allEventQueues() {
108  1851 return context.allEventQueues();
109    }
110   
111    /**
112    * Return all available root windows. A root window is one that has a null parent. Nominally this means a list similar
113    * to that returned by <code>{@link Frame#getFrames() Frame.getFrames()}</code>, but in the case of an
114    * <code>{@link java.applet.Applet}</code> may return a few dialogs as well.
115    * @return all available root windows.
116    */
 
117  13531 toggle public Collection<Window> rootWindows() {
118  13531 return context.rootWindows();
119    }
120   
121    /**
122    * Returns the singleton instance of this class.
123    * @return the singleton instance of this class.
124    */
 
125  1203 toggle @RunsInEDT
126    public static WindowMonitor instance() {
127  1203 return SingletonLazyLoader.INSTANCE;
128    }
129   
130    @RunsInEDT
 
131    private static class SingletonLazyLoader {
132    static final WindowMonitor INSTANCE = execute(new GuiQuery<WindowMonitor>() {
 
133  621 toggle protected WindowMonitor executeInEDT() throws Throwable {
134  621 return new WindowMonitor(Toolkit.getDefaultToolkit());
135    }
136    });
137    }
138    }