1 |
|
---|
2 | package de.ugoe.cs.autoquest.jfcmonitor;
|
---|
3 |
|
---|
4 | import java.awt.AWTEvent;
|
---|
5 | import java.awt.Window;
|
---|
6 | import java.awt.event.AWTEventListener;
|
---|
7 | import 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 | */
|
---|
18 | public 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 | } |
---|