jdk/src/share/classes/java/awt/Component.java
changeset 4259 b41995ac0c17
parent 4257 c447aed67cec
parent 3972 8942e64cf57d
child 4261 126dc6fe0d7b
--- a/jdk/src/share/classes/java/awt/Component.java	Wed Oct 14 19:23:15 2009 +0400
+++ b/jdk/src/share/classes/java/awt/Component.java	Thu Oct 15 16:37:55 2009 -0700
@@ -60,7 +60,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import javax.accessibility.*;
-import java.util.logging.*;
 import java.applet.Applet;
 
 import sun.security.action.GetPropertyAction;
@@ -74,6 +73,9 @@
 import sun.awt.EmbeddedFrame;
 import sun.awt.dnd.SunDropTargetEvent;
 import sun.awt.im.CompositionArea;
+import sun.font.FontManager;
+import sun.font.FontManagerFactory;
+import sun.font.SunFontManager;
 import sun.java2d.SunGraphics2D;
 import sun.java2d.pipe.Region;
 import sun.awt.image.VSyncedBSManager;
@@ -81,6 +83,7 @@
 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
 import sun.awt.RequestFocusController;
 import sun.java2d.SunGraphicsEnvironment;
+import sun.util.logging.PlatformLogger;
 
 /**
  * A <em>component</em> is an object having a graphical representation
@@ -185,10 +188,10 @@
                                            Serializable
 {
 
-    private static final Logger log = Logger.getLogger("java.awt.Component");
-    private static final Logger eventLog = Logger.getLogger("java.awt.event.Component");
-    private static final Logger focusLog = Logger.getLogger("java.awt.focus.Component");
-    private static final Logger mixingLog = Logger.getLogger("java.awt.mixing.Component");
+    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
+    private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
+    private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
+    private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
 
     /**
      * The peer of the component. The peer implements the component's
@@ -2903,8 +2906,12 @@
      * @since     JDK1.0
      */
     public FontMetrics getFontMetrics(Font font) {
-        // REMIND: PlatformFont flag should be obsolete soon...
-        if (sun.font.FontManager.usePlatformFontMetrics()) {
+        // This is an unsupported hack, but left in for a customer.
+        // Do not remove.
+        FontManager fm = FontManagerFactory.getInstance();
+        if (fm instanceof SunFontManager
+            && ((SunFontManager) fm).usePlatformFontMetrics()) {
+
             if (peer != null &&
                 !(peer instanceof LightweightPeer)) {
                 return peer.getFontMetrics(font);
@@ -4526,13 +4533,13 @@
         // Check that this component belongs to this app-context
         AppContext compContext = appContext;
         if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
-            if (eventLog.isLoggable(Level.FINE)) {
-                eventLog.log(Level.FINE, "Event " + e + " is being dispatched on the wrong AppContext");
-            }
-        }
-
-        if (eventLog.isLoggable(Level.FINEST)) {
-            eventLog.log(Level.FINEST, "{0}", e);
+            if (eventLog.isLoggable(PlatformLogger.FINE)) {
+                eventLog.fine("Event " + e + " is being dispatched on the wrong AppContext");
+            }
+        }
+
+        if (eventLog.isLoggable(PlatformLogger.FINEST)) {
+            eventLog.finest("{0}", e);
         }
 
         /*
@@ -4567,8 +4574,8 @@
                 return;
             }
         }
-        if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
-            focusLog.log(Level.FINEST, "" + e);
+        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
+            focusLog.finest("" + e);
         }
         // MouseWheel may need to be retargeted here so that
         // AWTEventListener sees the event go to the correct
@@ -4625,8 +4632,8 @@
                 if (inputContext != null) {
                     inputContext.dispatchEvent(e);
                     if (e.isConsumed()) {
-                        if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
-                            focusLog.log(Level.FINEST, "3579: Skipping " + e);
+                        if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
+                            focusLog.finest("3579: Skipping " + e);
                         }
                         return;
                     }
@@ -4660,8 +4667,8 @@
               if (p != null) {
                   p.preProcessKeyEvent((KeyEvent)e);
                   if (e.isConsumed()) {
-                        if (focusLog.isLoggable(Level.FINEST)) {
-                            focusLog.log(Level.FINEST, "Pre-process consumed event");
+                        if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                            focusLog.finest("Pre-process consumed event");
                         }
                       return;
                   }
@@ -4793,9 +4800,9 @@
                                   // position relative to its parent.
         MouseWheelEvent newMWE;
 
-        if (eventLog.isLoggable(Level.FINEST)) {
-            eventLog.log(Level.FINEST, "dispatchMouseWheelToAncestor");
-            eventLog.log(Level.FINEST, "orig event src is of " + e.getSource().getClass());
+        if (eventLog.isLoggable(PlatformLogger.FINEST)) {
+            eventLog.finest("dispatchMouseWheelToAncestor");
+            eventLog.finest("orig event src is of " + e.getSource().getClass());
         }
 
         /* parent field for Window refers to the owning Window.
@@ -4816,8 +4823,8 @@
                 }
             }
 
-            if (eventLog.isLoggable(Level.FINEST)) {
-                eventLog.log(Level.FINEST, "new event src is " + anc.getClass());
+            if (eventLog.isLoggable(PlatformLogger.FINEST)) {
+                eventLog.finest("new event src is " + anc.getClass());
             }
 
             if (anc != null && anc.eventEnabled(e)) {
@@ -5312,11 +5319,11 @@
     // Should only be called while holding the tree lock
     int numListening(long mask) {
         // One mask or the other, but not neither or both.
-        if (eventLog.isLoggable(Level.FINE)) {
+        if (eventLog.isLoggable(PlatformLogger.FINE)) {
             if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
                 (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
             {
-                eventLog.log(Level.FINE, "Assertion failed");
+                eventLog.fine("Assertion failed");
             }
         }
         if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
@@ -5353,9 +5360,9 @@
               break;
           case HierarchyEvent.ANCESTOR_MOVED:
           case HierarchyEvent.ANCESTOR_RESIZED:
-              if (eventLog.isLoggable(Level.FINE)) {
+              if (eventLog.isLoggable(PlatformLogger.FINE)) {
                   if (changeFlags != 0) {
-                      eventLog.log(Level.FINE, "Assertion (changeFlags == 0) failed");
+                      eventLog.fine("Assertion (changeFlags == 0) failed");
                   }
               }
               if (hierarchyBoundsListener != null ||
@@ -5369,8 +5376,8 @@
               break;
           default:
               // assert false
-              if (eventLog.isLoggable(Level.FINE)) {
-                  eventLog.log(Level.FINE, "This code must never be reached");
+              if (eventLog.isLoggable(PlatformLogger.FINE)) {
+                  eventLog.fine("This code must never be reached");
               }
               break;
         }
@@ -7437,8 +7444,8 @@
                                      CausedFocusEvent.Cause cause)
     {
         if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "requestFocus is not accepted");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("requestFocus is not accepted");
             }
             return false;
         }
@@ -7449,8 +7456,8 @@
         Component window = this;
         while ( (window != null) && !(window instanceof Window)) {
             if (!window.isVisible()) {
-                if (focusLog.isLoggable(Level.FINEST)) {
-                    focusLog.log(Level.FINEST, "component is recurively invisible");
+                if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                    focusLog.finest("component is recurively invisible");
                 }
                 return false;
             }
@@ -7461,15 +7468,15 @@
         Component heavyweight = (peer instanceof LightweightPeer)
             ? getNativeContainer() : this;
         if (heavyweight == null || !heavyweight.isVisible()) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Component is not a part of visible hierarchy");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Component is not a part of visible hierarchy");
             }
             return false;
         }
         peer = heavyweight.peer;
         if (peer == null) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Peer is null");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Peer is null");
             }
             return false;
         }
@@ -7481,12 +7488,12 @@
         if (!success) {
             KeyboardFocusManager.getCurrentKeyboardFocusManager
                 (appContext).dequeueKeyEvents(time, this);
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Peer request failed");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Peer request failed");
             }
         } else {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Pass for " + this);
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Pass for " + this);
             }
         }
         return success;
@@ -7497,24 +7504,24 @@
                                            CausedFocusEvent.Cause cause)
     {
         if (!isFocusable() || !isVisible()) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Not focusable or not visible");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Not focusable or not visible");
             }
             return false;
         }
 
         ComponentPeer peer = this.peer;
         if (peer == null) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "peer is null");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("peer is null");
             }
             return false;
         }
 
         Window window = getContainingWindow();
         if (window == null || !((Window)window).isFocusableWindow()) {
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "Component doesn't have toplevel");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("Component doesn't have toplevel");
             }
             return false;
         }
@@ -7535,8 +7542,8 @@
             // Controller is supposed to verify focus transfers and for this it
             // should know both from and to components.  And it shouldn't verify
             // transfers from when these components are equal.
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "focus owner is null or this");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("focus owner is null or this");
             }
             return true;
         }
@@ -7548,8 +7555,8 @@
             // most recent focus owner.  But most recent focus owner can be
             // changed by requestFocsuXXX() call only, so this transfer has
             // been already approved.
-            if (focusLog.isLoggable(Level.FINEST)) {
-                focusLog.log(Level.FINEST, "cause is activation");
+            if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+                focusLog.finest("cause is activation");
             }
             return true;
         }
@@ -7559,8 +7566,8 @@
                                                                           temporary,
                                                                           focusedWindowChangeAllowed,
                                                                           cause);
-        if (focusLog.isLoggable(Level.FINEST)) {
-            focusLog.log(Level.FINEST, "RequestFocusController returns {0}", ret);
+        if (focusLog.isLoggable(PlatformLogger.FINEST)) {
+            focusLog.finest("RequestFocusController returns {0}", ret);
         }
 
         return ret;
@@ -7651,7 +7658,7 @@
     }
 
     boolean transferFocus(boolean clearOnFailure) {
-        if (focusLog.isLoggable(Level.FINER)) {
+        if (focusLog.isLoggable(PlatformLogger.FINER)) {
             focusLog.finer("clearOnFailure = " + clearOnFailure);
         }
         Component toFocus = getNextFocusCandidate();
@@ -7660,12 +7667,12 @@
             res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
         }
         if (clearOnFailure && !res) {
-            if (focusLog.isLoggable(Level.FINER)) {
+            if (focusLog.isLoggable(PlatformLogger.FINER)) {
                 focusLog.finer("clear global focus owner");
             }
             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
         }
-        if (focusLog.isLoggable(Level.FINER)) {
+        if (focusLog.isLoggable(PlatformLogger.FINER)) {
             focusLog.finer("returning result: " + res);
         }
         return res;
@@ -7680,19 +7687,19 @@
             comp = rootAncestor;
             rootAncestor = comp.getFocusCycleRootAncestor();
         }
-        if (focusLog.isLoggable(Level.FINER)) {
+        if (focusLog.isLoggable(PlatformLogger.FINER)) {
             focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
         }
         Component candidate = null;
         if (rootAncestor != null) {
             FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
             Component toFocus = policy.getComponentAfter(rootAncestor, comp);
-            if (focusLog.isLoggable(Level.FINER)) {
+            if (focusLog.isLoggable(PlatformLogger.FINER)) {
                 focusLog.finer("component after is " + toFocus);
             }
             if (toFocus == null) {
                 toFocus = policy.getDefaultComponent(rootAncestor);
-                if (focusLog.isLoggable(Level.FINER)) {
+                if (focusLog.isLoggable(PlatformLogger.FINER)) {
                     focusLog.finer("default component is " + toFocus);
                 }
             }
@@ -7704,7 +7711,7 @@
             }
             candidate = toFocus;
         }
-        if (focusLog.isLoggable(Level.FINER)) {
+        if (focusLog.isLoggable(PlatformLogger.FINER)) {
             focusLog.finer("Focus transfer candidate: " + candidate);
         }
         return candidate;
@@ -7741,12 +7748,12 @@
             }
         }
         if (!res) {
-            if (focusLog.isLoggable(Level.FINER)) {
+            if (focusLog.isLoggable(PlatformLogger.FINER)) {
                 focusLog.finer("clear global focus owner");
             }
             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
         }
-        if (focusLog.isLoggable(Level.FINER)) {
+        if (focusLog.isLoggable(PlatformLogger.FINER)) {
             focusLog.finer("returning result: " + res);
         }
         return res;
@@ -9512,7 +9519,7 @@
         checkTreeLock();
 
         if (!areBoundsValid()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
             }
             return;
@@ -9548,7 +9555,7 @@
                     }
                     this.compoundShape = shape;
                     Point compAbsolute = getLocationOnWindow();
-                    if (mixingLog.isLoggable(Level.FINER)) {
+                    if (mixingLog.isLoggable(PlatformLogger.FINER)) {
                         mixingLog.fine("this = " + this +
                                 "; compAbsolute=" + compAbsolute + "; shape=" + shape);
                     }
@@ -9682,7 +9689,7 @@
         checkTreeLock();
         Region s = getNormalShape();
 
-        if (mixingLog.isLoggable(Level.FINE)) {
+        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
             mixingLog.fine("this = " + this + "; normalShape=" + s);
         }
 
@@ -9716,7 +9723,7 @@
             }
         }
 
-        if (mixingLog.isLoggable(Level.FINE)) {
+        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
             mixingLog.fine("currentShape=" + s);
         }
 
@@ -9726,12 +9733,12 @@
     void applyCurrentShape() {
         checkTreeLock();
         if (!areBoundsValid()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
             }
             return; // Because applyCompoundShape() ignores such components anyway
         }
-        if (mixingLog.isLoggable(Level.FINE)) {
+        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
             mixingLog.fine("this = " + this);
         }
         applyCompoundShape(calculateCurrentShape());
@@ -9740,7 +9747,7 @@
     final void subtractAndApplyShape(Region s) {
         checkTreeLock();
 
-        if (mixingLog.isLoggable(Level.FINE)) {
+        if (mixingLog.isLoggable(PlatformLogger.FINE)) {
             mixingLog.fine("this = " + this + "; s=" + s);
         }
 
@@ -9787,7 +9794,7 @@
 
     void mixOnShowing() {
         synchronized (getTreeLock()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this);
             }
             if (!isMixingNeeded()) {
@@ -9805,7 +9812,7 @@
         // We cannot be sure that the peer exists at this point, so we need the argument
         //    to find out whether the hiding component is (well, actually was) a LW or a HW.
         synchronized (getTreeLock()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
             }
             if (!isMixingNeeded()) {
@@ -9819,7 +9826,7 @@
 
     void mixOnReshaping() {
         synchronized (getTreeLock()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this);
             }
             if (!isMixingNeeded()) {
@@ -9838,7 +9845,7 @@
             boolean becameHigher = newZorder < oldZorder;
             Container parent = getContainer();
 
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this +
                     "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
             }
@@ -9882,13 +9889,13 @@
 
     final boolean isMixingNeeded() {
         if (SunToolkit.getSunAwtDisableMixing()) {
-            if (mixingLog.isLoggable(Level.FINEST)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINEST)) {
                 mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing");
             }
             return false;
         }
         if (!areBoundsValid()) {
-            if (mixingLog.isLoggable(Level.FINE)) {
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
             }
             return false;
@@ -9896,7 +9903,7 @@
         Window window = getContainingWindow();
         if (window != null) {
             if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) {
-                if (mixingLog.isLoggable(Level.FINE)) {
+                if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                     mixingLog.fine("containing window = " + window +
                             "; has h/w descendants = " + window.hasHeavyweightDescendants() +
                             "; has l/w descendants = " + window.hasLightweightDescendants());
@@ -9904,8 +9911,8 @@
                 return false;
             }
         } else {
-            if (mixingLog.isLoggable(Level.FINE)) {
-                mixingLog.finest("this = " + this + "; containing window is null");
+            if (mixingLog.isLoggable(PlatformLogger.FINE)) {
+                mixingLog.fine("this = " + this + "; containing window is null");
             }
             return false;
         }