source: trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/JFCNameChangeListener.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.Component;
18import java.beans.PropertyChangeEvent;
19import java.beans.PropertyChangeListener;
20
21import javax.accessibility.AccessibleContext;
22
23import de.ugoe.cs.util.StringTools;
24
25/**
26 * <p>
27 * Listener that listens on the name change of a component.     
28 * </p>
29 * @author Fabian Glaser
30 * @version 1.0
31 */
32public class JFCNameChangeListener implements PropertyChangeListener {
33         /**
34     * <p>
35     * Writer for logging events.
36     * </p>
37     */
38    final private JFCMonitorOutputWriter outputWriter;
39   
40    /**
41     * <p>
42     * Constructor. Creates a new JFCNameChangeListener with a given
43     * {@link JFCMonitorOutputWriter}. 
44     * </p>
45     * @param outputWriter
46     */
47    public JFCNameChangeListener(JFCMonitorOutputWriter outputWriter){
48        this.outputWriter = outputWriter;
49    }
50       
51        @Override
52        public void propertyChange(PropertyChangeEvent evt) {
53                String propertyName = evt.getPropertyName();
54                Component component = null;
55               
56                if (propertyName.equals("AccessibleName")){
57                        AccessibleContext context = (AccessibleContext) evt.getSource();
58                        component = (Component) context.getAccessibleParent();
59                }
60               
61                if (propertyName.equals("name")){
62                        component = (Component) evt.getSource();
63                }
64               
65                if (propertyName.equals("")){
66                       
67                }
68               
69                if (component != null){
70                        if (!JFCComponent.isKnown(component)){
71                                System.err.println("Referenced component is not known");
72                                throw new AssertionError("Referenced component is not known.");
73                        }
74                        StringBuilder builder = new StringBuilder();
75                        builder.append("<componentNameChange hash=\"");
76                        builder.append(Integer.toHexString(component.hashCode()));
77                        builder.append("\" newName=\"" + evt.getNewValue());
78                        builder.append("\" source=\"" + propertyName);
79                        builder.append("\" />" + StringTools.ENDLINE);
80                        outputWriter.write(builder.toString());
81                }
82        }
83       
84}
Note: See TracBrowser for help on using the repository browser.