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

Last change on this file since 822 was 822, checked in by sherbold, 12 years ago
  • converted JFCMonitor to Maven project
  • Property svn:mime-type set to text/plain
File size: 3.2 KB
Line 
1
2package de.ugoe.cs.eventbench.jfcmonitor;
3
4import java.awt.AWTEvent;
5import java.awt.Toolkit;
6import java.awt.event.AWTEventListener;
7import java.awt.event.FocusEvent;
8import java.io.FileOutputStream;
9import java.io.IOException;
10import java.io.OutputStreamWriter;
11import java.io.UnsupportedEncodingException;
12import java.util.Arrays;
13
14/**
15 * <p>
16 * Start-up class of the application.
17 * </p>
18 * <p>
19 * Launches the application under test in the same JVM.
20 * </p>
21 *
22 * @author Steffen Herbold
23 * @version 1.0
24 */
25public class Runner {
26
27    /**
28     * <p>
29     * Debugging variable. If set to true, the logging is also written to the 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 start-up information of
41     *            the application under test. The remaining parameters are passed on the toe
42     *            application under test.
43     */
44    public static void main(String[] args) {
45        String logfileName = "jfcmonitor_" + System.currentTimeMillis() + ".log";
46
47        FileOutputStream fis;
48        OutputStreamWriter writer;
49        try {
50            // the writer is not closed explicitly!
51            fis = new FileOutputStream(logfileName, true);
52            writer = new OutputStreamWriter(fis, "UTF-16");
53        }
54        catch (IOException e) {
55            System.err.println("JFCMONITOR -- failure opening logfile: " + e.getMessage());
56            return;
57        }
58
59        AWTEventListener listenerFile = new JFCListener(writer);
60        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.KEY_EVENT_MASK);
61        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.MOUSE_EVENT_MASK);
62        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, FocusEvent.FOCUS_EVENT_MASK);
63        Toolkit.getDefaultToolkit().addAWTEventListener(new WindowMonitor(),
64                                                        AWTEvent.WINDOW_EVENT_MASK);
65
66        if (stdOutputWrite) {
67            AWTEventListener listenerStdOut;
68            try {
69                listenerStdOut = new JFCListener(new OutputStreamWriter(System.out, "UTF-8"));
70                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
71                                                                AWTEvent.KEY_EVENT_MASK);
72                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
73                                                                AWTEvent.MOUSE_EVENT_MASK);
74                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
75                                                                FocusEvent.FOCUS_EVENT_MASK);
76            }
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(args, 1, args.length));
84        launcher.exec();
85    }
86}
Note: See TracBrowser for help on using the repository browser.