1
package games.strategy.engine.framework;
3
import games.strategy.debug.Console;
4
import games.strategy.engine.EngineVersion;
5
import games.strategy.engine.framework.startup.ui.MainFrame;
6
import games.strategy.triplea.ui.ErrorHandler;
8
import java.util.logging.LogManager;
9
import java.util.prefs.BackingStoreException;
10
import java.util.prefs.Preferences;
12
import javax.swing.LookAndFeel;
13
import javax.swing.SwingUtilities;
14
import javax.swing.UIManager;
17
public class GameRunner2
19
public static final String LOOK_AND_FEEL_PREF = "LookAndFeel";
21
public static final String TRIPLEA_GAME_PROPERTY = "triplea.game";
22
public static final String TRIPLEA_HOST_PROPERTY = "triplea.host";
23
public static final String TRIPLEA_PORT_PROPERTY = "triplea.port";
24
public static final String TRIPLEA_SERVER_PASSWORD_PROPERTY = "triplea.server.password";
25
public static final String TRIPLEA_CLIENT_PROPERTY = "triplea.client";
26
public static final String TRIPLEA_SERVER_PROPERTY = "triplea.server";
27
public static final String TRIPLEA_NAME_PROPERTY = "triplea.name";
28
public static final String TRIPLEA_STARTED = "triplea.started";
30
//these properties are for games that should connect to the Lobby Server
31
public static final String LOBBY_PORT = "triplea.lobby.port";
32
public static final String LOBBY_HOST = "triplea.lobby.host";
33
public static final String LOBBY_GAME_COMMENTS = "triplea.lobby.game.comments";
34
public static final String LOBBY_GAME_HOSTED_BY = "triplea.lobby.game.hostedBy";
38
public static void main(String[] args)
42
Console.getConsole().displayStandardError();
43
Console.getConsole().displayStandardOutput();
45
System.setProperty("sun.awt.exception.handler", ErrorHandler.class.getName());
46
System.setProperty("triplea.engine.version", EngineVersion.VERSION.toString());
50
handleCommandLineArgs(args);
54
private static void showMainFrame()
56
SwingUtilities.invokeLater(new Runnable()
61
MainFrame frame = new MainFrame();
72
* Move command line arguments to System.properties
74
private static void handleCommandLineArgs(String[] args)
76
String[] properties = new String[] {TRIPLEA_SERVER_PROPERTY, TRIPLEA_CLIENT_PROPERTY, TRIPLEA_PORT_PROPERTY, TRIPLEA_HOST_PROPERTY, TRIPLEA_GAME_PROPERTY, TRIPLEA_NAME_PROPERTY, TRIPLEA_SERVER_PASSWORD_PROPERTY};
79
//if only 1 arg, it must be the game name
81
//optionally, it may not start with the property name
85
if(args[0].startsWith(TRIPLEA_GAME_PROPERTY))
87
value = getValue( TRIPLEA_GAME_PROPERTY);
93
System.setProperty(TRIPLEA_GAME_PROPERTY, value);
97
boolean usagePrinted = false;
98
for(int argIndex = 0; argIndex < args.length; argIndex++)
100
boolean found = false;
101
for(int propIndex = 0; propIndex < properties.length; propIndex++)
103
if(args[argIndex].startsWith(properties[propIndex]))
105
String value = getValue(args[argIndex]);
106
System.getProperties().setProperty(properties[propIndex], value);
107
System.out.println(properties[propIndex] + ":" + value );
113
System.out.println("Unrecogized:" + args[argIndex]);
123
private static void usage()
125
System.out.println("Arguments\n" +
126
" triplea.game=<FILE_NAME>\n" +
127
" triplea.server=true\n" +
128
" triplea.client=true\n" +
129
" triplea.port=<PORT>\n" +
130
" triplea.host=<HOST>\n" +
131
" triplea.name=<PLAYER_NAME>\n" +
133
"if there is only one argument, and it does not start with triplea.game, the argument will be \n" +
134
"taken as the name of the file to load.\n" +
137
" to start a game using the given file:\n" +
139
" triplea /home/sgb/games/test.xml\n" +
143
" triplea triplea.game=/home/sgb/games/test.xml\n" +
145
" to connect to a remote host:\n" +
147
" triplea triplea.client=true triplea.host=127.0.0.0 triplea.port=3300 triplea.name=Paul\n" +
149
" to start a server with the given game\n" +
151
" triplea triplea.game=/home/sgb/games/test.xml triplea.server=true triplea.port=3300 triplea.name=Allan" +
153
" to start a server, you can optionally password protect the game using triplea.server.password=foo"
157
private static String getValue(String arg)
159
int index = arg.indexOf('=');
162
return arg.substring(index +1);
165
public static void setupLookAndFeel()
169
SwingUtilities.invokeAndWait(new Runnable() {
174
UIManager.setLookAndFeel(getDefaultLookAndFeel());
175
} catch(Throwable t) {
176
if(!GameRunner.isMac()) {
179
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
180
} catch(Exception e) {}
185
} catch(Throwable t) {
186
t.printStackTrace(System.out);
190
public static void setupLogging()
192
//setup logging to read our logging.properties
195
LogManager.getLogManager().readConfiguration(ClassLoader.getSystemResourceAsStream("logging.properties"));
196
} catch (Exception e)
202
public static String getDefaultLookAndFeel() {
203
Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
204
String defaultLokAndFeel = "org.jvnet.substance.skin.SubstanceRavenGraphiteLookAndFeel";
205
//macs are already beautiful
206
if(GameRunner.isMac()) {
207
defaultLokAndFeel = UIManager.getSystemLookAndFeelClassName();
209
return pref.get(LOOK_AND_FEEL_PREF, defaultLokAndFeel);
212
public static void setDefaultLookAndFeel(String lookAndFeelClassName) {
213
Preferences pref = Preferences.userNodeForPackage(GameRunner2.class);
214
pref.put(LOOK_AND_FEEL_PREF, lookAndFeelClassName);
217
} catch (BackingStoreException e) {