changeset 9077:01fee0a8b707

RT-46093: Different months can get the same info "You were born yesterday" Reviewed-By: ddhill
author Morris Meyer <morris.meyer@oracle.com>
date Mon, 01 Jun 2015 21:32:15 -0400
parents d352eeca1c89
children dc298be52c6d
files apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/stringbinding/StringBindingApp.java buildSrc/mac.gradle modules/graphics/src/main/java/com/sun/glass/ui/Application.java modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java modules/graphics/src/main/java/com/sun/javafx/application/LauncherImpl.java modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java modules/graphics/src/main/native-glass/mac/GlassApplication.m modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java
diffstat 11 files changed, 102 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/stringbinding/StringBindingApp.java	Sat May 30 15:02:18 2015 +0300
+++ b/apps/samples/Ensemble8/src/samples/java/ensemble/samples/language/stringbinding/StringBindingApp.java	Mon Jun 01 21:32:15 2015 -0400
@@ -60,7 +60,8 @@
 public class StringBindingApp extends Application {
 
     public Parent createContent() {
-        final SimpleDateFormat format = new SimpleDateFormat("mm/dd/yyyy");
+        final SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy");
+        format.setLenient(false);
         final TextField dateField = new TextField();
         dateField.setPromptText("Enter a birth date");
         dateField.setMaxHeight(TextField.USE_PREF_SIZE);
@@ -83,15 +84,18 @@
                     Date today = new Date();
                     Calendar c2 = Calendar.getInstance();
                     c2.setTime(today);
-
+                    
                     if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR) - 1
                             && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
                         return "You were born yesterday";
+                    } else if (c.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR)
+                               && c.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
+                        return "You were born today";
                     } else {
                         return "You were born " + format.format(date);
                     }
                 } catch (Exception e) {
-                    return "Enter a valid birth date (mm/dd/yyyy)";
+                    return "Enter your valid birth date (mm/dd/yyyy)";
                 }
             }
         });
--- a/buildSrc/mac.gradle	Sat May 30 15:02:18 2015 +0300
+++ b/buildSrc/mac.gradle	Mon Jun 01 21:32:15 2015 -0400
@@ -136,9 +136,18 @@
     "com/sun/glass/ui/mac/*"]
 MAC.glass.nativeSource = file("modules/graphics/src/main/native-glass/mac")
 MAC.glass.compiler = compiler
-MAC.glass.ccFlags = [ccFlags].flatten()
+MAC.glass.ccFlags = [
+        ccFlags,
+        "-iframework$MACOSX_SDK_PATH/System/Library/Frameworks",
+        "-F$MACOSX_SDK_PATH/System/Library/Frameworks/JavaVM.framework/Frameworks"
+        ].flatten()
 MAC.glass.linker = linker
-MAC.glass.linkFlags = [linkFlags].flatten()
+MAC.glass.linkFlags = [
+        linkFlags,
+        "-iframework$MACOSX_SDK_PATH/System/Library/Frameworks",
+        "-F$MACOSX_SDK_PATH/System/Library/Frameworks/JavaVM.framework/Frameworks",
+        "-framework", "JavaRuntimeSupport"
+        ].flatten()
 MAC.glass.lib = "glass"
 
 MAC.decora = [:]
--- a/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/Application.java	Mon Jun 01 21:32:15 2015 -0400
@@ -139,17 +139,20 @@
     }
     
     // May be called on any thread.
-    public static void run(final Runnable launchable) {
+    public static void run(final String mainApplicationName, final Runnable launchable) {
         if (application != null) {
             throw new IllegalStateException("Application is already running");
         }
+        
         application = PlatformFactory.getPlatformFactory().createApplication();
         // each concrete Application should set the app name using its own platform mechanism:
         // on Mac OS X - use NSBundle info, which can be overriden by -Xdock:name
         // on Windows - TODO
         // on Linux - TODO
-        //application.name = DEFAULT_NAME; // default
+        
         try {
+            application.name = mainApplicationName;
+            
             application.runLoop(() -> {
                 Screen.initScreens();
                 launchable.run();
--- a/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java	Mon Jun 01 21:32:15 2015 -0400
@@ -180,6 +180,28 @@
     @Override public void installDefaultMenus(MenuBar menubar) {
         installAppleMenu(menubar);
     }
+    
+    @Override public void setName(String name) {
+        if (_supportsSystemMenu()) {
+            /* 
+             * If JavaFX has control over the system menu, which stems from
+             * JavaFX / Glass not being embedded in AWT, SWT or elsewhere, 
+             * then assert JavaFX name as the dock and system menu name
+             */
+            try {
+                /* LauncherImpl path */
+                Class cl = Class.forName(name);
+                _setApplicationName(cl.getSimpleName());
+            } catch (ClassNotFoundException cnfe) {
+                /* GlassApplication NSBundle path */
+                _setApplicationName(name);
+            }
+            
+        }
+        super.setName(name);
+    }
+    
+    private native void _setApplicationName(String nane);
 
 
     // FACTORY METHODS
--- a/modules/graphics/src/main/java/com/sun/javafx/application/LauncherImpl.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/application/LauncherImpl.java	Mon Jun 01 21:32:15 2015 -0400
@@ -334,6 +334,7 @@
             final String preloaderClassName, String[] args) {
 
         try {
+            PlatformImpl.setApplicationName(mainClassName);
             startToolkit();
         } catch (InterruptedException ex) {
             abort(ex, "Toolkit initialization error", mainClassName);
@@ -819,7 +820,7 @@
                         app.set(c.newInstance());
                         // Set startup parameters
                         ParametersImpl.registerParameters(app.get(), new ParametersImpl(args));
-                        PlatformImpl.setApplicationName(appClass);
+                        PlatformImpl.setApplicationClass(appClass);
                     } catch (Throwable t) {
                         System.err.println("Exception in Application constructor");
                         constructorError = t;
--- a/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/application/PlatformImpl.java	Mon Jun 01 21:32:15 2015 -0400
@@ -87,6 +87,7 @@
     private static Boolean hasPointer;
     private static boolean isThreadMerged = false;
     private static BooleanProperty accessibilityActive = new SimpleBooleanProperty();
+    private static String startupApplicationName = null;
 
     /**
      * Set a flag indicating whether this application should show up in the
@@ -116,9 +117,19 @@
      *
      * @param appClass the Application class.
      */
-    public static void setApplicationName(final Class appClass) {
+    public static void setApplicationClass(final Class appClass) {
         runLater(() -> com.sun.glass.ui.Application.GetApplication().setName(appClass.getName()));
     }
+    
+    /*
+     * Some platforms like the Mac need the application prior to the running runLoop.
+     * Cache an initial value for them.
+     *
+     * @param appName the name of the started Application.
+     */
+    public static void setApplicationName(final String appName) {
+        startupApplicationName = appName;
+    }
 
     /**
      * Return whether or not focus navigation between controls is context-
@@ -208,7 +219,7 @@
         };
         Toolkit.getToolkit().addTkListener(toolkitListener);
 
-        Toolkit.getToolkit().startup(() -> {
+        Toolkit.getToolkit().startup(startupApplicationName, () -> {
             startupLatch.countDown();
             r.run();
         });
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/DummyToolkit.java	Mon Jun 01 21:32:15 2015 -0400
@@ -147,7 +147,7 @@
     }
 
     @Override
-    public void startup(Runnable runnable) {
+    public void startup(String name, Runnable runnable) {
         throw new UnsupportedOperationException("Not supported yet.");
     }
 
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/Toolkit.java	Mon Jun 01 21:32:15 2015 -0400
@@ -530,7 +530,7 @@
     // Subclasses may override this to provide a platform-specific default
     public boolean getDefaultImageSmooth() { return true; }
 
-    public abstract void startup(Runnable runnable);
+    public abstract void startup(String name, Runnable runnable);
     public abstract void defer(Runnable runnable);
     public void exit() {
         fxUserThread = null;
--- a/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/java/com/sun/javafx/tk/quantum/QuantumToolkit.java	Mon Jun 01 21:32:15 2015 -0400
@@ -246,7 +246,7 @@
      *                            that allows the system to perform some startup
      *                            functionality after the toolkit has been initialized.
      */
-    @Override public void startup(final Runnable userStartupRunnable) {
+    @Override public void startup(final String name, final Runnable userStartupRunnable) {
         // Save the context class loader of the launcher thread
         ccl = Thread.currentThread().getContextClassLoader();
 
@@ -254,7 +254,7 @@
             this.userRunnable = userStartupRunnable;
 
             // Ensure that the toolkit can only be started here
-            Application.run(() -> runToolkit());
+            Application.run(name, () -> runToolkit());
         } catch (RuntimeException ex) {
             if (verbose) {
                 ex.printStackTrace();
--- a/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/main/native-glass/mac/GlassApplication.m	Mon Jun 01 21:32:15 2015 -0400
@@ -28,8 +28,8 @@
 #import "com_sun_glass_ui_mac_MacApplication.h"
 #import "com_sun_glass_events_KeyEvent.h"
 
-
 #import "GlassMacros.h"
+#import "GlassAccessible.h"
 #import "GlassApplication.h"
 #import "GlassHelper.h"
 #import "GlassKey.h"
@@ -39,6 +39,7 @@
 #import "RemoteLayerSupport.h"
 
 #import "ProcessInfo.h"
+#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
 #import <Security/SecRequirement.h>
 
 //#define VERBOSE
@@ -493,6 +494,16 @@
             if (appName == nil) {
                 appName = [mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
             }
+            
+            if (appName == nil) {
+                jclass appCls = [GlassHelper ClassForName:"com.sun.glass.ui.Application" withEnv:jEnv];
+                GLASS_CHECK_EXCEPTION(jEnv);
+                jfieldID getNameStringField = (*jEnv)->GetFieldID(jEnv, appCls, "name", "Ljava/lang/String;");
+                GLASS_CHECK_EXCEPTION(jEnv);
+                jstring name = (jstring)(*jEnv)->GetObjectField(jEnv, glassApp->jApplication, getNameStringField);
+                GLASS_CHECK_EXCEPTION(jEnv);
+                appName = jStringToNSString(jEnv, name);
+            }
 
             if (appName) {
                 // make the name available to Java side, before Launchable.fnishLaunching callback
@@ -1124,10 +1135,10 @@
     GLASS_ASSERT_MAIN_JAVA_THREAD(env);
     GLASS_POOL_ENTER;
     {
-    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
-    if (paths && [paths count] > 0) {
-        string = (*env)->NewStringUTF(jEnv, [[paths lastObject] UTF8String]);
-    }
+        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+        if (paths && [paths count] > 0) {
+            string = (*env)->NewStringUTF(jEnv, [[paths lastObject] UTF8String]);
+        }
     }
     GLASS_POOL_EXIT;
     GLASS_CHECK_EXCEPTION(env);
@@ -1137,6 +1148,27 @@
 
 /*
  * Class:     com_sun_glass_ui_mac_MacApplication
+ * Method:    _setApplicationName
+ * Signature: (Ljava/lang/String;)V;
+ */
+JNIEXPORT void JNICALL Java_com_sun_glass_ui_mac_MacApplication__1setApplicationName
+(JNIEnv * env, jobject japplication, jstring name)
+{
+    GLASS_ASSERT_MAIN_JAVA_THREAD(env);
+    GLASS_POOL_ENTER;
+    {
+        NSString *appName = jStringToNSString(env, name);
+        LOG("Java_com_sun_glass_ui_mac_MacApplication__1setApplicationName: %s", [appName UTF8String]);
+        NSDictionary *registrationOptions = [NSMutableDictionary dictionaryWithObject:appName forKey:@"JRSAppNameKey"];
+        [JRSAppKitAWT registerAWTAppWithOptions:registrationOptions];
+    }
+    GLASS_POOL_EXIT;
+    GLASS_CHECK_EXCEPTION(env);
+    
+}
+
+/*
+ * Class:     com_sun_glass_ui_mac_MacApplication
  * Method:    _getMacKey
  * Signature: (I)I
  */
--- a/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Sat May 30 15:02:18 2015 +0300
+++ b/modules/graphics/src/test/java/com/sun/javafx/pgstub/StubToolkit.java	Mon Jun 01 21:32:15 2015 -0400
@@ -152,7 +152,7 @@
     }
 
     @Override
-    public void startup(Runnable runnable) {
+    public void startup(String name, Runnable runnable) {
         runnable.run();
     }