fixing issues related to the displays pref #3264

This commit is contained in:
Ben Fry
2015-06-08 20:50:07 -04:00
parent 1414ea9adc
commit 70dc95047f
5 changed files with 61 additions and 31 deletions

View File

@@ -153,6 +153,7 @@ public class Runner implements MessageConsumer {
public boolean launchVirtualMachine(boolean presenting) {
String[] vmParams = getMachineParams();
String[] sketchParams = getSketchParams(presenting);
// PApplet.printArray(sketchParams);
int port = 8000 + (int) (Math.random() * 1000);
String portStr = String.valueOf(port);
@@ -308,7 +309,7 @@ public class Runner implements MessageConsumer {
} else {
params.add("processing.core.PApplet");
// get the stored device index (starts at 0)
// get the stored device index (starts at 1)
int runDisplay = Preferences.getInteger("run.display");
// If there was a saved location (this guy has been run more than once)
@@ -327,17 +328,23 @@ public class Runner implements MessageConsumer {
// Make sure the display set in Preferences actually exists
GraphicsDevice runDevice = editorDevice;
if (runDisplay >= 0 && runDisplay < devices.length) {
runDevice = devices[runDisplay];
if (runDisplay > 0 && runDisplay <= devices.length) {
runDevice = devices[runDisplay-1];
} else {
// If a bad display is selected, use the same display as the editor
if (runDisplay > 0) { // don't complain about -1 or 0
System.err.println("Display " + runDisplay + " not available.");
}
runDevice = editorDevice;
for (int i = 0; i < devices.length; i++) {
if (devices[i] == runDevice) {
runDisplay = i;
// Wasn't setting the pref to avoid screwing things up with
// something temporary. But not setting it makes debugging one's
// setup just too damn weird, so changing that behavior.
runDisplay = i + 1;
System.err.println("Setting 'Run Sketches on Display' preference to display " + runDisplay);
Preferences.setInteger("run.display", runDisplay);
break;
// Don't set the pref, might be a temporary thing. Users can
// open/close Preferences to reset the device themselves.
// Preferences.setInteger("run.display", runDisplay);
}
}
}