source: trunk/JFCMonitor/src/de/ugoe/cs/eventbench/jfcmonitor/Runner.java @ 355

Last change on this file since 355 was 355, checked in by sherbold, 12 years ago
  • Extended functionality of the JFCMonitor. It now monitors the whole hierarchy of the created GUI and uses this information to improve the precision in the usage logs.
  • Property svn:mime-type set to text/plain
File size: 2.5 KB
Line 
1package de.ugoe.cs.eventbench.jfcmonitor;
2
3import java.awt.AWTEvent;
4import java.awt.Toolkit;
5import java.awt.event.AWTEventListener;
6import java.io.FileOutputStream;
7import java.io.IOException;
8import java.io.OutputStreamWriter;
9import java.io.UnsupportedEncodingException;
10import java.util.Arrays;
11
12/**
13 * <p>
14 * Start-up class of the application.
15 * </p>
16 * <p>
17 * Launches the application under test in the same JVM.
18 * </p>
19 *
20 * @author Steffen Herbold
21 * @version 1.0
22 */
23public class Runner {
24
25        /**
26         * <p>
27         * Debugging variable. If set to true, the logging is also written to the
28         * console.
29         * </p>
30         */
31        private final static boolean stdOutputWrite = true;
32
33        /**
34         * <p>
35         * Main method of the application.
36         * </p>
37         *
38         * @param args
39         *            the first parameter defines the Jar file that contains the
40         *            start-up information of the application under test. The
41         *            remaining parameters are passed on the toe application under
42         *            test.
43         */
44        public static void main(String[] args) {
45                String logfileName = "jfcmonitor_" + System.currentTimeMillis()
46                                + ".log";
47
48                FileOutputStream fis;
49                OutputStreamWriter writer;
50                try {
51                        // the writer is not closed explicitly!
52                        fis = new FileOutputStream(logfileName, true);
53                        writer = new OutputStreamWriter(fis, "UTF-16");
54                } catch (IOException e) {
55                        System.err.println("JFCMONITOR -- failure opening logfile: "
56                                        + e.getMessage());
57                        return;
58                }
59
60                AWTEventListener listenerFile = new JFCListener(writer);
61                Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
62                                AWTEvent.KEY_EVENT_MASK);
63                Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile,
64                                AWTEvent.MOUSE_EVENT_MASK);
65                Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(),
66                                AWTEvent.WINDOW_EVENT_MASK);
67
68                if (stdOutputWrite) {
69                        AWTEventListener listenerStdOut;
70                        try {
71                                listenerStdOut = new JFCListener(new OutputStreamWriter(
72                                                System.out, "UTF-8"));
73                                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
74                                                AWTEvent.KEY_EVENT_MASK);
75                                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
76                                                AWTEvent.MOUSE_EVENT_MASK);
77                        } catch (UnsupportedEncodingException e) {
78                                System.err
79                                                .println("JFCMONITOR -- failure to create OutputStreamWriter with UTF-8 encoding to System.out");
80                        }
81                }
82
83                JarLauncher launcher = new JarLauncher(args[0], Arrays.copyOfRange(
84                                args, 1, args.length));
85                launcher.exec();
86        }
87}
Note: See TracBrowser for help on using the repository browser.