You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/07/27 21:44:42 UTC

svn commit: r798268 - in /incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: Alert.java BrowserApplicationContext.java DesktopApplicationContext.java Prompt.java

Author: gbrown
Date: Mon Jul 27 19:44:42 2009
New Revision: 798268

URL: http://svn.apache.org/viewvc?rev=798268&view=rev
Log:
Make default error dialogs more descriptive.

Modified:
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java?rev=798268&r1=798267&r2=798268&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Alert.java Mon Jul 27 19:44:42 2009
@@ -123,48 +123,46 @@
     }
 
     public static void alert(String message, Display display) {
-        alert(MessageType.INFO, message, display, null);
+        alert(MessageType.INFO, message, null, display, null);
     }
 
-    public static void alert(String message, Display display,
-        DialogCloseListener dialogCloseListener) {
-        alert(MessageType.INFO, message, display, dialogCloseListener);
+    public static void alert(MessageType messageType, String message, Display display) {
+        alert(messageType, message, null, display, null);
     }
 
-    public static void alert(MessageType type, String message, Display display) {
-        alert(type, message, display, null);
+    public static void alert(MessageType messageType, String message, Component body, Display display) {
+        alert(messageType, message, body, display, null);
     }
 
-    public static void alert(MessageType type, String message, Display display,
+    public static void alert(MessageType messageType, String message, Component body, Display display,
         DialogCloseListener dialogCloseListener) {
-        Alert alert = createAlert(type, message);
+        Alert alert = createAlert(messageType, message, body);
         alert.open(display, dialogCloseListener);
     }
 
     public static void alert(String message, Window owner) {
-        alert(MessageType.INFO, message, owner, null);
+        alert(MessageType.INFO, message, null, owner, null);
     }
 
-    public static void alert(String message, Window owner,
-        DialogCloseListener dialogCloseListener) {
-        alert(MessageType.INFO, message, owner, dialogCloseListener);
+    public static void alert(MessageType messageType, String message, Window owner) {
+        alert(messageType, message, null, owner, null);
     }
 
-    public static void alert(MessageType type, String message, Window owner) {
-        alert(type, message, owner, null);
+    public static void alert(MessageType messageType, String message, Component body, Window owner) {
+        alert(messageType, message, body, owner, null);
     }
 
-    public static void alert(MessageType type, String message, Window owner,
+    public static void alert(MessageType messageType, String message, Component body, Window owner,
         DialogCloseListener dialogCloseListener) {
-        Alert alert = createAlert(type, message);
+        Alert alert = createAlert(messageType, message, body);
         alert.open(owner, dialogCloseListener);
     }
 
-    private static Alert createAlert(MessageType type, String message) {
+    private static Alert createAlert(MessageType messageType, String message, Component body) {
         List<Object> options = new ArrayList<Object>();
         options.add(resources.get("defaultOption"));
 
-        Alert alert = new Alert(type, message, options, null);
+        Alert alert = new Alert(messageType, message, options, body);
         alert.setTitle((String)resources.get("defaultTitle"));
         alert.setSelectedOption(0);
 

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=798268&r1=798267&r2=798268&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Mon Jul 27 19:44:42 2009
@@ -151,9 +151,7 @@
                         application.startup(applicationContext.getDisplay(),
                             new ImmutableMap<String, String>(properties));
                     } catch (Exception exception) {
-                        Alert.alert(MessageType.ERROR, exception.getMessage(),
-                            applicationContext.getDisplay());
-                        exception.printStackTrace();
+                        displayException(exception);
                     }
                 }
             }
@@ -166,9 +164,7 @@
                     try {
                         application.shutdown(false);
                     } catch (Exception exception) {
-                        Alert.alert(MessageType.ERROR, exception.getMessage(),
-                            applicationContext.getDisplay());
-                        exception.printStackTrace();
+                        displayException(exception);
                     }
                 }
             }
@@ -244,6 +240,22 @@
         public void update(Graphics graphics) {
             paint(graphics);
         }
+
+        private void displayException(Exception exception) {
+            exception.printStackTrace();
+
+            String message = exception.getClass().getName();
+
+            Label body = null;
+            String bodyText = exception.getMessage();
+            if (bodyText != null
+                && bodyText.length() > 0) {
+                body = new Label(bodyText);
+                body.getStyles().put("wrapText", true);
+            }
+
+            Alert.alert(MessageType.ERROR, message, body, applicationContext.getDisplay());
+        }
     }
 
     private static ArrayList<HostApplet> hostApplets = new ArrayList<HostApplet>();

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=798268&r1=798267&r2=798268&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Mon Jul 27 19:44:42 2009
@@ -79,9 +79,7 @@
                                 application.startup(applicationContext.getDisplay(),
                                     new ImmutableMap<String, String>(properties));
                             } catch(Exception exception) {
-                                exception.printStackTrace();
-                                Alert.alert(MessageType.ERROR, exception.getMessage(),
-                                    applicationContext.getDisplay());
+                                displayException(exception);
                             }
                         }
 
@@ -134,9 +132,7 @@
                         try {
                             application.suspend();
                         } catch(Exception exception) {
-                            exception.printStackTrace();
-                            Alert.alert(MessageType.ERROR, exception.getMessage(),
-                                applicationContext.getDisplay());
+                            displayException(exception);
                         }
 
                         break;
@@ -146,9 +142,7 @@
                         try {
                             application.resume();
                         } catch(Exception exception) {
-                            exception.printStackTrace();
-                            Alert.alert(MessageType.ERROR, exception.getMessage(),
-                                applicationContext.getDisplay());
+                            displayException(exception);
                         }
 
                         break;
@@ -188,9 +182,7 @@
             try {
                 cancelShutdown = application.shutdown(true);
             } catch(Exception exception) {
-                exception.printStackTrace();
-                Alert.alert(MessageType.ERROR, exception.getMessage(),
-                    applicationContext.getDisplay());
+                displayException(exception);
             }
         }
 
@@ -460,6 +452,22 @@
         }
     }
 
+    private static void displayException(Exception exception) {
+        exception.printStackTrace();
+
+        String message = exception.getClass().getName();
+
+        Label body = null;
+        String bodyText = exception.getMessage();
+        if (bodyText != null
+            && bodyText.length() > 0) {
+            body = new Label(bodyText);
+            body.getStyles().put("wrapText", true);
+        }
+
+        Alert.alert(MessageType.ERROR, message, body, applicationContext.getDisplay());
+    }
+
     /**
      * Invokes the application's about handler. The application must implement
      * the {@link Application.AboutHandler} interface.

Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java?rev=798268&r1=798267&r2=798268&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Prompt.java Mon Jul 27 19:44:42 2009
@@ -127,29 +127,28 @@
     }
 
     public static void prompt(String message, Window owner) {
-        prompt(MessageType.INFO, message, owner, null);
+        prompt(MessageType.INFO, message, null, owner, null);
     }
 
-    public static void prompt(String message, Window owner,
-        SheetStateListener sheetStateListener) {
-        prompt(MessageType.INFO, message, owner, sheetStateListener);
+    public static void prompt(MessageType messageType, String message, Window owner) {
+        prompt(messageType, message, null, owner, null);
     }
 
-    public static void prompt(MessageType type, String message, Window owner) {
-        prompt(type, message, owner, null);
+    public static void prompt(MessageType messageType, String message, Component body, Window owner) {
+        prompt(messageType, message, body, owner, null);
     }
 
-    public static void prompt(MessageType type, String message, Window owner,
-        SheetStateListener sheetStateListener) {
-        Prompt prompt = createPrompt(type, message);
-        prompt.open(owner, sheetStateListener);
+    public static void prompt(MessageType messageType, String message, Component body, Window owner,
+        SheetCloseListener sheetCloseListener) {
+        Prompt prompt = createPrompt(messageType, message, body);
+        prompt.open(owner, sheetCloseListener);
     }
 
-    private static Prompt createPrompt(MessageType type, String message) {
+    private static Prompt createPrompt(MessageType messageType, String message, Component body) {
         List<Object> options = new ArrayList<Object>();
         options.add(resources.get("defaultOption"));
 
-        Prompt prompt = new Prompt(type, message, options, null);
+        Prompt prompt = new Prompt(messageType, message, options, null);
         prompt.setTitle((String)resources.get("defaultTitle"));
         prompt.setSelectedOption(0);