* jME3 now shows error dialog on exception by default (unless user overrides handleError)
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9544 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
cc3577acdc
commit
af7435ffdf
@ -1,6 +1,7 @@
|
||||
package com.jme3.system.android;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.Environment;
|
||||
import com.jme3.asset.AndroidAssetManager;
|
||||
import com.jme3.asset.AssetManager;
|
||||
@ -41,6 +42,22 @@ public class JmeAndroidSystem extends JmeSystemDelegate {
|
||||
return new AndroidAssetManager(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String message) {
|
||||
final String finalMsg = message;
|
||||
final String finalTitle = "Error in jMonkeyEngine app";
|
||||
final Activity context = JmeAndroidSystem.getActivity();
|
||||
|
||||
context.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
AlertDialog dialog = new AlertDialog.Builder(context)
|
||||
.setTitle(finalTitle).setMessage(finalMsg).create();
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry) {
|
||||
return true;
|
||||
|
@ -43,8 +43,8 @@ import com.jme3.renderer.Camera;
|
||||
import com.jme3.renderer.RenderManager;
|
||||
import com.jme3.renderer.Renderer;
|
||||
import com.jme3.renderer.ViewPort;
|
||||
import com.jme3.system.*;
|
||||
import com.jme3.system.JmeContext.Type;
|
||||
import com.jme3.system.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.Callable;
|
||||
@ -518,8 +518,16 @@ public class Application implements SystemListener {
|
||||
* Internal use only.
|
||||
*/
|
||||
public void handleError(String errMsg, Throwable t){
|
||||
// Print error to log.
|
||||
logger.log(Level.SEVERE, errMsg, t);
|
||||
// user should add additional code to handle the error.
|
||||
// Display error message on screen
|
||||
if (t != null) {
|
||||
JmeSystem.showErrorDialog(errMsg + "\n" + t.getClass().getSimpleName() +
|
||||
(t.getMessage() != null ? ": " + t.getMessage() : ""));
|
||||
} else {
|
||||
JmeSystem.showErrorDialog(errMsg);
|
||||
}
|
||||
|
||||
stop(); // stop the application
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,19 @@ public class JmeSystem {
|
||||
return systemDelegate.newAudioRenderer(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error message to the user in whichever way the context
|
||||
* feels is appropriate. If this is a headless or an offscreen surface
|
||||
* context, this method should do nothing.
|
||||
*
|
||||
* @param message The error message to display. May contain new line
|
||||
* characters.
|
||||
*/
|
||||
public static void showErrorDialog(String message){
|
||||
checkDelegate();
|
||||
systemDelegate.showErrorDialog(message);
|
||||
}
|
||||
|
||||
public static void initialize(AppSettings settings) {
|
||||
checkDelegate();
|
||||
systemDelegate.initialize(settings);
|
||||
|
@ -100,6 +100,8 @@ public abstract class JmeSystemDelegate {
|
||||
|
||||
public abstract AssetManager newAssetManager();
|
||||
|
||||
public abstract void showErrorDialog(String message);
|
||||
|
||||
public abstract boolean showSettingsDialog(AppSettings sourceSettings, boolean loadFromRegistry);
|
||||
|
||||
private boolean is64Bit(String arch) {
|
||||
|
@ -38,11 +38,13 @@ import com.jme3.asset.AssetNotFoundException;
|
||||
import com.jme3.asset.DesktopAssetManager;
|
||||
import com.jme3.audio.AudioRenderer;
|
||||
import com.jme3.system.JmeContext.Type;
|
||||
import java.awt.EventQueue;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
@ -61,6 +63,17 @@ public class JmeDesktopSystem extends JmeSystemDelegate {
|
||||
return new DesktopAssetManager(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showErrorDialog(String message) {
|
||||
final String msg = message;
|
||||
final String title = "Error in jMonkeyEngine app";
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showSettingsDialog(AppSettings sourceSettings, final boolean loadFromRegistry) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user