changeset 948:804bd3cdb04f 2.2-b08

Automated merge with ssh://jpgodine@jfxsrc.us.oracle.com//javafx/2.2/MASTER/jfx/rt
author jpgodine@JPGODINE-LAP.st-users.us.oracle.com
date Tue, 08 May 2012 09:03:15 -0700
parents e971e6a12a35 b26bab84097d
children 893db73acfb5 3df48424b375
files javafx-ui-common/src/com/sun/javafx/css/StyleHelper.java javafx-ui-common/src/com/sun/javafx/css/StyleManager.java javafx-ui-common/src/javafx/scene/Node.java javafx-ui-common/src/javafx/scene/Parent.java javafx-ui-common/src/javafx/scene/Scene.java
diffstat 7 files changed, 91 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/application/LauncherImpl.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/com/sun/javafx/application/LauncherImpl.java	Tue May 08 09:03:15 2012 -0700
@@ -178,7 +178,11 @@
         final CountDownLatch pShutdownLatch = new CountDownLatch(1);
 
         final PlatformImpl.FinishListener listener = new PlatformImpl.FinishListener() {
-            @Override public void idle() {
+            @Override public void idle(boolean implicitExit) {
+                if (!implicitExit) {
+                    return;
+                }
+
 //                System.err.println("JavaFX Launcher: system is idle");
                 if (startCalled.get()) {
                     shutdownLatch.countDown();
--- a/javafx-ui-common/src/com/sun/javafx/application/PlatformImpl.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/com/sun/javafx/application/PlatformImpl.java	Tue May 08 09:03:15 2012 -0700
@@ -47,6 +47,7 @@
     private static CountDownLatch startupLatch = new CountDownLatch(1);
     private static AtomicBoolean listenersRegistered = new AtomicBoolean(false);
     private static TKListener toolkitListener = null;
+    private static volatile boolean implicitExit = true;
     private static AtomicInteger pendingRunnables = new AtomicInteger(0);
     private static AtomicInteger numWindows = new AtomicInteger(0);
     private static volatile boolean firstWindowShown = false;
@@ -193,6 +194,15 @@
         }
     }
 
+    public static void setImplicitExit(boolean implicitExit) {
+        PlatformImpl.implicitExit = implicitExit;
+        checkIdle();
+    }
+
+    public static boolean isImplicitExit() {
+        return implicitExit;
+    }
+
     public static void addListener(FinishListener l) {
         listenersRegistered.set(true);
         finishListeners.add(l);
@@ -208,7 +218,7 @@
             if (exitCalled) {
                 l.exitCalled();
             } else {
-                l.idle();
+                l.idle(implicitExit);
             }
         }
     }
@@ -253,6 +263,12 @@
         }
     }
 
+    // package scope method for testing
+    private static final CountDownLatch platformExitLatch = new CountDownLatch(1);
+    static CountDownLatch test_getPlatformExitLatch() {
+        return platformExitLatch;
+    }
+
     public static void tkExit() {
         if (toolkitExit.getAndSet(true)) {
             return;
@@ -270,6 +286,7 @@
 
             Toolkit.getToolkit().removeTkListener(toolkitListener);
             toolkitListener = null;
+            platformExitLatch.countDown();
         }
     }
 
@@ -291,7 +308,7 @@
     }
 
     public static interface FinishListener {
-        public void idle();
+        public void idle(boolean implicitExit);
         public void exitCalled();
     }
 
--- a/javafx-ui-common/src/javafx/application/Application.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/javafx/application/Application.java	Tue May 08 09:03:15 2012 -0700
@@ -44,15 +44,19 @@
  * JavaFX runtime does the following, in order, whenever an application is
  * launched:
  * </p>
- * <ul>
+ * <ol>
  * <li>Constructs an instance of the specified Application class</li>
  * <li>Calls the {@link #init} method</li>
  * <li>Calls the {@link #start} method</li>
- * <li>Waits for the application to finish, which happens either when the
- * last window has been closed, or the application calls
- * {@link Platform#exit}</li>
+ * <li>Waits for the application to finish, which happens when either of
+ * the following occur:
+ * <ul>
+ * <li>the application calls {@link Platform#exit}</li>
+ * <li>the last window has been closed and the {@code implicitExit}
+ * attribute on {@code Platform} is true</li>
+ * </ul></li>
  * <li>Calls the {@link #stop} method</li>
- * </ul>
+ * </ol>
  * <p>Note that the {@code start} method is abstract and must be overridden.
  * The {@code init} and {@code stop} methods have concrete implementations
  * that do nothing.</p>
--- a/javafx-ui-common/src/javafx/application/Platform.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/javafx/application/Platform.java	Tue May 08 09:03:15 2012 -0700
@@ -85,6 +85,33 @@
     }
 
     /**
+     * Sets the implicitExit attribute to the specified value. If this
+     * attribute is true, the JavaFX runtime will implicitly shutdown
+     * when the last window is closed; the JavaFX launcher will call the
+     * {@link Application#stop} method and terminate the JavaFX
+     * application thread.
+     * If this attribute is false, the application will continue to
+     * run normally even after the last window is closed, until the
+     * application calls {@link #exit}.
+     * The default value is true.
+     *
+     * @param implicitExit a flag indicating whether or not to implicitly exit
+     * when the last window is closed.
+     */
+    public static void setImplicitExit(boolean implicitExit) {
+        PlatformImpl.setImplicitExit(implicitExit);
+    }
+
+    /**
+     * Gets the value of the implicitExit attribute.
+     *
+     * @return the implicitExit attribute
+     */
+    public static boolean isImplicitExit() {
+        return PlatformImpl.isImplicitExit();
+    }
+
+    /**
      * Queries whether a specific conditional feature is supported
      * by the platform.
      * <p>
--- a/javafx-ui-common/src/javafx/scene/Scene.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/javafx/scene/Scene.java	Tue May 08 09:03:15 2012 -0700
@@ -180,6 +180,7 @@
      *
      * @throws IllegalStateException if this constructor is called on a thread
      * other than the JavaFX Application Thread.
+     * @throws NullPointerException if root is null
      */
     public Scene(Parent root) {
         this(root, -1, -1, Color.WHITE, false);
@@ -210,6 +211,7 @@
      *
      * @throws IllegalStateException if this constructor is called on a thread
      * other than the JavaFX Application Thread.
+     * @throws NullPointerException if root is null
      */
     public Scene(Parent root, double width, double height) {
         this(root, width, height, Color.WHITE, false);
@@ -223,6 +225,7 @@
      *
      * @throws IllegalStateException if this constructor is called on a thread
      * other than the JavaFX Application Thread.
+     * @throws NullPointerException if root is null
      */
     public Scene(Parent root, @Default("javafx.scene.paint.Color.WHITE") Paint fill) {
         this(root, -1, -1, fill, false);
@@ -238,6 +241,7 @@
      *
      * @throws IllegalStateException if this constructor is called on a thread
      * other than the JavaFX Application Thread.
+     * @throws NullPointerException if root is null
      */
     public Scene(Parent root, double width, double height,
             @Default("javafx.scene.paint.Color.WHITE") Paint fill) {
@@ -260,6 +264,7 @@
      *
      * @throws IllegalStateException if this constructor is called on a thread
      * other than the JavaFX Application Thread.
+     * @throws NullPointerException if root is null
      *
      * @see javafx.scene.Node#setDepthTest(DepthTest)
      */
@@ -917,6 +922,9 @@
      * layout of the scene graph.    If a resizable node (layout {@code Region} or
      * {@code Control}) is set as the root, then the root's size will track the
      * scene's size, causing the contents to be relayed out as necessary.
+     * 
+     * Scene doesn't accept null root.
+     * 
      */
     private ObjectProperty<Parent> root;
 
--- a/javafx-ui-common/src/javafx/scene/input/DataFormat.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/src/javafx/scene/input/DataFormat.java	Tue May 08 09:03:15 2012 -0700
@@ -103,8 +103,18 @@
      * With the above code, if I were to look on the clipboard, I'd find the String "Hello"
      * listed both for "text/foo" and "text/bar" on the clipboard.
      * @param ids The set of ids used to represent this DataFormat on the clipboard.
+     * @throws IllegalArgumentException if one of the given mime types is already
+     *         assigned to another DataFormat.
      */
     public DataFormat(String... ids) {
+        DATA_FORMAT_LIST.cleanup();
+        for (String id : ids) {
+            if (lookupMimeType(id) != null) {
+                throw new IllegalArgumentException("DataFormat '" + id +
+                        "' already exists.");
+            }
+        }
+
         // If ids is null, then we will use an empty set.
         Set<String> set = ids == null ?
                 Collections.<String>emptySet() :
--- a/javafx-ui-common/test/unit/javafx/scene/input/DataFormatTest.java	Mon May 07 23:29:39 2012 -0400
+++ b/javafx-ui-common/test/unit/javafx/scene/input/DataFormatTest.java	Tue May 08 09:03:15 2012 -0700
@@ -54,7 +54,7 @@
     private DataFormat format;
     private String mime1;
     private String mime2;
-    
+
     public DataFormatTest(DataFormat format, String mime1, String mime2) {
         this.format = format;
         this.mime1 = mime1;
@@ -82,15 +82,20 @@
     public void testToString() {
         assertNotNull(customFormat.toString());
         assertFalse("".equals(customFormat.toString()));
-    }    
-    
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void shouldNotBePossibleToReuseMimeTypes() {
+        DataFormat customEqual = new DataFormat(format.getIdentifiers().toArray(
+                new String[format.getIdentifiers().size()]));
+    }
+
+
     @Test
     public void testEqualsAndHashCode() {
-        DataFormat customEqual = new DataFormat(format.getIdentifiers().toArray(
-                new String[format.getIdentifiers().size()]));
-        
-        assertEquals(customEqual, format);
-        assertEquals(customEqual.hashCode(), format.hashCode());
+        //cannot have two different equal data formats
+        assertEquals(format, format);
+        assertEquals(format.hashCode(), format.hashCode());
         assertFalse(uniqueFormat.equals(format));
         assertFalse(uniqueFormat.hashCode() == format.hashCode());
     }