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/08/05 01:46:23 UTC

svn commit: r801029 - in /incubator/pivot/trunk: tutorials/www/index.html wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java

Author: gbrown
Date: Tue Aug  4 23:46:23 2009
New Revision: 801029

URL: http://svn.apache.org/viewvc?rev=801029&view=rev
Log:
Re-apply fix to DesktopApplicationContext that allows alerts to center on the display at startup, but don't break JNLP deployment.

Modified:
    incubator/pivot/trunk/tutorials/www/index.html
    incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java

Modified: incubator/pivot/trunk/tutorials/www/index.html
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/www/index.html?rev=801029&r1=801028&r2=801029&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/www/index.html (original)
+++ incubator/pivot/trunk/tutorials/www/index.html Tue Aug  4 23:46:23 2009
@@ -37,8 +37,8 @@
 <a href="navigation_containers.html">Navigation Containers</a><br>
 <a href="progress_indicators.html">Progress Indicators</a><br>
 <a href="bounded_range_components.html">Bounded Range Components</a><br>
-<a href="menus.html">Menus</a><br>
 <a href="calendars.html">Calendars</a><br>
+<a href="menus.html">Menus</a><br>
 <a href="table_views.html">Table Views</a><br>
 <a href="tree_views.html">Tree Views</a><br>
 <a href="file_browsing.html">File Browsing</a><br>

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=801029&r1=801028&r2=801029&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 Tue Aug  4 23:46:23 2009
@@ -35,7 +35,6 @@
 import org.apache.pivot.wtk.media.Image;
 import org.apache.pivot.wtk.media.Picture;
 
-
 /**
  * Application context used to execute applications in a native frame
  * window.
@@ -69,11 +68,25 @@
             if (this == windowedHostFrame) {
                 switch(event.getID()) {
                     case WindowEvent.WINDOW_OPENED: {
-                        applicationContext.getDisplayHost().requestFocus();
-
                         createTimer();
 
-                        Application application = applicationContext.getApplication();
+                        // Load the application
+                        Application application = null;
+                        try {
+                            Class<?> applicationClass = Class.forName(applicationClassName);
+                            application = (Application)applicationClass.newInstance();
+                            applicationContext.setApplication(application);
+                        } catch(Exception exception) {
+                            Alert.alert(MessageType.ERROR, exception.getMessage(),
+                                applicationContext.getDisplay());
+                            exception.printStackTrace();
+                        }
+
+                        // Set focus to the display host
+                        DisplayHost displayHost = applicationContext.getDisplayHost();
+                        displayHost.requestFocus();
+
+                        // Start the application
                         if (application != null) {
                             try {
                                 application.startup(applicationContext.getDisplay(),
@@ -81,6 +94,58 @@
                             } catch(Exception exception) {
                                 displayException(exception);
                             }
+
+                            // Hook into OS X application menu
+                            String osName = System.getProperty("os.name");
+                            if (osName.toLowerCase().startsWith("mac os x")) {
+                                try {
+                                    // Get the EAWT classes and methods
+                                    Class<?> eawtApplicationClass = Class.forName("com.apple.eawt.Application");
+                                    Class<?> eawtApplicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
+                                    Class<?> eawtApplicationEventClass = Class.forName("com.apple.eawt.ApplicationEvent");
+
+                                    Method setEnabledAboutMenuMethod = eawtApplicationClass.getMethod("setEnabledAboutMenu",
+                                        new Class<?>[] {Boolean.TYPE});
+
+                                    Method addApplicationListenerMethod = eawtApplicationClass.getMethod("addApplicationListener",
+                                        new Class<?>[] {eawtApplicationListenerClass});
+
+                                    final Method setHandledMethod = eawtApplicationEventClass.getMethod("setHandled",
+                                        new Class<?>[] {Boolean.TYPE});
+
+                                    // Create the proxy handler
+                                    InvocationHandler handler = new InvocationHandler() {
+                                        public Object invoke(Object proxy, Method method, Object[] args)
+                                            throws Throwable {
+                                            String methodName = method.getName();
+                                            if (methodName.equals("handleAbout"))  {
+                                                handleAbout();
+                                            } else if (methodName.equals("handleQuit")) {
+                                                exit();
+                                            }
+
+                                            // Invoke setHandled(true)
+                                            setHandledMethod.invoke(args[0], new Object[] {true});
+
+                                            return null;
+                                        }
+                                    };
+
+                                    Object eawtApplication = eawtApplicationClass.newInstance();
+
+                                    setEnabledAboutMenuMethod.invoke(eawtApplication,
+                                        application instanceof Application.AboutHandler);
+
+                                    Object eawtApplicationListener =
+                                        Proxy.newProxyInstance(DesktopApplicationContext.class.getClassLoader(),
+                                            new Class[]{eawtApplicationListenerClass}, handler);
+
+                                    // Invoke the addApplicationListener() method with the proxy listener
+                                    addApplicationListenerMethod.invoke(eawtApplication, new Object[] {eawtApplicationListener});
+                                } catch(Throwable throwable) {
+                                    System.err.println(throwable);
+                                }
+                            }
                         }
 
                         break;
@@ -91,6 +156,11 @@
                         break;
                     }
 
+                    case WindowEvent.WINDOW_CLOSED: {
+                        destroyTimer();
+                        break;
+                    }
+
                     case WindowEvent.WINDOW_DEACTIVATED: {
                         java.awt.Window oppositeWindow = event.getOppositeWindow();
 
@@ -153,6 +223,7 @@
     }
 
     private static DesktopApplicationContext applicationContext = null;
+    private static String applicationClassName = null;
     private static HashMap<String, String> properties = null;
 
     private static HostFrame windowedHostFrame = null;
@@ -187,10 +258,8 @@
         }
 
         if (!cancelShutdown) {
-            destroyTimer();
             windowedHostFrame.dispose();
             fullScreenHostFrame.dispose();
-            System.exit(0);
         }
     }
 
@@ -209,7 +278,7 @@
             System.err.println("Application class name is required.");
         }
 
-        String applicationClassName = args[0];
+        applicationClassName = args[0];
 
         // Get the startup properties
         properties = new HashMap<String, String>();
@@ -371,73 +440,9 @@
         fullScreenHostFrame = new HostFrame();
         fullScreenHostFrame.setUndecorated(true);
 
-        // Load the application
-        Application application = null;
-        try {
-            Class<?> applicationClass = Class.forName(applicationClassName);
-            application = (Application)applicationClass.newInstance();
-            applicationContext.setApplication(application);
-        } catch(Exception exception) {
-            Alert.alert(MessageType.ERROR, exception.getMessage(),
-                applicationContext.getDisplay());
-            exception.printStackTrace();
-        }
-
         // Open the windowed host
         windowedHostFrame.setVisible(true);
 
-        // Hook into OS X application menu
-        String osName = System.getProperty("os.name");
-        if (osName.toLowerCase().startsWith("mac os x")) {
-            try {
-                // Get the EAWT classes and methods
-                Class<?> eawtApplicationClass = Class.forName("com.apple.eawt.Application");
-                Class<?> eawtApplicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
-                Class<?> eawtApplicationEventClass = Class.forName("com.apple.eawt.ApplicationEvent");
-
-                Method setEnabledAboutMenuMethod = eawtApplicationClass.getMethod("setEnabledAboutMenu",
-                    new Class<?>[] {Boolean.TYPE});
-
-                Method addApplicationListenerMethod = eawtApplicationClass.getMethod("addApplicationListener",
-                    new Class<?>[] {eawtApplicationListenerClass});
-
-                final Method setHandledMethod = eawtApplicationEventClass.getMethod("setHandled",
-                    new Class<?>[] {Boolean.TYPE});
-
-                // Create the proxy handler
-                InvocationHandler handler = new InvocationHandler() {
-                    public Object invoke(Object proxy, Method method, Object[] args)
-                        throws Throwable {
-                        String methodName = method.getName();
-                        if (methodName.equals("handleAbout"))  {
-                            handleAbout();
-                        } else if (methodName.equals("handleQuit")) {
-                            exit();
-                        }
-
-                        // Invoke setHandled(true)
-                        setHandledMethod.invoke(args[0], new Object[] {true});
-
-                        return null;
-                    }
-                };
-
-                Object eawtApplication = eawtApplicationClass.newInstance();
-
-                setEnabledAboutMenuMethod.invoke(eawtApplication,
-                    application instanceof Application.AboutHandler);
-
-                Object eawtApplicationListener =
-                    Proxy.newProxyInstance(DesktopApplicationContext.class.getClassLoader(),
-                        new Class[]{eawtApplicationListenerClass}, handler);
-
-                // Invoke the addApplicationListener() method with the proxy listener
-                addApplicationListenerMethod.invoke(eawtApplication, new Object[] {eawtApplicationListener});
-            } catch(Throwable throwable) {
-                System.err.println(throwable);
-            }
-        }
-
         // Go to full-screen mode, if requested
         setFullScreen(fullScreen);
     }