Changeset 842 for trunk


Ignore:
Timestamp:
09/20/12 17:01:25 (12 years ago)
Author:
fglaser
Message:
  • OutputFormat? of JFCMonitor changed:
  • Components are printed, when they are created
  • Events hold hash values for components instead of full source path
Location:
trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor
Files:
1 added
4 edited

Legend:

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

    r825 r842  
    2323 * </p> 
    2424 *  
    25  * @author Steffen Herbold 
     25 * @author Steffen Herbold, Fabian Glaser 
    2626 * @version 1.0 
    2727 */ 
     
    199199        setTitle(); 
    200200        StringBuilder builder = new StringBuilder(); 
    201         if (parent != null) { 
    202             builder.append(parent.getXML()); 
    203         } 
    204         builder.append("  <component>" + StringTools.ENDLINE); 
     201        builder.append("  <component"); 
     202        if (parent != null){ 
     203                builder.append(" parent=" + Integer.toHexString(parent.component.hashCode())); 
     204        } 
     205        builder.append(">"+ StringTools.ENDLINE); 
    205206        builder.append("   <param name=\"title\" value=\"" + title + "\" />" + StringTools.ENDLINE); 
    206207        builder.append("   <param name=\"class\" value=\"" + componentClass + "\" />" + 
     
    212213        builder.append("  </component>" + StringTools.ENDLINE); 
    213214        return builder.toString(); 
     215    } 
     216     
     217    /** 
     218     * <p> 
     219     * Returns an XML representation of the components children. 
     220     * </p> 
     221     * @return XML representation of children 
     222     */ 
     223    public String printChildren(){ 
     224        StringBuilder builder = new StringBuilder(); 
     225        for (JFCComponent child: children){ 
     226                builder.append(child.getXML()); 
     227                builder.append(child.printChildren()); 
     228        } 
     229        return builder.toString(); 
    214230    } 
    215231 
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/JFCListener.java

    r825 r842  
    88import java.awt.event.KeyEvent; 
    99import java.awt.event.MouseEvent; 
    10 import java.io.IOException; 
    11 import java.io.OutputStreamWriter; 
    1210 
    1311import de.ugoe.cs.util.StringTools; 
     
    1917 * </p> 
    2018 *  
    21  * @author Steffen Herbold 
     19 * @author Steffen Herbold, Fabian Glaser 
    2220 * @version 1.0 
    2321 */ 
     
    2927     * </p> 
    3028     */ 
    31     final private OutputStreamWriter outputWriter; 
     29    final private JFCMonitorOutputWriter outputWriter; 
    3230 
    3331    /** 
    3432     * <p> 
    35      * Constructor. Creates a new JFCListener with a given {@link OutputStreamWriter}, where the 
     33     * Constructor. Creates a new JFCListener with a given {@link JFCMonitorOutputWriter}, where the 
    3634     * monitored information is logged. 
    3735     * </p> 
     
    4038     *            writer for the logged information 
    4139     */ 
    42     public JFCListener(OutputStreamWriter outputWriter) { 
     40    public JFCListener(JFCMonitorOutputWriter outputWriter) { 
    4341        this.outputWriter = outputWriter; 
    44         try { 
    45             outputWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + StringTools.ENDLINE); 
    46             outputWriter.write("<sessions>" + StringTools.ENDLINE); 
    47         } 
    48         catch (IOException e) { 
    49             System.err.println("JFCMONITOR -- Failure writing to log: " + e.getMessage()); 
    50         } 
    5142    } 
    5243 
     
    9889        } 
    9990        if (builder.length() > 0 && outputWriter != null) { 
    100             try { 
    101                 outputWriter.write(builder.toString()); 
    102                 outputWriter.flush(); 
    103             } 
    104             catch (IOException e) { 
    105                 System.err.println("JFCMONITOR -- Failure writing to log: " + e.getMessage()); 
    106             } 
     91            outputWriter.write(builder.toString()); 
    10792        } 
    10893    } 
     
    119104     */ 
    120105    private void addSourceInfo(StringBuilder builder, AWTEvent event) { 
    121         builder.append(" <source>" + StringTools.ENDLINE); 
     106        builder.append(" <source"); 
     107        if (event.getSource() instanceof Component) { 
     108            Component source = (Component) event.getSource(); 
     109            builder.append(" hash=" + Integer.toHexString(source.hashCode())); 
     110        }   
     111        builder.append(">" + StringTools.ENDLINE); 
    122112        builder.append("  <param name=\"toString\" value=\"" + 
    123113            StringTools.xmlEntityReplacement(event.getSource().toString()) + "\" />" + 
    124114            StringTools.ENDLINE); 
    125         if (event.getSource() instanceof Component) { 
    126             Component source = (Component) event.getSource(); 
    127             JFCComponent jfcComponent = JFCComponent.find(source); 
    128             if (jfcComponent != null) { 
    129                 builder.append(jfcComponent.getXML()); 
    130             } 
    131         } 
    132115        builder.append(" </source>" + StringTools.ENDLINE); 
    133116    } 
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/Runner.java

    r825 r842  
    2020 * </p> 
    2121 *  
    22  * @author Steffen Herbold 
     22 * @author Steffen Herbold, Fabian Glaser 
    2323 * @version 1.0 
    2424 */ 
     
    5050            // the writer is not closed explicitly! 
    5151            fis = new FileOutputStream(logfileName, true); 
    52             writer = new OutputStreamWriter(fis, "UTF-16"); 
     52            writer = new OutputStreamWriter(fis, "UTF-8"); 
    5353        } 
    5454        catch (IOException e) { 
     
    5757        } 
    5858 
    59         AWTEventListener listenerFile = new JFCListener(writer); 
     59        JFCMonitorOutputWriter jfcWriter = new JFCMonitorOutputWriter(writer); 
     60        AWTEventListener listenerFile = new JFCListener(jfcWriter); 
    6061        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.KEY_EVENT_MASK); 
    6162        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.MOUSE_EVENT_MASK); 
    6263        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, FocusEvent.FOCUS_EVENT_MASK); 
    63         Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(), 
     64        Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(jfcWriter), 
    6465                                                        AWTEvent.WINDOW_EVENT_MASK); 
    6566 
     
    6768            AWTEventListener listenerStdOut; 
    6869            try { 
    69                 listenerStdOut = new JFCListener(new OutputStreamWriter(System.out, "UTF-8")); 
     70                OutputStreamWriter stdOutputWriter = new OutputStreamWriter(System.out, "UTF-8"); 
     71                JFCMonitorOutputWriter stdJfcWriter = new JFCMonitorOutputWriter(stdOutputWriter); 
     72                listenerStdOut = new JFCListener(stdJfcWriter); 
    7073                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut, 
    7174                                                                AWTEvent.KEY_EVENT_MASK); 
     
    7477                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut, 
    7578                                                                FocusEvent.FOCUS_EVENT_MASK); 
     79                Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(stdJfcWriter), 
     80                        AWTEvent.WINDOW_EVENT_MASK); 
    7681            } 
    7782            catch (UnsupportedEncodingException e) { 
  • trunk/quest-jfcmonitor/src/main/java/de/ugoe/cs/quest/jfcmonitor/WindowMonitor.java

    r825 r842  
    1212 * </p> 
    1313 *  
    14  * @author Steffen Herbold 
     14 * @author Steffen Herbold, Fabian Glaser 
    1515 * @version 1.0 
    1616 */ 
    1717public class WindowMonitor implements AWTEventListener { 
     18         /** 
     19     * <p> 
     20     * Writer for logging events. 
     21     * </p> 
     22     */ 
     23    final private JFCMonitorOutputWriter outputWriter;   
     24         
     25    /** 
     26     * <p> 
     27     * Constructor. Creates a new WindowMonitor with a given {@link JFCMonitorOutputWriter}, where the 
     28     * monitored information is logged. 
     29     * </p> 
     30     *  
     31     * @param outputWriter 
     32     *            writer for the logged information 
     33     */ 
     34    public WindowMonitor(JFCMonitorOutputWriter outputWriter) { 
     35        this.outputWriter = outputWriter; 
     36    } 
     37         
    1838 
    1939    /** 
     
    3454                window = ((WindowEvent) event).getWindow(); 
    3555                JFCComponent.add(window); 
     56                JFCComponent jfcComponent = JFCComponent.find(window); 
     57                if (jfcComponent != null) { 
     58                    outputWriter.write(jfcComponent.getXML()); 
     59                    outputWriter.write(jfcComponent.printChildren()); 
     60                } 
    3661                break; 
    3762            case WindowEvent.WINDOW_CLOSED: 
Note: See TracChangeset for help on using the changeset viewer.