Changing (desktop) com.jme3.app.SettingsDialog.windowedResolutions access modifiers

Hi their everybody,



I like to change the possible windowed resolutions of (desktop)

com.jme3.app.SettingsDialog to 16:10 resolutions. For that my

current idea is to change the


  • com.jme3.app.SettingsDialog.windowedResolutions



    Well, to do that this member variable need to be


  • public static



    Is it possible to change it in the official upstream (or trunk)?



    Best regards,

    Dirk.

Or are their any other ideas to realize that? Or exist an other communication channel (i.e. mailing list, newsgroup, etc.) to discuss this topic?



Best,

Dirk.

Note: I’m nearly 100% sure that changing the fields to protected is not going to be an acceptable approach. This class isn’t really designed for subclassing and randomly changing some access modifiers doesn’t make it so, either.



However, I’m also curious about a solution because I would like to remove some of the options to eliminate resolutions that would just look crazy in my game and to limit the amount of different nifty screen resolutions I need to support. But it so far hasn’t been a high priority… and forking that class is always a backup plan for me.

Okay,



I’m trying to make com.jme3.app.SettingsDialog ready for subclassing and trying to overload boolean JmeSystem.showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry, SettingsDialog settingsDialog) which get the users subclass as last argument.



If it works I will post a patch :smiley: …



Dirk.

No, this should be added to the appSettings if anything. The only illogical thing is that not every platform has “windowed” resolutions, mostly you get a set of supported resolutions from the system. So this would be some general set of “free” resolutions in the AppSettings.

Okay,



I’m trying to implement a private AppSettings.saveCollection(String name, Collection), private AppSettings.loadCollection(…) These will be called from AppSettings.save() {… saveCollection(“windowedResolutions”, windowedResolutions); …}. The SettingsDialog is calling source.getResolutions(). Okay?

Yeah…

[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) :stuck_out_tongue_winking_eye: …

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 = {
  •   &quot;320 x 240&quot;, &quot;640 x 480&quot;, &quot;800 x 600&quot;, &quot;1024 x 768&quot;,<br />
    
  •   &quot;1152 x 864&quot;, &quot;1280 x 720&quot;};<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(&quot;(Item)&quot;)) 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(&quot;(Vector&lt;String&gt;)&quot;)) {<br />
    
  •   key = key.substring(0, key.length() - 16);<br />
    
  •            int size = Integer.parseInt(val);<br />
    

+

  •   Vector&lt;String&gt; vec = new Vector&lt;String&gt;();<br />
    
  •   for (int i=0; i&lt;size; i++) {<br />
    
  •       String p = props.getProperty(key + &quot;.&quot; + i + &quot;(Item)&quot;);<br />
    

+

  •       if (p == null)<br />
    
  •   	throw new IOException(&quot;Cannot parse key: &quot; + key<br />
    
  •   			      + &quot;.&quot; + i);<br />
    
  •       vec.add(p);<br />
    
  •   }<br />
    

+

  •   put(key, vec);<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&lt;String&gt; vec = (Vector&lt;String&gt;) val;<br />
    
  •   props.setProperty(entry.getKey() + &quot;(Vector&lt;String&gt;)&quot;,<br />
    
  •   		  Integer.toString(vec.size()));<br />
    

+

  •            for (int i=0; i&lt;vec.size(); i++)<br />
    
  •       props.setProperty(entry.getKey() + &quot;.&quot; + i + &quot;(Item)&quot;,<br />
    
  •   		      vec.get(i));<br />
    

+

  •   continue;<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 />
    

+

  • for (Map.Entry<String, Object> entry : defaults.entrySet()) {
  •        String key = (String) entry.getKey();<br />
    
  •        Object defaultValue = entry.getValue();<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&lt;String&gt; vec = new Vector&lt;String&gt;();<br />
    
  •   for (int i=0; i&lt;vecPrefs.keys().length; i++) {<br />
    
  •       String p = vecPrefs.get(Integer.toString(i), null);<br />
    

+

  •       if (p == null)<br />
    
  •   	throw new BackingStoreException(&quot;Cannot parse key: &quot; + key<br />
    
  •   					+ &quot;.&quot; + i);<br />
    
  •       vec.add(p);<br />
    
  •   }<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);
  •    for (String key : keySet()) {<br />
    
  •        prefs.put(key, get(key).toString());<br />
    
  •    for (String key : keySet()) {<br />
    
  •   Object val = get(key);<br />
    

+

  •   if (val instanceof Vector) {<br />
    
  •   Preferences vecPrefs = prefs.node(key);<br />
    
  •   Vector&lt;String&gt; vec = (Vector&lt;String&gt;) val;<br />
    

+

  •   for (int i=0; i&lt;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;

}

+

  • public void setWindowedResolutions(String[] resolutions) {
  • Vector<String> windowedRes = new Vector<String>();

    +
  • for (int i=0; i<resolutions.length; i++)
  •   windowedRes.add(resolutions<i>);<br />
    

+

  • put("windowedResolutions", windowedRes);
  • }

    +
  • public String[] getWindowedResolutions() {
  • if (get("windowedResolutions") == null) return null;

    +
  • return ((Vector<String>) get("windowedResolutions"))
  •   .toArray(new String[0]);<br />
    
  • }

    +
  • public void setWindowedColorDepths(String[] depths) {
  • Vector<String> windowedDepths = new Vector<String>();

    +
  • for (int i=0; i<depths.length; i++)
  •   windowedDepths.add(depths<i>);<br />
    

+

  • put("windowedColorDepths", windowedDepths);
  • }

    +
  • public String[] getWindowedColorDepths() {
  • if (get("windowedColorDepths") == null) return null;

    +
  • return ((Vector<String>) get("windowedColorDepths"))
  •   .toArray(new String[0]);<br />
    
  • }

    }

    Index: src/desktop/com/jme3/app/SettingsDialog.java

    ===================================================================

    — src/desktop/com/jme3/app/SettingsDialog.java (Revision 7688)

    +++ src/desktop/com/jme3/app/SettingsDialog.java (Arbeitskopie)

    @@ -96,9 +96,6 @@

    private URL imageFile = null;

    // Array of supported display modes

    private DisplayMode[] modes = null;
  • // Array of windowed resolutions
  • private String[] windowedResolutions = {"320 x 240", "640 x 480", "800 x 600",
  •    &quot;1024 x 768&quot;, &quot;1152 x 864&quot;, &quot;1280 x 720&quot;};<br />
    

// 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 />
    
  •                    &quot;24 bpp&quot;, &quot;16 bpp&quot;}));<br />
    
  •           source.getWindowedResolutions()));<br />
    
  •        colorDepthCombo.setModel(new DefaultComboBoxModel(<br />
    
  •                source.getWindowedColorDepths()));<br />
    

displayFreqCombo.setModel(new DefaultComboBoxModel(

new String[]{"n/a"}));

displayFreqCombo.setEnabled(false);

[/patch]

1 Like