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

Last change on this file since 488 was 488, checked in by sherbold, 12 years ago
  • converted quest-ui-core to Maven project
File size: 3.2 KB
RevLine 
[434]1package de.ugoe.cs.quest.ui;
[1]2
[247]3import java.io.IOException;
4import java.util.List;
5
6import joptsimple.OptionException;
7import joptsimple.OptionParser;
8import joptsimple.OptionSet;
9import joptsimple.OptionSpec;
[432]10import de.ugoe.cs.quest.log4j.Log4JLogger;
[434]11import de.ugoe.cs.quest.ui.swt.MainWindow;
[1]12import de.ugoe.cs.util.console.CommandExecuter;
[171]13import de.ugoe.cs.util.console.Console;
[1]14import de.ugoe.cs.util.console.TextConsole;
15
[171]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 */
[1]27public class Runner {
28
[247]29        public enum UITYPE {
30                text, swt
31        };
[396]32       
33        public enum LOG4JTYPE {
34                enable, disable
35        }
[247]36
[1]37        /**
[171]38         * <p>
39         * Main method of the application.
40         * </p>
41         *
[1]42         * @param args
[171]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
[1]46         */
47        public static void main(String[] args) {
[171]48                CommandExecuter.getInstance().addCommandPackage(
[434]49                                "de.ugoe.cs.quest.ui.commands");
[171]50                CommandExecuter.getInstance().addCommandPackage(
[434]51                                "de.ugoe.cs.quest.plugin.mfc.commands");
[171]52                CommandExecuter.getInstance().addCommandPackage(
[434]53                                "de.ugoe.cs.quest.plugin.php.commands");
[196]54                CommandExecuter.getInstance().addCommandPackage(
[434]55                                "de.ugoe.cs.quest.plugin.guitar.commands");
[299]56                CommandExecuter.getInstance().addCommandPackage(
[434]57                                "de.ugoe.cs.quest.plugin.jfc.commands");
[396]58                //new Log4JLogger();
[247]59
60                OptionParser parser = new OptionParser();
[396]61                OptionSpec<LOG4JTYPE> log4j = parser.accepts("log4j", "Allowed values: enable, disable").withRequiredArg()
62                                .ofType(LOG4JTYPE.class).defaultsTo(LOG4JTYPE.enable);
[247]63                OptionSpec<UITYPE> ui = parser.accepts("ui", "Allowed values: text, swt").withRequiredArg()
64                                .ofType(UITYPE.class).defaultsTo(UITYPE.text);
[407]65                OptionSpec<LOG4JTYPE> trace = parser.accepts("trace", "Allowed values: enable, disable").withRequiredArg().ofType(LOG4JTYPE.class).defaultsTo(LOG4JTYPE.enable);
[247]66                OptionSet options = parser.parse(args);
67
68                List<String> startupCommands = options.nonOptionArguments();
69                try {
[396]70                        switch (options.valueOf(log4j)) {
71                        case enable:
72                                new Log4JLogger();
73                                break;
74                        case disable:
75                                // do nothing
76                                break;
77                        default:
[407]78                                throw new AssertionError("reached source code that should be unreachable");
[112]79                        }
[396]80                       
81                        switch (options.valueOf(ui)) {
82                        case text:
83                                TextConsole textConsole = new TextConsole();
[407]84                                if( options.valueOf(trace)==LOG4JTYPE.disable ) {
85                                        textConsole.setDebug(false);
86                                }
[396]87                                for (String command : startupCommands) {
88                                        CommandExecuter.getInstance().exec(command);
89                                }
90                                textConsole.run(true);
91                                break;
92                        case swt:
93                                MainWindow mainWindow = new MainWindow(startupCommands);
94                                mainWindow.open();
95                                break;
96                        default:
[407]97                                throw new AssertionError("reached source code that should be unreachable");
[396]98                        }
[247]99                } catch (OptionException e) {
100                        System.err.println("Invalid Parameters: " + e.getMessage());
101                        try {
102                                parser.printHelpOn(System.out);
103                        } catch (IOException e1) {
104                                // ignore exception.
105                        }
106                }
[1]107        }
108
109}
Note: See TracBrowser for help on using the repository browser.