Changeset 928 for trunk/autoquest-jfcmonitor/src/main/java/de/ugoe
- Timestamp:
- 10/17/12 10:50:44 (12 years ago)
- Location:
- trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor
- Files:
-
- 1 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/JFCComponent.java
r927 r928 142 142 * @param component 143 143 * component that is searched for 144 * @return corresponding JFComponent instance; null if the comp enent is not found144 * @return corresponding JFComponent instance; null if the component is not found 145 145 */ 146 146 public static JFCComponent find(Component component) { … … 192 192 */ 193 193 private String title = null; 194 195 /** 196 * <p> 197 * Helper attribute that encodes the source of the title. 198 * </p> 199 */ 200 private int titleSource = JFCComponentTitleHierachy.SOURCE_NOT_KNOWN; 194 201 195 202 /** … … 303 310 /** 304 311 * <p> 312 * Returns an integer that encodes the source of the title. 313 * </p> 314 * @return int 315 */ 316 public int getTitleSource(){ 317 return titleSource; 318 } 319 320 /** 321 * <p> 305 322 * Returns an XML representation of the components children. 306 323 * </p> … … 363 380 * </p> 364 381 */ 365 private void setTitle() { 382 public void setTitle() { 383 // Note that JFCComponentTitleHierarchy depends on this method. So any changes made 384 // here should be reflected in JFCComponentTitleHierarchy. 385 366 386 title = null; // reset title 367 387 … … 369 389 if (accessibleContext != null) { 370 390 title = accessibleContext.getAccessibleName(); 391 titleSource = JFCComponentTitleHierachy.ACCESSIBLE_NAME; 371 392 } 372 393 if (title == null) { 373 394 title = icon; 395 titleSource = JFCComponentTitleHierachy.ICON; 374 396 } 375 397 if (title == null) { 376 398 title = component.getName(); 399 titleSource = JFCComponentTitleHierachy.NAME; 377 400 } 378 401 if (title == null) { 379 402 // use coordinates as last resort 380 403 title = "Pos(" + component.getX() + "," + component.getY() + ")"; 404 titleSource = JFCComponentTitleHierachy.POS; 381 405 } 382 406 } -
trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/JFCTitleChangeListener.java
r927 r928 25 25 /** 26 26 * <p> 27 * Listener that listens on the name change of a component. 27 * Listener that listens on the name change of a component. 28 28 * </p> 29 * 29 30 * @author Fabian Glaser 30 31 * @version 1.0 31 32 */ 32 public 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 33 public class JFCTitleChangeListener implements PropertyChangeListener { 34 /** 35 * <p> 36 * Writer for logging events. 37 * </p> 38 */ 39 final private JFCMonitorOutputWriter outputWriter; 40 41 final private boolean CHECK_HIERARCHY = true; 42 43 /** 44 * <p> 45 * Constructor. Creates a new JFCNameChangeListener with a given 46 * {@link JFCMonitorOutputWriter}. 47 * </p> 48 * 49 * @param outputWriter 50 */ 51 public JFCTitleChangeListener(JFCMonitorOutputWriter outputWriter) { 52 this.outputWriter = outputWriter; 53 } 54 51 55 @Override 52 public void propertyChange(PropertyChangeEvent evt) {56 public synchronized void propertyChange(PropertyChangeEvent evt) { 53 57 String propertyName = evt.getPropertyName(); 54 58 Component component = null; 55 56 if (propertyName.equals("AccessibleName")){ 59 int titleSource = JFCComponentTitleHierachy.SOURCE_NOT_KNOWN; 60 61 // Set source component and title source 62 if (propertyName.equals("AccessibleName")) { 57 63 AccessibleContext context = (AccessibleContext) evt.getSource(); 58 64 component = (Component) context.getAccessibleParent(); 65 titleSource = JFCComponentTitleHierachy.ACCESSIBLE_NAME; 59 66 } 60 61 if (propertyName.equals("name")) {67 68 if (propertyName.equals("name")) { 62 69 component = (Component) evt.getSource(); 70 titleSource = JFCComponentTitleHierachy.NAME; 63 71 } 64 65 if (propertyName.equals("")){ 66 72 73 if (propertyName.equals("icon")) { 74 component = (Component) evt.getSource(); 75 titleSource = JFCComponentTitleHierachy.ICON; 67 76 } 68 69 if (component != null){ 70 if (!JFCComponent.isKnown(component)){ 71 System.err.println("Referenced component is not known"); 77 78 if (propertyName.equals("x") || propertyName.equals("y")) { 79 component = (Component) evt.getSource(); 80 titleSource = JFCComponentTitleHierachy.POS; 81 } 82 83 if (component != null) { 84 JFCComponent jfcComponent = JFCComponent.find(component); 85 if (jfcComponent != null) { 86 int oldTitleSource = jfcComponent.getTitleSource(); 87 Object newTitle = evt.getNewValue(); 88 // We only print the name change message if the new title is as 89 // least as informative as the initial title 90 if ((!CHECK_HIERARCHY || oldTitleSource <= titleSource)) { 91 StringBuilder builder = new StringBuilder(); 92 builder.append("<componentNameChange hash=\""); 93 builder.append(Integer.toHexString(component.hashCode())); 94 builder.append("\" newName=\"" + newTitle); 95 builder.append("\" source=\"" + propertyName); 96 builder.append("\" />" + StringTools.ENDLINE); 97 outputWriter.write(builder.toString()); 98 } 99 } else { 72 100 throw new AssertionError("Referenced component is not known."); 73 101 } 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 102 } 82 103 } 83 104 84 105 } -
trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/Runner.java
r927 r928 78 78 Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(jfcWriter), 79 79 AWTEvent.WINDOW_EVENT_MASK); 80 JFCComponent.addPropertyChangeListener(new JFC NameChangeListener(jfcWriter));80 JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(jfcWriter)); 81 81 JFCComponent.addContainerListener(new JFCContainerListener(jfcWriter)); 82 82 … … 95 95 Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(stdJfcWriter), 96 96 AWTEvent.WINDOW_EVENT_MASK); 97 JFCComponent.addPropertyChangeListener(new JFC NameChangeListener(stdJfcWriter));97 JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(stdJfcWriter)); 98 98 JFCComponent.addContainerListener(new JFCContainerListener(stdJfcWriter)); 99 99 }
Note: See TracChangeset
for help on using the changeset viewer.