[Edit]: download patch (correct newlines)
Okay,
after applying the patch which is attached the following code snippet should work in a simple application:
String[] res = {“960 x 600”, “768 x 480”};
settings.setWindowedResolutions(res);
String[] depths = {“32 bpp”, “24 bpp”};
settings.setWindowedColorDepths(depths);
JmeSystem.showSettingsDialog(settings, false);
The API and file formats should be 100% backward compatible (hopefully)
…
Best,
Dirk.
[patch]Index: src/core/com/jme3/system/AppSettings.java
===================================================================
— src/core/com/jme3/system/AppSettings.java (Revision 7688)
+++ src/core/com/jme3/system/AppSettings.java (Arbeitskopie)
@@ -38,6 +38,7 @@
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
+import java.util.Vector;
import java.util.Properties;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@@ -70,6 +71,15 @@
defaults.put(“UseInput”, true);
defaults.put(“VSync”, false);
defaults.put(“FrameRate”, -1);
+
- String[] windowedRes = {
-
"320 x 240", "640 x 480", "800 x 600", "1024 x 768",<br />
-
"1152 x 864", "1280 x 720"};<br />
- defaults.setWindowedResolutions(windowedRes);
+
- String[] windowedDepths = {"24 bpp", "16 bpp"};
- defaults.setWindowedColorDepths(windowedDepths);
+
// defaults.put("Icons", null);
// disable these settings to benchmark speed
@@ -107,6 +117,10 @@
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String key = (String) entry.getKey();
String val = (String) entry.getValue();
+
-
/* Elements of a vector */<br />
-
if (key.endsWith("(Item)")) continue;<br />
+
if (val != null) {
val = val.trim();
}
@@ -119,6 +133,21 @@
} else if (key.endsWith("(bool)")) {
boolean bVal = Boolean.parseBoolean(val);
putBoolean(key.substring(0, key.length() - 6), bVal);
-
} else if (key.endsWith("(Vector<String>)")) {<br />
-
key = key.substring(0, key.length() - 16);<br />
-
int size = Integer.parseInt(val);<br />
+
-
Vector<String> vec = new Vector<String>();<br />
-
for (int i=0; i<size; i++) {<br />
-
String p = props.getProperty(key + "." + i + "(Item)");<br />
+
+
} else {
throw new IOException("Cannot parse key: " + key);
}
@@ -136,6 +165,16 @@
type = "(string)";
} else if (val instanceof Boolean) {
type = "(bool)";
-
} else if (val instanceof Vector) {<br />
-
Vector<String> vec = (Vector<String>) val;<br />
-
props.setProperty(entry.getKey() + "(Vector<String>)",<br />
-
Integer.toString(vec.size()));<br />
+
-
for (int i=0; i<vec.size(); i++)<br />
-
props.setProperty(entry.getKey() + "." + i + "(Item)",<br />
-
vec.get(i));<br />
+
} else {
throw new UnsupportedEncodingException();
}
@@ -146,25 +185,49 @@
public void load(String preferencesKey) throws BackingStoreException {
Preferences prefs = Preferences.userRoot().node(preferencesKey);
-
String[] keys = prefs.keys();<br />
-
if (keys != null) {<br />
-
for (String key : keys) {<br />
-
Object defaultValue = defaults.get(key);<br />
-
if (defaultValue instanceof Integer) {<br />
-
put(key, prefs.getInt(key, (Integer) defaultValue));<br />
-
} else if (defaultValue instanceof String) {<br />
-
put(key, prefs.get(key, (String) defaultValue));<br />
-
} else if (defaultValue instanceof Boolean) {<br />
-
put(key, prefs.getBoolean(key, (Boolean) defaultValue));<br />
-
}<br />
-
}<br />
-
}<br />
+
+
-
if (defaultValue instanceof Integer) {<br />
-
put(key, prefs.getInt(key, (Integer) defaultValue));<br />
-
} else if (defaultValue instanceof String) {<br />
-
put(key, prefs.get(key, (String) defaultValue));<br />
-
} else if (defaultValue instanceof Boolean) {<br />
-
put(key, prefs.getBoolean(key, (Boolean) defaultValue));<br />
-
} else if (defaultValue instanceof Vector) {<br />
-
Preferences vecPrefs = prefs.node(key);<br />
+
-
Vector<String> vec = new Vector<String>();<br />
-
for (int i=0; i<vecPrefs.keys().length; i++) {<br />
-
String p = vecPrefs.get(Integer.toString(i), null);<br />
+
+
-
if (vec.size() == 0) put(key, defaultValue);<br />
-
else put(key, vec);<br />
-
}<br />
- }
}
public void save(String preferencesKey) throws BackingStoreException {
Preferences prefs = Preferences.userRoot().node(preferencesKey);
+
-
if (val instanceof Vector) {<br />
-
Preferences vecPrefs = prefs.node(key);<br />
-
Vector<String> vec = (Vector<String>) val;<br />
+
-
for (int i=0; i<vec.size(); i++)<br />
-
vecPrefs.put(Integer.toString(i), vec.get(i));<br />
-
} else<br />
-
prefs.put(key, val.toString());<br />
}
}
@@ -450,4 +513,36 @@
public String getSettingsDialogImage() {
return settingsDialogImage;
}
+
+
+
// UI components
private JCheckBox vsyncBox = null;
private JCheckBox fullscreenBox = null;
@@ -548,9 +545,9 @@
private void updateResolutionChoices() {
if (!fullscreenBox.isSelected()) {
displayResCombo.setModel(new DefaultComboBoxModel(
-
windowedResolutions));<br />
-
colorDepthCombo.setModel(new DefaultComboBoxModel(new String[]{<br />
-
"24 bpp", "16 bpp"}));<br />
-
source.getWindowedResolutions()));<br />
-
colorDepthCombo.setModel(new DefaultComboBoxModel(<br />
-
source.getWindowedColorDepths()));<br />
displayFreqCombo.setModel(new DefaultComboBoxModel(
new String[]{"n/a"}));
displayFreqCombo.setEnabled(false);
[/patch]