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
+32 -19
View File
@@ -143,7 +143,6 @@ public class PreferencesFrame {
// get a wide name in there before getPreferredSize() is called
fontSelectionBox = new JComboBox<String>(new String[] { Toolkit.getMonoFontName() });
fontSelectionBox.setToolTipText(fontTip);
//updateDisplayList();
fontSelectionBox.setEnabled(false); // don't enable until fonts are loaded
@@ -317,17 +316,18 @@ public class PreferencesFrame {
// Run sketches on display [ 1 ]
JLabel displayLabel = new JLabel(Language.text("preferences.run_sketches_on_display")+": ");
JLabel displayLabel = new JLabel(Language.text("preferences.run_sketches_on_display") + ": ");
final String tip = "<html>" + Language.text("preferences.run_sketches_on_display.tip");
displayLabel.setToolTipText(tip);
displaySelectionBox = new JComboBox<String>();
updateDisplayList(); // needs to happen here for getPreferredSize()
// [ ] Automatically associate .pde files with Processing
autoAssociateBox =
new JCheckBox(Language.text("preferences.automatically_associate_pde_files"));
autoAssociateBox.setVisible(false);
autoAssociateBox =
new JCheckBox(Language.text("preferences.automatically_associate_pde_files"));
autoAssociateBox.setVisible(false);
// More preferences are in the ...
@@ -577,17 +577,21 @@ public class PreferencesFrame {
Language.saveLanguage(language);
}
int oldDisplayIndex = Preferences.getInteger("run.display"); //$NON-NLS-1$
int displayIndex = 0;
for (int d = 0; d < displaySelectionBox.getItemCount(); d++) {
if (displaySelectionBox.getSelectedIndex() == d) {
displayIndex = d;
// The preference will have already been reset when the window was created
if (displaySelectionBox.isEnabled()) {
int oldDisplayNum = Preferences.getInteger("run.display");
int displayNum = -1;
for (int d = 0; d < displaySelectionBox.getItemCount(); d++) {
if (displaySelectionBox.getSelectedIndex() == d) {
displayNum = d + 1;
}
}
}
if (oldDisplayIndex != displayIndex) {
Preferences.setInteger("run.display", displayIndex); //$NON-NLS-1$
for (Editor editor : base.getEditors()) {
editor.setSketchLocation(null);
if ((displayNum != -1) && (displayNum != oldDisplayNum)) {
Preferences.setInteger("run.display", displayNum); //$NON-NLS-1$
// Reset the location of the sketch, the window has changed
for (Editor editor : base.getEditors()) {
editor.setSketchLocation(null);
}
}
}
@@ -670,11 +674,14 @@ public class PreferencesFrame {
sketchbookLocationField.setText(Preferences.getSketchbookPath());
checkUpdatesBox.setSelected(Preferences.getBoolean("update.check")); //$NON-NLS-1$
updateDisplayList();
int defaultDisplayNum = updateDisplayList();
int displayNum = Preferences.getInteger("run.display"); //$NON-NLS-1$
if (displayNum >= 0 && displayNum < displayCount) {
displaySelectionBox.setSelectedIndex(displayNum);
//if (displayNum > 0 && displayNum <= displayCount) {
if (displayNum < 1 || displayNum > displayCount) {
displayNum = defaultDisplayNum;
Preferences.setInteger("run.display", displayNum);
}
displaySelectionBox.setSelectedIndex(displayNum-1);
// This takes a while to load, so run it from a separate thread
//EventQueue.invokeLater(new Runnable() {
@@ -749,11 +756,15 @@ public class PreferencesFrame {
}
void updateDisplayList() {
/**
* @return the number (1..whatever, not 0-indexed) of the default display
*/
int updateDisplayList() {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice defaultDevice = ge.getDefaultScreenDevice();
GraphicsDevice[] devices = ge.getScreenDevices();
int defaultNum = -1;
displayCount = devices.length;
String[] items = new String[displayCount];
for (int i = 0; i < displayCount; i++) {
@@ -762,6 +773,7 @@ public class PreferencesFrame {
i + 1, mode.getWidth(), mode.getHeight());
if (devices[i] == defaultDevice) {
title += " default";
defaultNum = i + 1;
}
items[i] = title;
}
@@ -771,5 +783,6 @@ public class PreferencesFrame {
if (displayCount == 1) {
displaySelectionBox.setEnabled(false);
}
return defaultNum;
}
}
+11 -5
View File
@@ -9655,8 +9655,10 @@ public class PApplet implements PConstants {
void frameMoved(int x, int y) {
System.err.println(EXTERNAL_MOVE + " " + x + " " + y);
System.err.flush(); // doesn't seem to help or hurt
if (!fullScreen) {
System.err.println(EXTERNAL_MOVE + " " + x + " " + y);
System.err.flush(); // doesn't seem to help or hurt
}
}
@@ -9818,7 +9820,7 @@ public class PApplet implements PConstants {
int stopColor = 0xff808080;
boolean hideStop = false;
int displayIndex = -1; // use default
int displayNum = -1; // use default
// boolean fullScreen = false;
boolean present = false;
// boolean spanDisplays = false;
@@ -9838,8 +9840,8 @@ public class PApplet implements PConstants {
editorLocation = parseInt(split(value, ','));
} else if (param.equals(ARGS_DISPLAY)) {
displayIndex = parseInt(value, -1);
if (displayIndex == -1) {
displayNum = parseInt(value, -1);
if (displayNum == -1) {
System.err.println("Could not parse " + value + " for " + ARGS_DISPLAY);
}
@@ -9926,6 +9928,10 @@ public class PApplet implements PConstants {
}
}
// Set the suggested display that's coming from the command line
// (and most likely, from the PDE's preference setting).
sketch.display = displayNum;
// Call the settings() method which will give us our size() call
// try {
sketch.handleSettings();
@@ -398,6 +398,7 @@ public class PSurfaceAWT extends PSurfaceNone {
GraphicsEnvironment.getLocalGraphicsEnvironment();
int displayNum = sketch.sketchDisplay();
// System.out.println("display from sketch is " + displayNum);
if (displayNum > 0) { // if -1, use the default device
GraphicsDevice[] devices = environment.getScreenDevices();
if (displayNum <= devices.length) {
@@ -694,6 +695,7 @@ public class PSurfaceAWT extends PSurfaceNone {
int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
// Ignore previous sketch placement when dealing with full screen
if (sketch.sketchFullScreen()) {
location = null;
}
@@ -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);
}
}
}
+2
View File
@@ -26,6 +26,8 @@ X https://github.com/processing/processing/issues/2843
o Update Windows icons for multiple sizes, implement them in the PDE
o http://code.google.com/p/processing/issues/detail?id=632
X closed during the 2.x cycle
X try to clean up the Recent menu with the home icon
_ make sure it doesn't break on Windows
contribs
X several Greek translation updates