Allowing the initial status location and color to be set in case an error occurs before getdown.txt has been read (as is the case when the user rejects our certificate).

This commit is contained in:
Matt Jensen
2008-12-19 00:53:24 +00:00
parent ab121cf012
commit d85b6a0122
2 changed files with 53 additions and 23 deletions
@@ -6,13 +6,13 @@
// //
// Redistribution and use in source and binary forms, with or without modification, are permitted // Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met: // provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, this list of // 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer. // conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of // 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials provided // conditions and the following disclaimer in the documentation and/or other materials provided
// with the distribution. // with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
@@ -104,7 +104,7 @@ public class Application
/** Background image specifiers for {@link RotatingBackgrounds}. */ /** Background image specifiers for {@link RotatingBackgrounds}. */
public String[] rotatingBackgrounds; public String[] rotatingBackgrounds;
/** The error background image for {@link RotatingBackgrounds}. */ /** The error background image for {@link RotatingBackgrounds}. */
public String errorBackground; public String errorBackground;
@@ -546,7 +546,7 @@ public class Application
_jvmargs.add(jvmargs[ii]); _jvmargs.add(jvmargs[ii]);
} }
} }
// Add the launch specific JVM arguments // Add the launch specific JVM arguments
for (String arg : _baseJvmArgs) { for (String arg : _baseJvmArgs) {
_jvmargs.add(arg); _jvmargs.add(arg);
@@ -1258,31 +1258,51 @@ public class Application
protected Rectangle parseRect (HashMap<String,Object> cdata, String name, Rectangle def) protected Rectangle parseRect (HashMap<String,Object> cdata, String name, Rectangle def)
{ {
String value = (String)cdata.get(name); String value = (String)cdata.get(name);
Rectangle rect = parseRect(value);
if (rect == null) {
log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
} else {
return rect;
}
return def;
}
public static Rectangle parseRect (String value)
{
if (!StringUtil.isBlank(value)) { if (!StringUtil.isBlank(value)) {
int[] v = StringUtil.parseIntArray(value); int[] v = StringUtil.parseIntArray(value);
if (v != null && v.length == 4) { if (v != null && v.length == 4) {
return new Rectangle(v[0], v[1], v[2], v[3]); return new Rectangle(v[0], v[1], v[2], v[3]);
} else {
log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
} }
} }
return def; return null;
} }
/** Used to parse color specifications from the config file. */ /** Used to parse color specifications from the config file. */
protected Color parseColor (HashMap<String,Object> cdata, String name, Color def) protected Color parseColor (HashMap<String,Object> cdata, String name, Color def)
{ {
String value = (String)cdata.get(name); String value = (String)cdata.get(name);
if (!StringUtil.isBlank(value)) { Color color = parseColor(value);
try { if (color == null) {
return new Color(Integer.parseInt(value, 16)); log.warning("Ignoring invalid '" + name + "' config '" + value + "'.");
} catch (Exception e) { } else {
log.warning("Ignoring invalid '" + name + "' config '" + value + "'."); return color;
}
} }
return def; return def;
} }
public static Color parseColor (String hexValue)
{
if (!StringUtil.isBlank(hexValue)) {
try {
return new Color(Integer.parseInt(hexValue, 16));
} catch (NumberFormatException e) {
log.warning("Ignoring invalid color", "hexValue", hexValue, "exception", e);
}
}
return null;
}
/** Parses a list of strings from the config file. */ /** Parses a list of strings from the config file. */
protected String[] parseList (HashMap<String,Object> cdata, String name) protected String[] parseList (HashMap<String,Object> cdata, String name)
{ {
@@ -1324,7 +1344,7 @@ public class Application
protected ArrayList<String> _jvmargs = new ArrayList<String>(); protected ArrayList<String> _jvmargs = new ArrayList<String>();
protected ArrayList<String> _appargs = new ArrayList<String>(); protected ArrayList<String> _appargs = new ArrayList<String>();
protected String[] _baseJvmArgs = new String[0]; protected String[] _baseJvmArgs = new String[0];
protected Object[] _signers; protected Object[] _signers;
@@ -6,13 +6,13 @@
// //
// Redistribution and use in source and binary forms, with or without modification, are permitted // Redistribution and use in source and binary forms, with or without modification, are permitted
// provided that the following conditions are met: // provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, this list of // 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer. // conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of // 2. Redistributions in binary form must reproduce the above copyright notice, this list of
// conditions and the following disclaimer in the documentation and/or other materials provided // conditions and the following disclaimer in the documentation and/or other materials provided
// with the distribution. // with the distribution.
// //
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
@@ -23,8 +23,10 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package com.threerings.getdown.launcher; package com.threerings.getdown.launcher;
import java.awt.Color;
import java.awt.Container; import java.awt.Container;
import java.awt.Image; import java.awt.Image;
import java.awt.Rectangle;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -34,15 +36,12 @@ import java.net.URL;
import javax.swing.JApplet; import javax.swing.JApplet;
import javax.swing.JPanel; import javax.swing.JPanel;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.util.Map; import java.util.Map;
import com.samskivert.util.RunAnywhere; import com.samskivert.util.RunAnywhere;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
import com.threerings.getdown.data.Application;
import com.threerings.getdown.util.ConfigUtil; import com.threerings.getdown.util.ConfigUtil;
import static com.threerings.getdown.Log.log; import static com.threerings.getdown.Log.log;
@@ -111,7 +110,7 @@ public class GetdownApplet extends JApplet
jvmargs = params.split(","); jvmargs = params.split(",");
for (int ii = 0; ii < jvmargs.length; ii++) { for (int ii = 0; ii < jvmargs.length; ii++) {
jvmargs[ii] = "-D" + jvmargs[ii]; jvmargs[ii] = "-D" + jvmargs[ii];
} }
} }
try { try {
@@ -141,9 +140,9 @@ public class GetdownApplet extends JApplet
protected void exit (int exitCode) { protected void exit (int exitCode) {
_app.releaseLock(); _app.releaseLock();
// Redirect to the URL in 'redirect_on_finish' if we completed successfully. // Redirect to the URL in 'redirect_on_finish' if we completed successfully.
// This allows us to use some javascript on that page to close Getdown's // This allows us to use some javascript on that page to close Getdown's
// browser window. I'd prefer to use the javascript bridge from the applet // browser window. I'd prefer to use the javascript bridge from the applet
// rather than redirecting, but calling JSObject.getWindow(this).call("close") // rather than redirecting, but calling JSObject.getWindow(this).call("close")
// doesn't seem to do anything. // doesn't seem to do anything.
if (getParameter("redirect_on_finish") != null && exitCode == 0) { if (getParameter("redirect_on_finish") != null && exitCode == 0) {
URL dest; URL dest;
@@ -163,6 +162,17 @@ public class GetdownApplet extends JApplet
} }
}; };
// configure the status/progress text in case something goes horribly wrong before we
// get a chance to read getdown.txt (like when the user rejects write permissions)
Rectangle statusBounds = Application.parseRect(getParameter("ui.status"));
if (statusBounds != null) {
_getdown._ifc.status = statusBounds;
}
Color statusColor = Application.parseColor(getParameter("ui.status_text"));
if (statusColor != null) {
_getdown._ifc.statusText = statusColor;
}
// set up our user interface immediately // set up our user interface immediately
_getdown.preInit(); _getdown.preInit();