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

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