source: trunk/quest-runner/src/main/java/de/ugoe/cs/quest/ui/Runner.java @ 526

Last change on this file since 526 was 526, checked in by sherbold, 12 years ago
  • intial commit of quest-runner and quest-ui-swt. Both projects contain components that were moved from quest-ui-core. The quest-runner is responsible for the execution of the QUEST application. The quest-ui-swt contains an SWT GUI.
  • Property svn:mime-type set to text/plain
File size: 3.3 KB
Line 
1package de.ugoe.cs.quest.ui;
2
3import java.io.IOException;
4import java.util.List;
5
6import joptsimple.OptionException;
7import joptsimple.OptionParser;
8import joptsimple.OptionSet;
9import joptsimple.OptionSpec;
10import de.ugoe.cs.quest.log4j.Log4JLogger;
11import de.ugoe.cs.quest.ui.swt.MainWindow;
12import de.ugoe.cs.util.console.CommandExecuter;
13import de.ugoe.cs.util.console.Console;
14import de.ugoe.cs.util.console.TextConsole;
15
16/**
17 * <p>
18 * Start-up class of the application.
19 * </p>
20 * <p>
21 * It sets up and starts the {@link Console}.
22 * </p>
23 *
24 * @author Steffen Herbold
25 * @version 1.0
26 */
27public class Runner {
28
29        public enum UITYPE {
30                text, swt
31        };
32
33        public enum LOG4JTYPE {
34                enable, disable
35        }
36
37        /**
38         * <p>
39         * Main method of the application.
40         * </p>
41         *
42         * @param args
43         *            if parameters are defined, they are interpreted as commands
44         *            for the {@link Console} and executed before the user can use
45         *            the console; can be used to perform batch operations
46         */
47        public static void main(String[] args) {
48                CommandExecuter.getInstance().addCommandPackage(
49                                "de.ugoe.cs.quest.ui.commands");
50                CommandExecuter.getInstance().addCommandPackage(
51                                "de.ugoe.cs.quest.ui.swt.commands");
52                CommandExecuter.getInstance().addCommandPackage(
53                                "de.ugoe.cs.quest.plugin.mfc.commands");
54                CommandExecuter.getInstance().addCommandPackage(
55                                "de.ugoe.cs.quest.plugin.php.commands");
56                CommandExecuter.getInstance().addCommandPackage(
57                                "de.ugoe.cs.quest.plugin.guitar.commands");
58                CommandExecuter.getInstance().addCommandPackage(
59                                "de.ugoe.cs.quest.plugin.jfc.commands");
60
61                OptionParser parser = new OptionParser();
62                OptionSpec<LOG4JTYPE> log4j = parser
63                                .accepts("log4j", "Allowed values: enable, disable")
64                                .withRequiredArg().ofType(LOG4JTYPE.class)
65                                .defaultsTo(LOG4JTYPE.enable);
66                OptionSpec<UITYPE> ui = parser
67                                .accepts("ui", "Allowed values: text, swt").withRequiredArg()
68                                .ofType(UITYPE.class).defaultsTo(UITYPE.text);
69                OptionSpec<LOG4JTYPE> trace = parser
70                                .accepts("trace", "Allowed values: enable, disable")
71                                .withRequiredArg().ofType(LOG4JTYPE.class)
72                                .defaultsTo(LOG4JTYPE.enable);
73                OptionSet options = parser.parse(args);
74
75                List<String> startupCommands = options.nonOptionArguments();
76                try {
77                        switch (options.valueOf(log4j)) {
78                        case enable:
79                                new Log4JLogger();
80                                break;
81                        case disable:
82                                // do nothing
83                                break;
84                        default:
85                                throw new AssertionError(
86                                                "reached source code that should be unreachable");
87                        }
88
89                        switch (options.valueOf(ui)) {
90                        case text:
91                                TextConsole textConsole = new TextConsole();
92                                if (options.valueOf(trace) == LOG4JTYPE.disable) {
93                                        textConsole.setDebug(false);
94                                }
95                                for (String command : startupCommands) {
96                                        CommandExecuter.getInstance().exec(command);
97                                }
98                                textConsole.run(true);
99                                break;
100                        case swt:
101                                MainWindow mainWindow = new MainWindow(startupCommands);
102                                mainWindow.open();
103                                break;
104                        default:
105                                throw new AssertionError(
106                                                "reached source code that should be unreachable");
107                        }
108                } catch (OptionException e) {
109                        System.err.println("Invalid Parameters: " + e.getMessage());
110                        try {
111                                parser.printHelpOn(System.out);
112                        } catch (IOException e1) {
113                                // ignore exception.
114                        }
115                }
116        }
117
118}
Note: See TracBrowser for help on using the repository browser.