source: trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/JFCWindowMonitor.java @ 853

Last change on this file since 853 was 853, checked in by fglaser, 12 years ago
  • JFCMonitor now logs component class parents
  • Renamed WindowMonitor? to JFCWindowMonitor
  • Property svn:mime-type set to text/plain
File size: 1.9 KB
Line 
1
2package de.ugoe.cs.quest.jfcmonitor;
3
4import java.awt.AWTEvent;
5import java.awt.Window;
6import java.awt.event.AWTEventListener;
7import java.awt.event.WindowEvent;
8
9/**
10 * <p>
11 * An AWT event listener responsible to monitor the window creation and destruction.
12 * </p>
13 *
14 * @author Steffen Herbold
15 * @author Fabian Glaser
16 * @version 1.0
17 */
18public class JFCWindowMonitor implements AWTEventListener {
19         /**
20     * <p>
21     * Writer for logging events.
22     * </p>
23     */
24    final private JFCMonitorOutputWriter outputWriter; 
25       
26    /**
27     * <p>
28     * Constructor. Creates a new JFCWindowMonitor with a given {@link JFCMonitorOutputWriter}, where the
29     * monitored information is logged.
30     * </p>
31     *
32     * @param outputWriter
33     *            writer for the logged information
34     */
35    public JFCWindowMonitor(JFCMonitorOutputWriter outputWriter) {
36        this.outputWriter = outputWriter;
37    }
38       
39
40    /**
41     * <p>
42     * Adds all created windows (and their child components) to the GUI hierarchy maintained by
43     * {@link JFCComponent} and removes them if a window is destroyed.
44     * </p>
45     * </p>
46     *
47     * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
48     */
49    @Override
50    public void eventDispatched(AWTEvent event) {
51        Window window;
52        switch (event.getID())
53        {
54            case WindowEvent.WINDOW_OPENED:
55                window = ((WindowEvent) event).getWindow();
56                JFCComponent.add(window);
57                JFCComponent jfcComponent = JFCComponent.find(window);
58                if (jfcComponent != null) {
59                    outputWriter.write(jfcComponent.getXML());
60                    outputWriter.write(jfcComponent.printChildren());
61                }
62                break;
63            default:
64                break;
65        }
66    }
67
68}
Note: See TracBrowser for help on using the repository browser.