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/05/08 15:51:09 UTC

svn commit: r772987 - in /incubator/pivot/trunk/wtk/src/pivot/wtk: DesktopApplicationContext.java Dialog.java about.wtkx

Author: gbrown
Date: Fri May  8 13:51:08 2009
New Revision: 772987

URL: http://svn.apache.org/viewvc?rev=772987&view=rev
Log:
Hook into OSX application menus; automatically center ownerless dialog on display.

Added:
    incubator/pivot/trunk/wtk/src/pivot/wtk/about.wtkx
Modified:
    incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/Dialog.java

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java?rev=772987&r1=772986&r2=772987&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java Fri May  8 13:51:08 2009
@@ -27,10 +27,12 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import pivot.collections.ArrayList;
 import pivot.collections.HashMap;
 import pivot.collections.immutable.ImmutableMap;
 import pivot.wtk.media.Image;
 import pivot.wtk.media.Picture;
+import pivot.wtkx.WTKXSerializer;
 
 /**
  * Application context used to execute applications in a native frame
@@ -51,6 +53,44 @@
 
             // Clear the background
             setBackground(null);
+
+            // Hook into OSX application menu
+            if (System.getProperty("mrj.version") != null) {
+                new com.apple.eawt.Application() {
+                    {   addApplicationListener(new com.apple.eawt.ApplicationAdapter() {
+                            @Override
+                            public void handleAbout(com.apple.eawt.ApplicationEvent event) {
+                                // TODO i18n
+                                Display display = applicationContext.getDisplay();
+
+                                ArrayList<String> options = new ArrayList<String>();
+                                options.add("OK");
+
+                                Component body;
+                                WTKXSerializer wtkxSerializer = new WTKXSerializer();
+                                try {
+                                    body = (Component)wtkxSerializer.readObject(getClass().getResource("about.wtkx"));
+                                } catch(Exception exception) {
+                                    throw new RuntimeException(exception);
+                                }
+
+                                Alert alert = new Alert(MessageType.INFO, "About Apache Pivot", options, body);
+                                alert.setTitle("About");
+                                alert.setSelectedOption(0);
+
+                                alert.open(display);
+
+                                event.setHandled(true);
+                            }
+
+                            @Override
+                            public void handleQuit(com.apple.eawt.ApplicationEvent event) {
+                                exit();
+                            }
+                        });
+                    }
+                };
+            }
         }
 
         @Override
@@ -86,28 +126,6 @@
                     }
 
                     case WindowEvent.WINDOW_CLOSING: {
-                        boolean shutdown = true;
-
-                        try {
-                            shutdown = application.shutdown(true);
-                        } catch(Exception exception) {
-                            exception.printStackTrace();
-                            Alert.alert(MessageType.ERROR, exception.getMessage(),
-                                applicationContext.getDisplay());
-                        }
-
-                        if (shutdown) {
-                            destroyTimer();
-
-                            java.awt.Window window = event.getWindow();
-                            window.setVisible(false);
-                            window.dispose();
-                        }
-
-                        break;
-                    }
-
-                    case WindowEvent.WINDOW_CLOSED: {
                         exit();
                         break;
                     }
@@ -176,7 +194,22 @@
      * Terminates the application context.
      */
     public static void exit() {
-        System.exit(0);
+        boolean shutdown = true;
+
+        try {
+            shutdown = application.shutdown(true);
+        } catch(Exception exception) {
+            exception.printStackTrace();
+            Alert.alert(MessageType.ERROR, exception.getMessage(),
+                applicationContext.getDisplay());
+        }
+
+        if (shutdown) {
+            destroyTimer();
+            windowedHostFrame.dispose();
+            fullScreenHostFrame.dispose();
+            System.exit(0);
+        }
     }
 
     public static void main(String[] args) {

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/Dialog.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/Dialog.java?rev=772987&r1=772986&r2=772987&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/Dialog.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/Dialog.java Fri May  8 13:51:08 2009
@@ -55,10 +55,10 @@
         private static final float GOLDEN_SECTION = 0.382f;
 
         public void run() {
-            Window owner = getOwner();
+            Component owner = getOwner();
 
             if (owner == null) {
-                throw new IllegalStateException("Dialog has no owner.");
+                owner = getDisplay();
             }
 
             int deltaWidth = owner.getWidth() - getWidth();
@@ -116,6 +116,8 @@
         if (isOpen()) {
             this.dialogCloseListener = dialogCloseListener;
             this.modal = false;
+
+            ApplicationContext.queueCallback(new RepositionCallback());
         }
     }
 
@@ -198,9 +200,6 @@
                 // and make it the active window
                 setEnabled(true);
                 setActiveWindow(this);
-
-                // Align the dialog with its owner
-                ApplicationContext.queueCallback(new RepositionCallback());
             }
         }
     }

Added: incubator/pivot/trunk/wtk/src/pivot/wtk/about.wtkx
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/about.wtkx?rev=772987&view=auto
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/about.wtkx (added)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/about.wtkx Fri May  8 13:51:08 2009
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License,
+Version 2.0 (the "License"); you may not use this file except in
+compliance with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+<FlowPane orientation="vertical"
+    xmlns:wtkx="http://incubator.apache.org/pivot/wtkx/1.1"
+    xmlns:content="pivot.wtk.content" xmlns="pivot.wtk">
+    <Label text="Apache Pivot 1.2 (incubating)"/>
+</FlowPane>
+