source: trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/JFCWindowMonitor.java @ 927

Last change on this file since 927 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 2.5 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   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
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.jfcmonitor;
16
17import java.awt.AWTEvent;
18import java.awt.Window;
19import java.awt.event.AWTEventListener;
20import java.awt.event.WindowEvent;
21
22/**
23 * <p>
24 * An AWT event listener responsible to monitor the window creation and destruction.
25 * </p>
26 *
27 * @author Steffen Herbold
28 * @author Fabian Glaser
29 * @version 1.0
30 */
31public class JFCWindowMonitor implements AWTEventListener {
32         /**
33     * <p>
34     * Writer for logging events.
35     * </p>
36     */
37    final private JFCMonitorOutputWriter outputWriter; 
38       
39    /**
40     * <p>
41     * Constructor. Creates a new JFCWindowMonitor with a given {@link JFCMonitorOutputWriter}, where the
42     * monitored information is logged.
43     * </p>
44     *
45     * @param outputWriter
46     *            writer for the logged information
47     */
48    public JFCWindowMonitor(JFCMonitorOutputWriter outputWriter) {
49        this.outputWriter = outputWriter;
50    }
51       
52
53    /**
54     * <p>
55     * Adds all created windows (and their child components) to the GUI hierarchy maintained by
56     * {@link JFCComponent} and removes them if a window is destroyed.
57     * </p>
58     * </p>
59     *
60     * @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
61     */
62    @Override
63    public void eventDispatched(AWTEvent event) {
64        Window window;
65        switch (event.getID())
66        {
67            case WindowEvent.WINDOW_OPENED:
68                window = ((WindowEvent) event).getWindow();
69                JFCComponent.add(window);
70                JFCComponent jfcComponent = JFCComponent.find(window);
71                if (jfcComponent != null) {
72                    outputWriter.write(jfcComponent.getXML());
73                    outputWriter.write(jfcComponent.printChildren());
74                }
75                break;
76            default:
77                break;
78        }
79    }
80
81}
Note: See TracBrowser for help on using the repository browser.