source: trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/WindowMonitor.java @ 851

Last change on this file since 851 was 851, checked in by fglaser, 12 years ago
  • JFCMonitor: Added new ContainerListener? that listens on component added and component removed events
  • small refactorings
  • 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, Fabian Glaser
15 * @version 1.0
16 */
17public class WindowMonitor implements AWTEventListener {
18         /**
19     * <p>
20     * Writer for logging events.
21     * </p>
22     */
23    final private JFCMonitorOutputWriter outputWriter; 
24       
25    /**
26     * <p>
27     * Constructor. Creates a new WindowMonitor with a given {@link JFCMonitorOutputWriter}, where the
28     * monitored information is logged.
29     * </p>
30     *
31     * @param outputWriter
32     *            writer for the logged information
33     */
34    public WindowMonitor(JFCMonitorOutputWriter outputWriter) {
35        this.outputWriter = outputWriter;
36    }
37       
38
39    /**
40     * <p>
41     * Adds all created windows (and their child components) to the GUI hierarchy maintained by
42     * {@link JFCComponent} and removes them if a window is destroyed.
43     * </p>
44     * </p>
45     *
46     * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
47     */
48    @Override
49    public void eventDispatched(AWTEvent event) {
50        Window window;
51        switch (event.getID())
52        {
53            case WindowEvent.WINDOW_OPENED:
54                window = ((WindowEvent) event).getWindow();
55                JFCComponent.add(window);
56                JFCComponent jfcComponent = JFCComponent.find(window);
57                if (jfcComponent != null) {
58                    outputWriter.write(jfcComponent.getXML());
59                    outputWriter.write(jfcComponent.printChildren());
60                }
61                break;
62            default:
63                break;
64        }
65    }
66
67}
Note: See TracBrowser for help on using the repository browser.