8027324: The spec for Toolkit.setDynamicLayout() and Toolkit.isDynamicLayoutActive() needs to be clarified
authorserb
Mon, 02 May 2016 12:08:59 +0300
changeset 38396 29de73c166ce
parent 38395 acdc10ebac11
child 38397 8ff4232c93c2
8027324: The spec for Toolkit.setDynamicLayout() and Toolkit.isDynamicLayoutActive() needs to be clarified Reviewed-by: alexsch, prr
jdk/src/java.desktop/share/classes/java/awt/Toolkit.java
jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java
--- a/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java	Mon May 02 12:01:39 2016 +0300
+++ b/jdk/src/java.desktop/share/classes/java/awt/Toolkit.java	Mon May 02 12:08:59 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -207,30 +207,34 @@
     }
 
     /**
-     * Returns whether dynamic layout of Containers on resize is
-     * currently active (both set in program
-     *( {@code isDynamicLayoutSet()} )
-     *, and supported
-     * by the underlying operating system and/or window manager).
-     * If dynamic layout is currently inactive then Containers
-     * re-layout their components when resizing is completed. As a result
-     * the {@code Component.validate()} method will be invoked only
-     * once per resize.
-     * If dynamic layout is currently active then Containers
-     * re-layout their components on every native resize event and
-     * the {@code validate()} method will be invoked each time.
-     * The OS/WM support can be queried using
-     * the getDesktopProperty("awt.dynamicLayoutSupported") method.
+     * Returns whether dynamic layout of Containers on resize is currently
+     * enabled on the underlying operating system and/or window manager). If the
+     * platform supports it, {@code setDynamicLayout(boolean)} may be used to
+     * programmatically enable or disable platform dynamic layout. Regardless of
+     * whether that toggling is supported, or whether {@code true} or {@code
+     * false} is specified as an argument, or has never been called at all, this
+     * method will return the active current platform behavior and which will be
+     * followed by the JDK in determining layout policy during resizing.
+     * <p>
+     * If dynamic layout is currently inactive then Containers re-layout their
+     * components when resizing is completed. As a result the
+     * {@code Component.validate()} method will be invoked only once per resize.
+     * If dynamic layout is currently active then Containers re-layout their
+     * components on every native resize event and the {@code validate()} method
+     * will be invoked each time. The OS/WM support can be queried using the
+     * getDesktopProperty("awt.dynamicLayoutSupported") method. This property
+     * will reflect the platform capability but is not sufficient to tell if it
+     * is presently enabled.
      *
-     * @return    true if dynamic layout of Containers on resize is
-     *            currently active, false otherwise.
-     * @exception HeadlessException if the GraphicsEnvironment.isHeadless()
-     *            method returns true
-     * @see       #setDynamicLayout(boolean dynamic)
-     * @see       #isDynamicLayoutSet()
-     * @see       #getDesktopProperty(String propertyName)
-     * @see       java.awt.GraphicsEnvironment#isHeadless
-     * @since     1.4
+     * @return true if dynamic layout of Containers on resize is currently
+     *         active, false otherwise.
+     * @throws HeadlessException if the GraphicsEnvironment.isHeadless() method
+     *         returns true
+     * @see #setDynamicLayout(boolean dynamic)
+     * @see #isDynamicLayoutSet()
+     * @see #getDesktopProperty(String propertyName)
+     * @see java.awt.GraphicsEnvironment#isHeadless
+     * @since 1.4
      */
     public boolean isDynamicLayoutActive()
         throws HeadlessException {
--- a/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java	Mon May 02 12:01:39 2016 +0300
+++ b/jdk/test/java/awt/Toolkit/DynamicLayout/bug7172833.java	Mon May 02 12:08:59 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -45,16 +45,34 @@
 
     public static void main(final String[] args) throws Exception {
         final StubbedToolkit t = new StubbedToolkit();
-
+        final Boolean dynamicLayoutSupported
+                = (Boolean) t.getDesktopProperty("awt.dynamicLayoutSupported");
         t.setDynamicLayout(true);
         if(!t.isDynamicLayoutSet()){
             throw new RuntimeException("'true' expected but 'false' returned");
         }
+        if (dynamicLayoutSupported) {
+            if (!t.isDynamicLayoutActive()) {
+                throw new RuntimeException("is inactive but set+supported");
+            }
+        } else {
+            if (t.isDynamicLayoutActive()) {
+                throw new RuntimeException("is active but unsupported");
+            }
+        }
 
         t.setDynamicLayout(false);
         if(t.isDynamicLayoutSet()){
             throw new RuntimeException("'false' expected but 'true' returned");
         }
+        if (dynamicLayoutSupported) {
+            // Layout is supported and was set to false, cannot verifym because
+            // the native system is free to ignore our request.
+        } else {
+            if (t.isDynamicLayoutActive()) {
+                throw new RuntimeException("is active but unset+unsupported");
+            }
+        }
     }
 
     static final class StubbedToolkit extends Toolkit {