Changeset 851 for trunk/quest-jfcmonitor


Ignore:
Timestamp:
10/01/12 12:01:25 (12 years ago)
Author:
fglaser
Message:
  • JFCMonitor: Added new ContainerListener? that listens on component added and component removed events
  • small refactorings
Location:
trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor
Files:
1 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/JFCComponent.java

    r850 r851  
    44import java.awt.Component; 
    55import java.awt.Container; 
     6import java.awt.event.ContainerListener; 
    67import java.beans.PropertyChangeListener; 
    78import java.io.File; 
     
    4647    private static List<PropertyChangeListener> propertyChangeListeners =  
    4748        new ArrayList<PropertyChangeListener>(); 
     49     
     50    private static List<ContainerListener> containerListeners = 
     51                new ArrayList<ContainerListener>(); 
    4852 
    4953    /** 
     
    6064    } 
    6165     
    62     public static void addListener(PropertyChangeListener list){ 
     66    public static void addPropertyChangeListener(PropertyChangeListener list){ 
    6367        propertyChangeListeners.add(list); 
     68    } 
     69     
     70    public static void addContainerListener(ContainerListener list){ 
     71        containerListeners.add(list); 
     72    } 
     73     
     74    public static boolean isKnown(Component component){ 
     75        if (knownComponents.containsKey(component)) 
     76                return true; 
     77        return false; 
    6478    } 
    6579 
     
    190204 
    191205        if (component instanceof Container) { 
     206                for (ContainerListener listener: containerListeners) 
     207                        ((Container) component).addContainerListener(listener); 
     208                 
    192209            for (Component childComponent : ((Container) component).getComponents()) { 
    193210                add(childComponent, this); 
     
    223240        builder.append("  <component"); 
    224241        if (parent != null){ 
     242                if (!JFCComponent.isKnown(parent.component)) 
     243                        throw new AssertionError("Referenced parent is not known."); 
    225244                builder.append(" parent=\"" + Integer.toHexString(parent.component.hashCode()) + "\""); 
    226245        } 
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/JFCNameChangeListener.java

    r850 r851  
    88import java.beans.PropertyChangeListener; 
    99 
     10import javax.accessibility.AccessibleContext; 
     11 
    1012import de.ugoe.cs.util.StringTools; 
    1113 
     
    1416 * 
    1517 */ 
    16 public class NameChangeListener implements PropertyChangeListener { 
     18public class JFCNameChangeListener implements PropertyChangeListener { 
    1719         /** 
    1820     * <p> 
     
    2224    final private JFCMonitorOutputWriter outputWriter;   
    2325     
    24     public NameChangeListener(JFCMonitorOutputWriter outputWriter){ 
     26    public JFCNameChangeListener(JFCMonitorOutputWriter outputWriter){ 
    2527        this.outputWriter = outputWriter; 
    2628    } 
     
    2931        public void propertyChange(PropertyChangeEvent evt) { 
    3032                if (evt.getPropertyName().equals("AccessibleName")){ 
     33                        AccessibleContext context = (AccessibleContext) evt.getSource(); 
     34                        Component component = (Component) context.getAccessibleParent(); 
    3135                        StringBuilder builder = new StringBuilder(); 
    3236                        builder.append("<componentNameChange hash=\""); 
    33                         outputWriter.write(evt.getSource().toString()); 
    34                         if (JFCComponent.find((Component) evt.getSource()) == null) 
    35                                         System.err.println("Quelle nicht bekannt"); 
    36                         builder.append(Integer.toHexString(evt.getSource().hashCode())); 
     37                        if (!JFCComponent.isKnown(component)){ 
     38                                        System.err.println("Referenced component is not known"); 
     39                                        throw new AssertionError("Referenced component is not known."); 
     40                        } 
     41                        builder.append(Integer.toHexString(component.hashCode())); 
    3742                        builder.append("\" newName=\"" + evt.getNewValue()); 
    3843                        builder.append("\"/>" + StringTools.ENDLINE); 
    3944                        outputWriter.write(builder.toString()); 
    40                 } 
    41                          
     45                }                
    4246        } 
    4347         
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/Runner.java

    r850 r851  
    6464        Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(jfcWriter), 
    6565                                                        AWTEvent.WINDOW_EVENT_MASK); 
    66         JFCComponent.addListener(new NameChangeListener(jfcWriter)); 
     66        JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(jfcWriter)); 
    6767 
    6868        if (stdOutputWrite) { 
     
    8080                Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(stdJfcWriter), 
    8181                        AWTEvent.WINDOW_EVENT_MASK); 
    82                 JFCComponent.addListener(new NameChangeListener(stdJfcWriter)); 
     82                JFCComponent.addPropertyChangeListener(new JFCNameChangeListener(stdJfcWriter)); 
     83                JFCComponent.addContainerListener(new JFCContainerListener(stdJfcWriter)); 
    8384            } 
    8485            catch (UnsupportedEncodingException e) { 
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/WindowMonitor.java

    r850 r851  
    6060                } 
    6161                break; 
    62             case WindowEvent.WINDOW_CLOSED: 
    63                 window = ((WindowEvent) event).getWindow(); 
    64                 JFCComponent.remove(window); 
    65                 break; 
    6662            default: 
    6763                break; 
Note: See TracChangeset for help on using the changeset viewer.