Changeset 928


Ignore:
Timestamp:
10/17/12 10:50:44 (12 years ago)
Author:
fglaser
Message:
  • Title change hierarchy control added
  • JFCNameChangeListener renamed to JFCTitleChangeListener
  • JFCTitleChangeListener now additionaly listens on icon and position changes
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  
    142142     * @param component 
    143143     *            component that is searched for 
    144      * @return corresponding JFComponent instance; null if the compenent is not found 
     144     * @return corresponding JFComponent instance; null if the component is not found 
    145145     */ 
    146146    public static JFCComponent find(Component component) { 
     
    192192     */ 
    193193    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; 
    194201 
    195202    /** 
     
    303310    /** 
    304311     * <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> 
    305322     * Returns an XML representation of the components children. 
    306323     * </p> 
     
    363380     * </p> 
    364381     */ 
    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         
    366386        title = null; // reset title 
    367387 
     
    369389        if (accessibleContext != null) { 
    370390            title = accessibleContext.getAccessibleName(); 
     391            titleSource = JFCComponentTitleHierachy.ACCESSIBLE_NAME; 
    371392        } 
    372393        if (title == null) { 
    373394            title = icon; 
     395            titleSource = JFCComponentTitleHierachy.ICON; 
    374396        } 
    375397        if (title == null) { 
    376398            title = component.getName(); 
     399            titleSource = JFCComponentTitleHierachy.NAME; 
    377400        } 
    378401        if (title == null) { 
    379402            // use coordinates as last resort 
    380403            title = "Pos(" + component.getX() + "," + component.getY() + ")"; 
     404            titleSource = JFCComponentTitleHierachy.POS; 
    381405        } 
    382406    } 
  • trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/JFCTitleChangeListener.java

    r927 r928  
    2525/** 
    2626 * <p> 
    27  * Listener that listens on the name change of a component.      
     27 * Listener that listens on the name change of a component. 
    2828 * </p> 
     29 *  
    2930 * @author Fabian Glaser 
    3031 * @version 1.0 
    3132 */ 
    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          
     33public 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 
    5155        @Override 
    52         public void propertyChange(PropertyChangeEvent evt) { 
     56        public synchronized void propertyChange(PropertyChangeEvent evt) { 
    5357                String propertyName = evt.getPropertyName(); 
    5458                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")) { 
    5763                        AccessibleContext context = (AccessibleContext) evt.getSource(); 
    5864                        component = (Component) context.getAccessibleParent(); 
     65                        titleSource = JFCComponentTitleHierachy.ACCESSIBLE_NAME; 
    5966                } 
    60                  
    61                 if (propertyName.equals("name")){ 
     67 
     68                if (propertyName.equals("name")) { 
    6269                        component = (Component) evt.getSource(); 
     70                        titleSource = JFCComponentTitleHierachy.NAME; 
    6371                } 
    64                  
    65                 if (propertyName.equals("")){ 
    66                          
     72 
     73                if (propertyName.equals("icon")) { 
     74                        component = (Component) evt.getSource(); 
     75                        titleSource = JFCComponentTitleHierachy.ICON; 
    6776                } 
    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 { 
    72100                                throw new AssertionError("Referenced component is not known."); 
    73101                        } 
    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()); 
    81102                } 
    82103        } 
    83          
     104 
    84105} 
  • trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/Runner.java

    r927 r928  
    7878        Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(jfcWriter), 
    7979                                                        AWTEvent.WINDOW_EVENT_MASK); 
    80         JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(jfcWriter)); 
     80        JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(jfcWriter)); 
    8181        JFCComponent.addContainerListener(new JFCContainerListener(jfcWriter)); 
    8282 
     
    9595                Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(stdJfcWriter), 
    9696                        AWTEvent.WINDOW_EVENT_MASK); 
    97                 JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(stdJfcWriter)); 
     97                JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(stdJfcWriter)); 
    9898                JFCComponent.addContainerListener(new JFCContainerListener(stdJfcWriter)); 
    9999            } 
Note: See TracChangeset for help on using the changeset viewer.