source: trunk/autoquest-jfcmonitor/src/main/java/de/ugoe/cs/autoquest/jfcmonitor/Runner.java @ 1113

Last change on this file since 1113 was 928, checked in by fglaser, 12 years ago
  • Title change hierarchy control added
  • JFCNameChangeListener renamed to JFCTitleChangeListener
  • JFCTitleChangeListener now additionaly listens on icon and position changes
  • Property svn:mime-type set to text/plain
File size: 4.6 KB
RevLine 
[927]1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
[822]14
[922]15package de.ugoe.cs.autoquest.jfcmonitor;
[271]16
[263]17import java.awt.AWTEvent;
18import java.awt.Toolkit;
19import java.awt.event.AWTEventListener;
[370]20import java.awt.event.FocusEvent;
[303]21import java.io.FileOutputStream;
[271]22import java.io.IOException;
[268]23import java.io.OutputStreamWriter;
[308]24import java.io.UnsupportedEncodingException;
[263]25import java.util.Arrays;
26
[271]27/**
28 * <p>
29 * Start-up class of the application.
30 * </p>
31 * <p>
32 * Launches the application under test in the same JVM.
33 * </p>
34 *
[853]35 * @author Steffen Herbold
36 * @author Fabian Glaser
[271]37 * @version 1.0
38 */
[263]39public class Runner {
40
[822]41    /**
42     * <p>
43     * Debugging variable. If set to true, the logging is also written to the console.
44     * </p>
45     */
46    private final static boolean stdOutputWrite = true;
[271]47
[822]48    /**
49     * <p>
50     * Main method of the application.
51     * </p>
52     *
53     * @param args
54     *            the first parameter defines the Jar file that contains the start-up information of
55     *            the application under test. The remaining parameters are passed on the toe
56     *            application under test.
57     */
58    public static void main(String[] args) {
59        String logfileName = "jfcmonitor_" + System.currentTimeMillis() + ".log";
[295]60
[822]61        FileOutputStream fis;
62        OutputStreamWriter writer;
63        try {
64            // the writer is not closed explicitly!
65            fis = new FileOutputStream(logfileName, true);
[842]66            writer = new OutputStreamWriter(fis, "UTF-8");
[822]67        }
68        catch (IOException e) {
69            System.err.println("JFCMONITOR -- failure opening logfile: " + e.getMessage());
70            return;
71        }
[271]72
[842]73        JFCMonitorOutputWriter jfcWriter = new JFCMonitorOutputWriter(writer);
74        AWTEventListener listenerFile = new JFCListener(jfcWriter);
[822]75        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.KEY_EVENT_MASK);
76        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, AWTEvent.MOUSE_EVENT_MASK);
77        Toolkit.getDefaultToolkit().addAWTEventListener(listenerFile, FocusEvent.FOCUS_EVENT_MASK);
[853]78        Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(jfcWriter),
[822]79                                                        AWTEvent.WINDOW_EVENT_MASK);
[928]80        JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(jfcWriter));
[853]81        JFCComponent.addContainerListener(new JFCContainerListener(jfcWriter));
[271]82
[822]83        if (stdOutputWrite) {
84            AWTEventListener listenerStdOut;
85            try {
[842]86                OutputStreamWriter stdOutputWriter = new OutputStreamWriter(System.out, "UTF-8");
87                JFCMonitorOutputWriter stdJfcWriter = new JFCMonitorOutputWriter(stdOutputWriter);
88                listenerStdOut = new JFCListener(stdJfcWriter);
[822]89                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
90                                                                AWTEvent.KEY_EVENT_MASK);
91                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
92                                                                AWTEvent.MOUSE_EVENT_MASK);
93                Toolkit.getDefaultToolkit().addAWTEventListener(listenerStdOut,
94                                                                FocusEvent.FOCUS_EVENT_MASK);
[853]95                Toolkit.getDefaultToolkit().addAWTEventListener(new JFCWindowMonitor(stdJfcWriter),
[842]96                        AWTEvent.WINDOW_EVENT_MASK);
[928]97                JFCComponent.addPropertyChangeListener(new JFCTitleChangeListener(stdJfcWriter));
[851]98                JFCComponent.addContainerListener(new JFCContainerListener(stdJfcWriter));
[822]99            }
100            catch (UnsupportedEncodingException e) {
101                System.err
102                    .println("JFCMONITOR -- failure to create OutputStreamWriter with UTF-8 encoding to System.out");
103            }
104        }
[271]105
[822]106        JarLauncher launcher = new JarLauncher(args[0], Arrays.copyOfRange(args, 1, args.length));
107        launcher.exec();
108    }
[263]109}
Note: See TracBrowser for help on using the repository browser.