You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2013/09/27 15:55:41 UTC
svn commit: r1526905 - in /pivot/branches/2.0.x:
tests/src/org/apache/pivot/tests/ wtk/src/org/apache/pivot/wtk/
Author: smartini
Date: Fri Sep 27 13:55:41 2013
New Revision: 1526905
URL: http://svn.apache.org/r1526905
Log:
PIVOT-916, Replace DesktopApplicationContext.displayException calls with ApplicationContext.handleUncaughtException
Modified:
pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/ApplicationHandlerTest.java
pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/Application.java
pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/ApplicationHandlerTest.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/ApplicationHandlerTest.java?rev=1526905&r1=1526904&r2=1526905&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/ApplicationHandlerTest.java (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/ApplicationHandlerTest.java Fri Sep 27 13:55:41 2013
@@ -25,11 +25,13 @@ import org.apache.pivot.wtk.Keyboard;
import org.apache.pivot.wtk.Window;
public class ApplicationHandlerTest extends Application.Adapter
- implements Application.UnprocessedKeyHandler, Application.UncaughtExceptionHandler {
+ implements Application.UnprocessedKeyHandler {
private Window window = null;
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
+ super.startup(display, properties); // optional, but useful to set display and properties
+
BXMLSerializer bxmlSerializer = new BXMLSerializer();
window = (Window)bxmlSerializer.readObject(ApplicationHandlerTest.class,
"application_handler_test.bxml");
@@ -64,13 +66,8 @@ public class ApplicationHandlerTest exte
System.out.println("Unprocessed key released: " + keyCode + "; " + keyLocation);
}
- @Override
- public void uncaughtExceptionThrown(Exception exception) {
- System.out.println("Uncaught exception thrown.");
- exception.printStackTrace();
- }
-
public static void main(String[] args) {
DesktopApplicationContext.main(ApplicationHandlerTest.class, args);
}
+
}
Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/Application.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/Application.java?rev=1526905&r1=1526904&r2=1526905&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/Application.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/Application.java Fri Sep 27 13:55:41 2013
@@ -29,10 +29,12 @@ public interface Application {
/**
* Application adapter.
*/
- public static class Adapter implements Application {
+ public static class Adapter implements Application, UncaughtExceptionHandler {
+ private Display disp;
+
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
- // empty block
+ this.disp = display;
}
@Override
@@ -49,6 +51,36 @@ public interface Application {
public void resume() throws Exception {
// empty block
}
+
+ @Override
+ public void uncaughtExceptionThrown(Exception exception) {
+ exception.printStackTrace();
+ displayException(exception);
+ }
+
+ protected Display getDisplay() {
+ return disp;
+ }
+
+ private void displayException(Exception exception) {
+ if (getDisplay() == null) {
+ return;
+ }
+
+ String message = exception.getClass().getName();
+
+ TextArea body = null;
+ String bodyText = exception.getMessage();
+ if (bodyText != null && bodyText.length() > 0) {
+ body = new TextArea();
+ body.setText(bodyText);
+ body.setEditable(false);
+ }
+
+ Alert alert = new Alert(MessageType.ERROR, message, null, body, false);
+ alert.open(getDisplay());
+ }
+
}
/**
Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java?rev=1526905&r1=1526904&r2=1526905&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/ApplicationContext.java Fri Sep 27 13:55:41 2013
@@ -2006,7 +2006,7 @@ public abstract class ApplicationContext
return cursor;
}
- private static void handleUncaughtException(Exception exception) {
+ protected static void handleUncaughtException(Exception exception) {
int n = 0;
for (Application application : applications) {
if (application instanceof Application.UncaughtExceptionHandler) {
Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=1526905&r1=1526904&r2=1526905&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Fri Sep 27 13:55:41 2013
@@ -223,7 +223,7 @@ public final class BrowserApplicationCon
HostApplet.this.application.startup(HostApplet.this.displayHost.getDisplay(),
new ImmutableMap<String, String>(HostApplet.this.startupProperties));
} catch (Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
// Add the application to the application list
@@ -242,7 +242,7 @@ public final class BrowserApplicationCon
try {
HostApplet.this.application.shutdown(false);
} catch (Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
// Remove the application from the application list
@@ -331,23 +331,6 @@ public final class BrowserApplicationCon
paint(graphics);
}
- private void displayException(Exception exception) {
- exception.printStackTrace();
-
- String message = exception.getClass().getName();
-
- TextArea body = null;
- String bodyText = exception.getMessage();
- if (bodyText != null
- && bodyText.length() > 0) {
- body = new TextArea();
- body.setText(bodyText);
- body.setEditable(false);
- }
-
- Alert alert = new Alert(MessageType.ERROR, message, null, body, false);
- alert.open(this.displayHost.getDisplay());
- }
}
private static ArrayList<HostApplet> hostApplets = new ArrayList<HostApplet>();
Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=1526905&r1=1526904&r2=1526905&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Fri Sep 27 13:55:41 2013
@@ -258,7 +258,7 @@ public final class DesktopApplicationCon
try {
application.suspend();
} catch(Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
break;
@@ -267,7 +267,7 @@ public final class DesktopApplicationCon
try {
application.resume();
} catch(Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
break;
@@ -416,7 +416,7 @@ public final class DesktopApplicationCon
try {
cancelShutdown = application.shutdown(optional);
} catch(Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
if (!cancelShutdown) {
@@ -641,7 +641,7 @@ public final class DesktopApplicationCon
application.startup(primaryDisplayHost.getDisplay(),
new ImmutableMap<String, String>(properties));
} catch (Exception exception) {
- displayException(exception);
+ handleUncaughtException(exception);
}
}
});
@@ -706,24 +706,6 @@ public final class DesktopApplicationCon
}
}
- private static void displayException(Exception exception) {
- exception.printStackTrace();
-
- String message = exception.getClass().getName();
-
- TextArea body = null;
- String bodyText = exception.getMessage();
- if (bodyText != null
- && bodyText.length() > 0) {
- body = new TextArea();
- body.setText(bodyText);
- body.setEditable(false);
- }
-
- Alert alert = new Alert(MessageType.ERROR, message, null, body, false);
- alert.open(primaryDisplayHost.getDisplay());
- }
-
/**
* Returns the full-screen mode flag.
*/