SettingDialog :

- Image url does not need an additionnal "/" at the start of the path (still work with it though). It to be consistent with the paths used for the asset manager.
- If the image is not found an AssetNotFound exception is thrown.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7517 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent f1361cc9e6
commit 620e339b7c
  1. 202
      engine/src/desktop/com/jme3/system/JmeSystem.java

@ -29,22 +29,19 @@
* 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.system; package com.jme3.system;
import com.jme3.app.SettingsDialog; import com.jme3.app.SettingsDialog;
import com.jme3.app.SettingsDialog.SelectionListener; import com.jme3.app.SettingsDialog.SelectionListener;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.asset.AssetNotFoundException;
import com.jme3.asset.DesktopAssetManager; import com.jme3.asset.DesktopAssetManager;
import com.jme3.audio.AudioRenderer; import com.jme3.audio.AudioRenderer;
import com.jme3.util.JmeFormatter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -57,54 +54,44 @@ public class JmeSystem {
* Microsoft Windows 32 bit * Microsoft Windows 32 bit
*/ */
Windows32, Windows32,
/** /**
* Microsoft Windows 64 bit * Microsoft Windows 64 bit
*/ */
Windows64, Windows64,
/** /**
* Linux 32 bit * Linux 32 bit
*/ */
Linux32, Linux32,
/** /**
* Linux 64 bit * Linux 64 bit
*/ */
Linux64, Linux64,
/** /**
* Apple Mac OS X 32 bit * Apple Mac OS X 32 bit
*/ */
MacOSX32, MacOSX32,
/** /**
* Apple Mac OS X 64 bit * Apple Mac OS X 64 bit
*/ */
MacOSX64, MacOSX64,
/** /**
* Apple Mac OS X 32 bit PowerPC * Apple Mac OS X 32 bit PowerPC
*/ */
MacOSX_PPC32, MacOSX_PPC32,
/** /**
* Apple Mac OS X 64 bit PowerPC * Apple Mac OS X 64 bit PowerPC
*/ */
MacOSX_PPC64, MacOSX_PPC64,
} }
private static final Logger logger = Logger.getLogger(JmeSystem.class.getName()); private static final Logger logger = Logger.getLogger(JmeSystem.class.getName());
private static boolean initialized = false; private static boolean initialized = false;
private static boolean lowPermissions = false; private static boolean lowPermissions = false;
public static boolean trackDirectMemory(){ public static boolean trackDirectMemory() {
return false; return false;
} }
public static void setLowPermissions(boolean lowPerm){ public static void setLowPermissions(boolean lowPerm) {
lowPermissions = lowPerm; lowPermissions = lowPerm;
} }
@ -112,30 +99,36 @@ public class JmeSystem {
return lowPermissions; return lowPermissions;
} }
public static AssetManager newAssetManager(URL configFile){ public static AssetManager newAssetManager(URL configFile) {
return new DesktopAssetManager(configFile); return new DesktopAssetManager(configFile);
} }
public static AssetManager newAssetManager(){ public static AssetManager newAssetManager() {
return new DesktopAssetManager(null); return new DesktopAssetManager(null);
} }
public static boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry){ public static boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
if (SwingUtilities.isEventDispatchThread()) if (SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Cannot run from EDT"); throw new IllegalStateException("Cannot run from EDT");
}
final AppSettings settings = new AppSettings(false); final AppSettings settings = new AppSettings(false);
settings.copyFrom(sourceSettings); settings.copyFrom(sourceSettings);
final URL iconUrl = JmeSystem.class.getResource(sourceSettings.getSettingsDialogImage()); String iconPath = sourceSettings.getSettingsDialogImage();
final URL iconUrl = JmeSystem.class.getResource(iconPath.startsWith("/") ? iconPath : "/" + iconPath);
if (iconUrl == null) {
throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
}
final AtomicBoolean done = new AtomicBoolean(); final AtomicBoolean done = new AtomicBoolean();
final AtomicInteger result = new AtomicInteger(); final AtomicInteger result = new AtomicInteger();
final Object lock = new Object(); final Object lock = new Object();
final SelectionListener selectionListener = new SelectionListener(){ final SelectionListener selectionListener = new SelectionListener() {
public void onSelection(int selection){
synchronized (lock){ public void onSelection(int selection) {
synchronized (lock) {
done.set(true); done.set(true);
result.set(selection); result.set(selection);
lock.notifyAll(); lock.notifyAll();
@ -143,21 +136,23 @@ public class JmeSystem {
} }
}; };
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
synchronized (lock) { synchronized (lock) {
SettingsDialog dialog = new SettingsDialog(settings, iconUrl,loadFromRegistry); SettingsDialog dialog = new SettingsDialog(settings, iconUrl, loadFromRegistry);
dialog.setSelectionListener(selectionListener); dialog.setSelectionListener(selectionListener);
dialog.showDialog(); dialog.showDialog();
} }
} }
}); });
synchronized (lock){ synchronized (lock) {
while (!done.get()) while (!done.get()) {
try { try {
lock.wait(); lock.wait();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
} }
}
} }
sourceSettings.copyFrom(settings); sourceSettings.copyFrom(settings);
@ -165,48 +160,49 @@ public class JmeSystem {
return result.get() == SettingsDialog.APPROVE_SELECTION; return result.get() == SettingsDialog.APPROVE_SELECTION;
} }
private static boolean is64Bit(String arch){ private static boolean is64Bit(String arch) {
if (arch.equals("x86")) if (arch.equals("x86")) {
return false; return false;
else if (arch.equals("amd64")) } else if (arch.equals("amd64")) {
return true; return true;
else if (arch.equals("x86_64")) } else if (arch.equals("x86_64")) {
return true; return true;
else if (arch.equals("ppc") || arch.equals("PowerPC")) } else if (arch.equals("ppc") || arch.equals("PowerPC")) {
return false; return false;
else if (arch.equals("ppc64")) } else if (arch.equals("ppc64")) {
return true; return true;
else if (arch.equals("i386") || arch.equals("i686")) } else if (arch.equals("i386") || arch.equals("i686")) {
return false; return false;
else if (arch.equals("universal")) } else if (arch.equals("universal")) {
return false; return false;
else } else {
throw new UnsupportedOperationException("Unsupported architecture: "+arch); throw new UnsupportedOperationException("Unsupported architecture: " + arch);
}
} }
public static Platform getPlatform(){ public static Platform getPlatform() {
String os = System.getProperty("os.name").toLowerCase(); String os = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch").toLowerCase(); String arch = System.getProperty("os.arch").toLowerCase();
boolean is64 = is64Bit(arch); boolean is64 = is64Bit(arch);
if (os.contains("windows")){ if (os.contains("windows")) {
return is64 ? Platform.Windows64 : Platform.Windows32; return is64 ? Platform.Windows64 : Platform.Windows32;
}else if (os.contains("linux") || os.contains("freebsd") || os.contains("sunos")){ } else if (os.contains("linux") || os.contains("freebsd") || os.contains("sunos")) {
return is64 ? Platform.Linux64 : Platform.Linux32; return is64 ? Platform.Linux64 : Platform.Linux32;
}else if (os.contains("mac os x") || os.contains("darwin")){ } else if (os.contains("mac os x") || os.contains("darwin")) {
if (arch.startsWith("ppc")){ if (arch.startsWith("ppc")) {
return is64 ? Platform.MacOSX_PPC64 : Platform.MacOSX_PPC32; return is64 ? Platform.MacOSX_PPC64 : Platform.MacOSX_PPC32;
}else{ } else {
return is64 ? Platform.MacOSX64 : Platform.MacOSX32; return is64 ? Platform.MacOSX64 : Platform.MacOSX32;
} }
}else{ } else {
throw new UnsupportedOperationException("The specified platform: "+os+" is not supported."); throw new UnsupportedOperationException("The specified platform: " + os + " is not supported.");
} }
} }
private static JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type){ private static JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) {
try{ try {
Class<? extends JmeContext> ctxClazz = null; Class<? extends JmeContext> ctxClazz = null;
switch (type){ switch (type) {
case Canvas: case Canvas:
ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.lwjgl.LwjglCanvas"); ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.lwjgl.LwjglCanvas");
break; break;
@ -221,22 +217,22 @@ public class JmeSystem {
} }
return ctxClazz.newInstance(); return ctxClazz.newInstance();
}catch (InstantiationException ex){ } catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (IllegalAccessException ex){ } catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (ClassNotFoundException ex){ } catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n" + logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n"
"Make sure jme3_lwjgl-ogl is on the classpath.", ex); + "Make sure jme3_lwjgl-ogl is on the classpath.", ex);
} }
return null; return null;
} }
private static JmeContext newContextJogl(AppSettings settings, JmeContext.Type type){ private static JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) {
try{ try {
Class<? extends JmeContext> ctxClazz = null; Class<? extends JmeContext> ctxClazz = null;
switch (type){ switch (type) {
case Display: case Display:
ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.jogl.JoglDisplay"); ctxClazz = (Class<? extends JmeContext>) Class.forName("com.jme3.system.jogl.JoglDisplay");
break; break;
@ -248,30 +244,30 @@ public class JmeSystem {
} }
return ctxClazz.newInstance(); return ctxClazz.newInstance();
}catch (InstantiationException ex){ } catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (IllegalAccessException ex){ } catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (ClassNotFoundException ex){ } catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n" + logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n"
"Make sure jme3_jogl is on the classpath.", ex); + "Make sure jme3_jogl is on the classpath.", ex);
} }
return null; return null;
} }
private static JmeContext newContextCustom(AppSettings settings, JmeContext.Type type){ private static JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) {
try{ try {
String className = settings.getRenderer().substring("CUSTOM".length()); String className = settings.getRenderer().substring("CUSTOM".length());
Class<? extends JmeContext> ctxClazz = null; Class<? extends JmeContext> ctxClazz = null;
ctxClazz = (Class<? extends JmeContext>) Class.forName(className); ctxClazz = (Class<? extends JmeContext>) Class.forName(className);
return ctxClazz.newInstance(); return ctxClazz.newInstance();
}catch (InstantiationException ex){ } catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (IllegalAccessException ex){ } catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (ClassNotFoundException ex){ } catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!", ex); logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!", ex);
} }
@ -282,84 +278,82 @@ public class JmeSystem {
initialize(settings); initialize(settings);
JmeContext ctx; JmeContext ctx;
if (settings.getRenderer() == null if (settings.getRenderer() == null
|| settings.getRenderer().equals("NULL") || settings.getRenderer().equals("NULL")
|| contextType == JmeContext.Type.Headless){ || contextType == JmeContext.Type.Headless) {
ctx = new NullContext(); ctx = new NullContext();
ctx.setSettings(settings); ctx.setSettings(settings);
}else if (settings.getRenderer().startsWith("LWJGL")){ } else if (settings.getRenderer().startsWith("LWJGL")) {
ctx = newContextLwjgl(settings, contextType); ctx = newContextLwjgl(settings, contextType);
ctx.setSettings(settings); ctx.setSettings(settings);
}else if (settings.getRenderer().startsWith("JOGL")){ } else if (settings.getRenderer().startsWith("JOGL")) {
ctx = newContextJogl(settings, contextType); ctx = newContextJogl(settings, contextType);
ctx.setSettings(settings); ctx.setSettings(settings);
}else if (settings.getRenderer().startsWith("CUSTOM")){ } else if (settings.getRenderer().startsWith("CUSTOM")) {
ctx = newContextCustom(settings, contextType); ctx = newContextCustom(settings, contextType);
ctx.setSettings(settings); ctx.setSettings(settings);
}else{ } else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unrecognizable renderer specified: "+ "Unrecognizable renderer specified: "
settings.getRenderer()); + settings.getRenderer());
} }
return ctx; return ctx;
} }
public static AudioRenderer newAudioRenderer(AppSettings settings){ public static AudioRenderer newAudioRenderer(AppSettings settings) {
initialize(settings); initialize(settings);
Class<? extends AudioRenderer> clazz = null; Class<? extends AudioRenderer> clazz = null;
try { try {
if (settings.getAudioRenderer().startsWith("LWJGL")){ if (settings.getAudioRenderer().startsWith("LWJGL")) {
clazz = (Class<? extends AudioRenderer>) Class.forName("com.jme3.audio.lwjgl.LwjglAudioRenderer"); clazz = (Class<? extends AudioRenderer>) Class.forName("com.jme3.audio.lwjgl.LwjglAudioRenderer");
}else if (settings.getAudioRenderer().startsWith("JOAL")){ } else if (settings.getAudioRenderer().startsWith("JOAL")) {
clazz = (Class<? extends AudioRenderer>) Class.forName("com.jme3.audio.joal.JoalAudioRenderer"); clazz = (Class<? extends AudioRenderer>) Class.forName("com.jme3.audio.joal.JoalAudioRenderer");
}else{ } else {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Unrecognizable audio renderer specified: "+ "Unrecognizable audio renderer specified: "
settings.getAudioRenderer()); + settings.getAudioRenderer());
} }
AudioRenderer ar = clazz.newInstance(); AudioRenderer ar = clazz.newInstance();
return ar; return ar;
}catch (InstantiationException ex){ } catch (InstantiationException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (IllegalAccessException ex){ } catch (IllegalAccessException ex) {
logger.log(Level.SEVERE, "Failed to create context", ex); logger.log(Level.SEVERE, "Failed to create context", ex);
}catch (ClassNotFoundException ex){ } catch (ClassNotFoundException ex) {
logger.log(Level.SEVERE, "CRITICAL ERROR: Audio implementation class is missing!\n" + logger.log(Level.SEVERE, "CRITICAL ERROR: Audio implementation class is missing!\n"
"Make sure jme3_lwjgl-oal or jm3_joal is on the classpath.", ex); + "Make sure jme3_lwjgl-oal or jm3_joal is on the classpath.", ex);
} }
return null; return null;
} }
public static void initialize(AppSettings settings){ public static void initialize(AppSettings settings) {
if (initialized) if (initialized) {
return; return;
}
initialized = true; initialized = true;
try { try {
if (!lowPermissions){ if (!lowPermissions) {
// can only modify logging settings // can only modify logging settings
// if permissions are available // if permissions are available
// JmeFormatter formatter = new JmeFormatter(); // JmeFormatter formatter = new JmeFormatter();
// Handler fileHandler = new FileHandler("jme.log"); // Handler fileHandler = new FileHandler("jme.log");
// fileHandler.setFormatter(formatter); // fileHandler.setFormatter(formatter);
// Logger.getLogger("").addHandler(fileHandler); // Logger.getLogger("").addHandler(fileHandler);
// Handler consoleHandler = new ConsoleHandler(); // Handler consoleHandler = new ConsoleHandler();
// consoleHandler.setFormatter(formatter); // consoleHandler.setFormatter(formatter);
// Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]); // Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
// Logger.getLogger("").addHandler(consoleHandler); // Logger.getLogger("").addHandler(consoleHandler);
} }
// } catch (IOException ex){ // } catch (IOException ex){
// logger.log(Level.SEVERE, "I/O Error while creating log file", ex); // logger.log(Level.SEVERE, "I/O Error while creating log file", ex);
} catch (SecurityException ex){ } catch (SecurityException ex) {
logger.log(Level.SEVERE, "Security error in creating log file", ex); logger.log(Level.SEVERE, "Security error in creating log file", ex);
} }
logger.log(Level.INFO, "Running on {0}", getFullName()); logger.log(Level.INFO, "Running on {0}", getFullName());
if (!lowPermissions){ if (!lowPermissions) {
try { try {
Natives.extractNativeLibs(getPlatform(), settings); Natives.extractNativeLibs(getPlatform(), settings);
} catch (IOException ex) { } catch (IOException ex) {
@ -368,15 +362,15 @@ public class JmeSystem {
} }
} }
public static String getFullName(){ public static String getFullName() {
return "jMonkey Engine 3 Alpha 0.6"; return "jMonkey Engine 3 Alpha 0.6";
} }
public static InputStream getResourceAsStream(String name){ public static InputStream getResourceAsStream(String name) {
return JmeSystem.class.getResourceAsStream(name); return JmeSystem.class.getResourceAsStream(name);
} }
public static URL getResource(String name){ public static URL getResource(String name) {
return JmeSystem.class.getResource(name); return JmeSystem.class.getResource(name);
} }
} }

Loading…
Cancel
Save