10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.java.swing; 27 28 import sun.awt.EventQueueDelegate; 29 import sun.awt.AppContext; 30 import java.util.Collections; 31 import java.util.Map; 32 import java.util.WeakHashMap; 33 import java.util.concurrent.Callable; 34 import java.applet.Applet; 35 import java.awt.AWTEvent; 36 import java.awt.EventQueue; 37 import java.awt.Component; 38 import java.awt.Container; 39 import java.awt.Window; 40 import javax.swing.JComponent; 41 import javax.swing.RepaintManager; 42 43 /** 44 * A collection of utility methods for Swing. 45 * <p> 46 * <b>WARNING:</b> While this class is public, it should not be treated as 47 * public API and its API may change in incompatable ways between dot dot 48 * releases and even patch releases. You should not rely on this class even 49 * existing. 100 } 101 } 102 103 /** 104 * Checks if vsync painting is requested for {@code rootContainer} 105 * 106 * @param rootContainer topmost container. Should be either Window or Applet 107 * @return {@code true} if vsync painting is requested for {@code rootContainer} 108 */ 109 public static boolean isVsyncRequested(Container rootContainer) { 110 assert (rootContainer instanceof Applet) || (rootContainer instanceof Window); 111 return Boolean.TRUE == vsyncedMap.get(rootContainer); 112 } 113 114 /** 115 * Returns delegate {@code RepaintManager} for {@code component} hierarchy. 116 */ 117 public static RepaintManager getDelegateRepaintManager(Component 118 component) { 119 RepaintManager delegate = null; 120 if (Boolean.TRUE == AppContext.getAppContext().get( 121 DELEGATE_REPAINT_MANAGER_KEY)) { 122 while (delegate == null && component != null) { 123 while (component != null 124 && ! (component instanceof JComponent)) { 125 component = component.getParent(); 126 } 127 if (component != null) { 128 delegate = (RepaintManager) 129 ((JComponent) component) 130 .getClientProperty(DELEGATE_REPAINT_MANAGER_KEY); 131 component = component.getParent(); 132 } 133 134 } 135 } 136 return delegate; 137 } 138 139 /* 140 * We use maps to avoid reflection. Hopefully it should perform better 141 * this way. | 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.java.swing; 27 28 import sun.awt.EventQueueDelegate; 29 import sun.awt.AppContext; 30 import sun.awt.SunToolkit; 31 32 import java.util.Collections; 33 import java.util.Map; 34 import java.util.WeakHashMap; 35 import java.util.concurrent.Callable; 36 import java.applet.Applet; 37 import java.awt.AWTEvent; 38 import java.awt.EventQueue; 39 import java.awt.Component; 40 import java.awt.Container; 41 import java.awt.Window; 42 import javax.swing.JComponent; 43 import javax.swing.RepaintManager; 44 45 /** 46 * A collection of utility methods for Swing. 47 * <p> 48 * <b>WARNING:</b> While this class is public, it should not be treated as 49 * public API and its API may change in incompatable ways between dot dot 50 * releases and even patch releases. You should not rely on this class even 51 * existing. 102 } 103 } 104 105 /** 106 * Checks if vsync painting is requested for {@code rootContainer} 107 * 108 * @param rootContainer topmost container. Should be either Window or Applet 109 * @return {@code true} if vsync painting is requested for {@code rootContainer} 110 */ 111 public static boolean isVsyncRequested(Container rootContainer) { 112 assert (rootContainer instanceof Applet) || (rootContainer instanceof Window); 113 return Boolean.TRUE == vsyncedMap.get(rootContainer); 114 } 115 116 /** 117 * Returns delegate {@code RepaintManager} for {@code component} hierarchy. 118 */ 119 public static RepaintManager getDelegateRepaintManager(Component 120 component) { 121 RepaintManager delegate = null; 122 if (Boolean.TRUE == SunToolkit.targetToAppContext(component) 123 .get(DELEGATE_REPAINT_MANAGER_KEY)) { 124 while (delegate == null && component != null) { 125 while (component != null 126 && ! (component instanceof JComponent)) { 127 component = component.getParent(); 128 } 129 if (component != null) { 130 delegate = (RepaintManager) 131 ((JComponent) component) 132 .getClientProperty(DELEGATE_REPAINT_MANAGER_KEY); 133 component = component.getParent(); 134 } 135 136 } 137 } 138 return delegate; 139 } 140 141 /* 142 * We use maps to avoid reflection. Hopefully it should perform better 143 * this way. |