/*
* Copyright (c) 2009-2012 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.system;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
/**
* AppSettings provides a store of configuration
* to be used by the application.
*
* By default only the {@link JmeContext context} uses the configuration,
* however the user may set and retrieve the settings as well.
*
* @author Kirill Vainer
*/
public final class AppSettings extends HashMap {
private static final AppSettings defaults = new AppSettings(false);
/**
* Use LWJGL as the display system and force using the OpenGL1.1 renderer.
*
* @see AppSettings#setRenderer(java.lang.String)
*/
public static final String LWJGL_OPENGL1 = "LWJGL-OPENGL1";
/**
* Use LWJGL as the display system and force using the OpenGL2.0 renderer.
*
* If the underlying system does not support OpenGL2.0, then the context
* initialization will throw an exception.
*
* @see AppSettings#setRenderer(java.lang.String)
*/
public static final String LWJGL_OPENGL2 = "LWJGL-OpenGL2";
/**
* Use LWJGL as the display system and force using the core OpenGL3.3 renderer.
*
* If the underlying system does not support OpenGL3.3, then the context
* initialization will throw an exception. Note that currently jMonkeyEngine
* does not have any shaders that support OpenGL3.3 therefore this
* option is not useful.
*
*
* @see AppSettings#setRenderer(java.lang.String)
*/
public static final String LWJGL_OPENGL3 = "LWJGL-OpenGL3";
/**
* Use LWJGL as the display system and allow the context
* to choose an appropriate renderer based on system capabilities.
*
* If the GPU supports OpenGL2 or later, then the OpenGL2.0 renderer will
* be used, otherwise, the OpenGL1.1 renderer is used.
*
* @see AppSettings#setRenderer(java.lang.String)
*/
public static final String LWJGL_OPENGL_ANY = "LWJGL-OpenGL-Any";
/**
* The JOGL renderer is no longer supported by jME.
*
* @deprecated Use the LWJGL renderer instead.
*
* @see AppSettings#setRenderer(java.lang.String)
*/
@Deprecated
public static final String JOGL = "JOGL";
/**
* The "NULL" option is no longer supported
*
* @deprecated Specify the "null" value instead
*
* @see AppSettings#setRenderer(java.lang.String)
* @see AppSettings#setAudioRenderer(java.lang.String)
*/
@Deprecated
public static final String NULL = "NULL";
/**
* Use the LWJGL OpenAL based renderer for audio capabilities.
*
* @see AppSettings#setAudioRenderer(java.lang.String)
*/
public static final String LWJGL_OPENAL = "LWJGL";
static {
defaults.put("Width", 640);
defaults.put("Height", 480);
defaults.put("BitsPerPixel", 24);
defaults.put("Frequency", 60);
defaults.put("DepthBits", 24);
defaults.put("StencilBits", 0);
defaults.put("Samples", 0);
defaults.put("Fullscreen", false);
defaults.put("Title", "jMonkey Engine 3.0");
defaults.put("Renderer", LWJGL_OPENGL2);
defaults.put("AudioRenderer", LWJGL_OPENAL);
defaults.put("DisableJoysticks", true);
defaults.put("UseInput", true);
defaults.put("VSync", false);
defaults.put("FrameRate", -1);
defaults.put("SettingsDialogImage", "/com/jme3/app/Monkey.png");
// defaults.put("Icons", null);
}
/**
* Create a new instance of AppSettings.
*
* If loadDefaults is true, then the default settings
* will be set on the AppSettings.
* Use false if you want to change some settings but you would like the
* application to load settings from previous launches.
*
* @param loadDefaults If default settings are to be loaded.
*/
public AppSettings(boolean loadDefaults) {
if (loadDefaults) {
putAll(defaults);
}
}
/**
* Copies all settings from other to this
* AppSettings.
*
* Any settings that are specified in other will overwrite settings
* set on this AppSettings.
*
* @param other The AppSettings to copy the settings from
*/
public void copyFrom(AppSettings other) {
this.putAll(other);
}
/**
* Same as {@link #copyFrom(com.jme3.system.AppSettings) }, except
* doesn't overwrite settings that are already set.
*
* @param other The AppSettings to merge the settings from
*/
public void mergeFrom(AppSettings other) {
for (String key : other.keySet()) {
if (get(key) == null) {
put(key, other.get(key));
}
}
}
/**
* Loads the settings from the given properties input stream.
*
* @param in The InputStream to load from
* @throws IOException If an IOException occurs
*
* @see #save(java.io.OutputStream)
*/
public void load(InputStream in) throws IOException {
Properties props = new Properties();
props.load(in);
for (Map.Entry