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 |
|
---|
15 | package de.ugoe.cs.autoquest.jfcmonitor;
|
---|
16 |
|
---|
17 | import java.awt.Component;
|
---|
18 | import java.awt.event.ContainerEvent;
|
---|
19 | import java.awt.event.ContainerListener;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * <p>
|
---|
23 | * A ComponentListener responsible for monitoring adding and removing of GUI components
|
---|
24 | * </p>
|
---|
25 | *
|
---|
26 | * @author Fabian Glaser
|
---|
27 | * @version 1.0
|
---|
28 | */
|
---|
29 | public class JFCContainerListener implements ContainerListener {
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * Writer for logging events.
|
---|
33 | * </p>
|
---|
34 | */
|
---|
35 | final private JFCMonitorOutputWriter outputWriter;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * <p>
|
---|
39 | * Constructor. Creates a new JFCContainerListener with a given {@link JFCMonitorOutputWriter}, where the
|
---|
40 | * monitored information is logged.
|
---|
41 | * </p>
|
---|
42 | *
|
---|
43 | * @param outputWriter
|
---|
44 | * writer for the logged information
|
---|
45 | */
|
---|
46 | public JFCContainerListener(JFCMonitorOutputWriter outputWriter) {
|
---|
47 | this.outputWriter = outputWriter;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void componentAdded(ContainerEvent e) {
|
---|
52 | Component src = e.getChild();
|
---|
53 | if (!JFCComponent.isKnown(src)){
|
---|
54 | JFCComponent.add(src);
|
---|
55 | JFCComponent jfcComponent = JFCComponent.find(src);
|
---|
56 | outputWriter.write(jfcComponent.getXML());
|
---|
57 | outputWriter.write(jfcComponent.printChildren());
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public void componentRemoved(ContainerEvent e) {
|
---|
63 | //System.out.println("Component has been removed...");
|
---|
64 | }
|
---|
65 |
|
---|
66 | } |
---|