This patch creates a new class, SettingsDialogConfiguration, that the user can optionally pass in to configure how the settings dialog is displayed. The existing method signatures are left intact to preserve backwards compatibility.
Currently this allows the following settings to be changed (solving my issue #295 in a rather nicer way):
- Whether the renderer drop-down menu appears
- What windowed resolutions are available
Possibly it would be good to move settingsDialogImage from AppSetting to this class too (and deprecate the old method), since that is also not an application setting but configuration of the settings dialog itself.
Patch against latest SVN (r6757). There may be some fudge since I’m working on top of my previous patches.
[patch]
Index: src/desktop/com/jme3/app/SettingsDialogConfiguration.java
===================================================================
— src/desktop/com/jme3/app/SettingsDialogConfiguration.java (revision )
+++ src/desktop/com/jme3/app/SettingsDialogConfiguration.java (revision )
@@ -0,0 +1,73 @@
+/*
-
- Copyright © 2009-2011 jMonkeyEngine
- Copyright © 2009-2011 jMonkeyEngine
-
- All rights reserved.
- All rights reserved.
- *
-
- Redistribution and use in source and binary forms, with or without
- Redistribution and use in source and binary forms, with or without
-
- modification, are permitted provided that the following conditions are
- modification, are permitted provided that the following conditions are
-
- met:
- met:
- *
-
-
- Redistributions of source code must retain the above copyright
- Redistributions of source code must retain the above copyright
-
-
- notice, this list of conditions and the following disclaimer.
- notice, this list of conditions and the following disclaimer.
- *
-
-
- Redistributions in binary form must reproduce the above copyright
- Redistributions in binary form must reproduce the above copyright
-
-
- notice, this list of conditions and the following disclaimer in the
- notice, this list of conditions and the following disclaimer in the
-
- documentation and/or other materials provided with the distribution.
- documentation and/or other materials provided with the distribution.
- *
-
-
- Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
- Neither the name of ‘jMonkeyEngine’ nor the names of its contributors
-
-
- may be used to endorse or promote products derived from this software
- may be used to endorse or promote products derived from this software
-
- without specific prior written permission.
- without specific prior written permission.
- *
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
+package com.jme3.app;
+
+/**
-
- This class controls how the settings dialog is presented to the user.
- This class controls how the settings dialog is presented to the user.
- *
-
-
@author David Croft
-
@author David Croft
-
-
@version $Id$
-
@version $Id$
- */
+public class SettingsDialogConfiguration {
- private boolean allowRendererChange = false;
+
- // Array of windowed resolutions
- private String[] windowedResolutions = {"320 x 240", "640 x 480", "800 x 600",
-
"1024 x 768", "1152 x 864", "1280 x 720"};<br />
+
+
- public boolean isAllowRendererChooser() {
-
return allowRendererChange;<br />
- }
+
- /**
-
* Determines whether the user is presented with the option to change the renderer.<br />
-
*<br />
-
* @param allowRendererChange true if the user can change the renderer<br />
-
*/<br />
- public void setAllowRendererChange(boolean allowRendererChange) {
-
this.allowRendererChange = allowRendererChange;<br />
- }
+
- public String[] getWindowedResolutions() {
-
return windowedResolutions;<br />
- }
+
- /**
-
* Specifies the resolutions listed in the selection menu for windowed mode.<br />
-
*<br />
-
* @param windowedResolutions Array of strings of the format "320 x 240"<br />
-
*/<br />
- public void setWindowedResolutions(String[] windowedResolutions) {
-
this.windowedResolutions = windowedResolutions;<br />
- }
+}
Index: src/desktop/com/jme3/app/SettingsDialog.java
===================================================================
— src/desktop/com/jme3/app/SettingsDialog.java (revision 6709)
+++ src/desktop/com/jme3/app/SettingsDialog.java (revision )
@@ -77,6 +80,8 @@
*/
public final class SettingsDialog extends JDialog {
- private final SettingsDialogConfiguration config;
+
public static interface SelectionListener {
public void onSelection(int selection);
@@ -92,24 +97,21 @@
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",
-
"1024 x 768", "1152 x 864", "1280 x 720"};<br />
// UI components
private JCheckBox vsyncBox = null;
private JCheckBox fullscreenBox = null;
private JComboBox displayResCombo = null;
private JComboBox colorDepthCombo = null;
private JComboBox displayFreqCombo = null;
-// private JComboBox rendererCombo = null;
- private JComboBox rendererCombo = null;
private JComboBox antialiasCombo = null;
private JLabel icon = null;
private int selection = 0;
private SelectionListener selectionListener = null;
/**
-
* Constructor for the <code>PropertiesDialog</code>. Creates a<br />
-
* properties dialog initialized for the primary display.<br />
-
* Constructor for the <code>SettingsDialog</code>. Creates a<br />
-
* settings dialog initialized for the primary display.<br />
*
-
@param source
-
the <code>AppSettings</code> object to use for working with<br />
@@ -125,8 +127,8 @@
}
/**
-
* Constructor for the <code>PropertiesDialog</code>. Creates a<br />
-
* properties dialog initialized for the primary display.<br />
-
* Constructor for the <code>SettingsDialog</code>. Creates a<br />
-
* settings dialog initialized for the primary display.<br />
*
-
@param source
-
the <code>GameSettings</code> object to use for working with<br />
@@ -134,11 +136,31 @@
-
@param imageFile
-
the image file to use as the title of the dialog;<br />
-
<code>null</code> will result in to image being displayed<br />
-
* @param mainThreadTasks<br />
-
* @throws JmeException<br />
-
* @param loadSettings<br />
-
* @throws NullPointerException<br />
-
if the source is <code>null</code><br />
*/
public SettingsDialog(AppSettings source, URL imageFile, boolean loadSettings) {
-
this(source, imageFile, loadSettings, null);<br />
- }
+
- /**
-
* Constructor for the <code>SettingsDialog</code>. Creates a<br />
-
* settings dialog initialized for the primary display.<br />
-
*<br />
-
* @param source<br />
-
* the <code>GameSettings</code> object to use for working with<br />
-
* the properties file.<br />
-
* @param imageFile<br />
-
* the image file to use as the title of the dialog;<br />
-
* <code>null</code> will result in to image being displayed<br />
-
* @param loadSettings<br />
-
* @param config<br />
-
* the configuration for how the settings dialog should be constructed, or null for defaults.<br />
-
* @throws NullPointerException<br />
-
* if the source is <code>null</code><br />
-
*/<br />
- public SettingsDialog(AppSettings source, URL imageFile, boolean loadSettings, SettingsDialogConfiguration config) {
if (source == null) {
throw new NullPointerException("Settings source cannot be null");
}
@@ -146,6 +168,9 @@
this.source = source;
this.imageFile = imageFile;
-
if (config == null) config = new SettingsDialogConfiguration();<br />
-
this.config = config;<br />
+
// setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
setModal(true);
@@ -294,11 +325,8 @@
});
vsyncBox = new JCheckBox("VSync?");
vsyncBox.setSelected(source.isVSync());
-// rendererCombo = setUpRendererChooser();
-// rendererCombo.addKeyListener(aListener);
-
+
-
updateResolutionChoices();
updateAntialiasChoices();
displayResCombo.setSelectedItem(source.getWidth() + " x " + source.getHeight());
@@ -310,8 +338,13 @@
optionsPanel.add(antialiasCombo);
optionsPanel.add(fullscreenBox);
optionsPanel.add(vsyncBox);
-// optionsPanel.add(rendererCombo);
-
if (config.isAllowRendererChooser()) {<br />
-
rendererCombo = setUpRendererChooser();<br />
-
rendererCombo.addKeyListener(aListener);<br />
-
optionsPanel.add(rendererCombo);<br />
-
}<br />
+
// Set the button action listeners. Cancel disposes without saving, OK
// saves.
ok.addActionListener(new ActionListener() {
@@ -400,8 +452,6 @@
- false; } }
*/
-
String renderer = "LWJGL-OpenGL2";//(String) rendererCombo.getSelectedItem();<br />
-
boolean valid = false;
// test valid display mode when going full screen
@@ -420,9 +470,13 @@
source.setFrequency(freq);
source.setFullscreen(fullscreen);
source.setVSync(vsync);
-
//source.setRenderer(renderer);<br />
source.setSamples(multisample);
-
if (config.isAllowRendererChooser()) {<br />
-
String renderer = (String) rendererCombo.getSelectedItem();<br />
-
source.setRenderer(renderer);<br />
-
}<br />
+
String appTitle = source.getTitle();
try {
@@ -517,7 +571,7 @@
private void updateResolutionChoices() {
if (!fullscreenBox.isSelected()) {
displayResCombo.setModel(new DefaultComboBoxModel(
-
windowedResolutions));<br />
-
config.getWindowedResolutions()));<br />
colorDepthCombo.setModel(new DefaultComboBoxModel(new String[]{
"24 bpp", "16 bpp"}));
displayFreqCombo.setModel(new DefaultComboBoxModel(
Index: src/desktop/com/jme3/system/JmeSystem.java
===================================================================
— src/desktop/com/jme3/system/JmeSystem.java (revision 6733)
+++ src/desktop/com/jme3/system/JmeSystem.java (revision )
@@ -34,6 +34,7 @@
import com.jme3.app.SettingsDialog;
import com.jme3.app.SettingsDialog.SelectionListener;
+import com.jme3.app.SettingsDialogConfiguration;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import com.jme3.audio.AudioRenderer;
@@ -121,7 +122,26 @@
return new DesktopAssetManager(null);
}
- /**
-
* Shows the settings dialog.<br />
-
*<br />
-
* @param sourceSettings The default settings populated into the dialog.<br />
-
* @param loadFromRegistry<br />
-
* @return True if the user clicked OK, else false.<br />
-
*/<br />
public static boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry){
-
return showSettingsDialog(sourceSettings, loadFromRegistry, null);<br />
- }
+
- /**
-
* Shows the settings dialog.<br />
-
*<br />
-
* @param sourceSettings The default settings populated into the dialog.<br />
-
* @param loadFromRegistry<br />
-
* @param config The settings dialog configuration, or null to use defaults.<br />
-
* @return True if the user clicked OK, else false.<br />
-
*/<br />
- public static boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry, final SettingsDialogConfiguration config){
if (SwingUtilities.isEventDispatchThread())
throw new IllegalStateException("Cannot run from EDT");
@@ -146,7 +166,7 @@
SwingUtilities.invokeLater(new Runnable() {
public void run() {
synchronized (lock) {
-
SettingsDialog dialog = new SettingsDialog(settings, iconUrl,loadFromRegistry);<br />
-
SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry, config);<br />
dialog.setSelectionListener(selectionListener);
dialog.showDialog();
}
Index: src/core/com/jme3/app/SimpleApplication.java
===================================================================
— src/core/com/jme3/app/SimpleApplication.java (revision 6709)
+++ src/core/com/jme3/app/SimpleApplication.java (revision )
@@ -44,6 +44,7 @@
import com.jme3.scene.Node;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.system.AppSettings;
+import com.jme3.app.SettingsDialogConfiguration;
import com.jme3.system.JmeContext.Type;
import com.jme3.system.JmeSystem;
import com.jme3.util.BufferUtils;
@@ -73,6 +74,7 @@
protected StatsView statsView;
protected FlyByCamera flyCam;
protected boolean showSettings = true;
- protected SettingsDialogConfiguration settingsDialogConfiguration;
private AppActionListener actionListener = new AppActionListener();
private class AppActionListener implements ActionListener {
@@ -115,7 +117,7 @@
// show settings dialog
if (showSettings) {
-
if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {<br />
-
if (!JmeSystem.showSettingsDialog(settings, loadSettings, settingsDialogConfiguration)) {<br />
return;
}
}
@@ -165,6 +167,16 @@
}
/**
-
* Specifies the configuration for the settings window, if it is enabled<br />
-
*<br />
-
* @param config the configuration to use, or null to use defaults.<br />
-
*/<br />
- public void setSettingsDialogConfiguration(SettingsDialogConfiguration config)
- {
-
this.settingsDialogConfiguration = config;<br />
- }
+
- /**
- Attaches FPS statistics to guiNode and displays it on the screen.
*
*/
[/patch]
Sample usage:
[java]
AsciiMain app = new AsciiMain();
AppSettings settings = new AppSettings(true);
settings.setFullscreen(true);
app.setSettings(settings);
SettingsDialogConfiguration settingsConfig = new SettingsDialogConfiguration();
settingsConfig.setAllowRendererChange(true);
settingsConfig.setWindowedResolutions(new String[]{"5 x 5", "100 x 100", "1500 x 1500"});
app.setSettingsDialogConfiguration(settingsConfig);
app.setShowSettings(true);
app.start();
}
[/java]
(Minor quibble: please add this patch too, since this character is prevent the file being compiled on my system):
[patch]
Index: src/terrain/com/jme3/terrain/heightmap/FluidSimHeightMap.java
===================================================================
— src/terrain/com/jme3/terrain/heightmap/FluidSimHeightMap.java (revision 6446)
+++ src/terrain/com/jme3/terrain/heightmap/FluidSimHeightMap.java (revision )
@@ -40,7 +40,7 @@
- rubbery fluid enabling to fine tune the generated heightmap using a number
- of parameters.
*
-
-
@author Frederik Bülthoff
-
@author Frederik Bülthoff
-
-
@author Frederik Buelthoff
-
@author Frederik Buelthoff
-
@see <a href="http://www.gamedev.net/reference/articles/article2001.asp">Terrain Generation Using Fluid Simulation</a>
-
@version $Id$
*
[/patch]
-davidc