jdk/src/share/classes/java/awt/Component.java
changeset 4259 b41995ac0c17
parent 4257 c447aed67cec
parent 3972 8942e64cf57d
child 4261 126dc6fe0d7b
equal deleted inserted replaced
4258:50b23b28d857 4259:b41995ac0c17
    58 import java.lang.reflect.InvocationTargetException;
    58 import java.lang.reflect.InvocationTargetException;
    59 import java.lang.reflect.Method;
    59 import java.lang.reflect.Method;
    60 import java.security.AccessController;
    60 import java.security.AccessController;
    61 import java.security.PrivilegedAction;
    61 import java.security.PrivilegedAction;
    62 import javax.accessibility.*;
    62 import javax.accessibility.*;
    63 import java.util.logging.*;
       
    64 import java.applet.Applet;
    63 import java.applet.Applet;
    65 
    64 
    66 import sun.security.action.GetPropertyAction;
    65 import sun.security.action.GetPropertyAction;
    67 import sun.awt.AppContext;
    66 import sun.awt.AppContext;
    68 import sun.awt.AWTAccessor;
    67 import sun.awt.AWTAccessor;
    72 import sun.awt.WindowClosingListener;
    71 import sun.awt.WindowClosingListener;
    73 import sun.awt.CausedFocusEvent;
    72 import sun.awt.CausedFocusEvent;
    74 import sun.awt.EmbeddedFrame;
    73 import sun.awt.EmbeddedFrame;
    75 import sun.awt.dnd.SunDropTargetEvent;
    74 import sun.awt.dnd.SunDropTargetEvent;
    76 import sun.awt.im.CompositionArea;
    75 import sun.awt.im.CompositionArea;
       
    76 import sun.font.FontManager;
       
    77 import sun.font.FontManagerFactory;
       
    78 import sun.font.SunFontManager;
    77 import sun.java2d.SunGraphics2D;
    79 import sun.java2d.SunGraphics2D;
    78 import sun.java2d.pipe.Region;
    80 import sun.java2d.pipe.Region;
    79 import sun.awt.image.VSyncedBSManager;
    81 import sun.awt.image.VSyncedBSManager;
    80 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
    82 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
    81 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
    83 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
    82 import sun.awt.RequestFocusController;
    84 import sun.awt.RequestFocusController;
    83 import sun.java2d.SunGraphicsEnvironment;
    85 import sun.java2d.SunGraphicsEnvironment;
       
    86 import sun.util.logging.PlatformLogger;
    84 
    87 
    85 /**
    88 /**
    86  * A <em>component</em> is an object having a graphical representation
    89  * A <em>component</em> is an object having a graphical representation
    87  * that can be displayed on the screen and that can interact with the
    90  * that can be displayed on the screen and that can interact with the
    88  * user. Examples of components are the buttons, checkboxes, and scrollbars
    91  * user. Examples of components are the buttons, checkboxes, and scrollbars
   183  */
   186  */
   184 public abstract class Component implements ImageObserver, MenuContainer,
   187 public abstract class Component implements ImageObserver, MenuContainer,
   185                                            Serializable
   188                                            Serializable
   186 {
   189 {
   187 
   190 
   188     private static final Logger log = Logger.getLogger("java.awt.Component");
   191     private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component");
   189     private static final Logger eventLog = Logger.getLogger("java.awt.event.Component");
   192     private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component");
   190     private static final Logger focusLog = Logger.getLogger("java.awt.focus.Component");
   193     private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component");
   191     private static final Logger mixingLog = Logger.getLogger("java.awt.mixing.Component");
   194     private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component");
   192 
   195 
   193     /**
   196     /**
   194      * The peer of the component. The peer implements the component's
   197      * The peer of the component. The peer implements the component's
   195      * behavior. The peer is set when the <code>Component</code> is
   198      * behavior. The peer is set when the <code>Component</code> is
   196      * added to a container that also is a peer.
   199      * added to a container that also is a peer.
  2901      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
  2904      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
  2902      * @see       Toolkit#getFontMetrics(Font)
  2905      * @see       Toolkit#getFontMetrics(Font)
  2903      * @since     JDK1.0
  2906      * @since     JDK1.0
  2904      */
  2907      */
  2905     public FontMetrics getFontMetrics(Font font) {
  2908     public FontMetrics getFontMetrics(Font font) {
  2906         // REMIND: PlatformFont flag should be obsolete soon...
  2909         // This is an unsupported hack, but left in for a customer.
  2907         if (sun.font.FontManager.usePlatformFontMetrics()) {
  2910         // Do not remove.
       
  2911         FontManager fm = FontManagerFactory.getInstance();
       
  2912         if (fm instanceof SunFontManager
       
  2913             && ((SunFontManager) fm).usePlatformFontMetrics()) {
       
  2914 
  2908             if (peer != null &&
  2915             if (peer != null &&
  2909                 !(peer instanceof LightweightPeer)) {
  2916                 !(peer instanceof LightweightPeer)) {
  2910                 return peer.getFontMetrics(font);
  2917                 return peer.getFontMetrics(font);
  2911             }
  2918             }
  2912         }
  2919         }
  4524         int id = e.getID();
  4531         int id = e.getID();
  4525 
  4532 
  4526         // Check that this component belongs to this app-context
  4533         // Check that this component belongs to this app-context
  4527         AppContext compContext = appContext;
  4534         AppContext compContext = appContext;
  4528         if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
  4535         if (compContext != null && !compContext.equals(AppContext.getAppContext())) {
  4529             if (eventLog.isLoggable(Level.FINE)) {
  4536             if (eventLog.isLoggable(PlatformLogger.FINE)) {
  4530                 eventLog.log(Level.FINE, "Event " + e + " is being dispatched on the wrong AppContext");
  4537                 eventLog.fine("Event " + e + " is being dispatched on the wrong AppContext");
  4531             }
  4538             }
  4532         }
  4539         }
  4533 
  4540 
  4534         if (eventLog.isLoggable(Level.FINEST)) {
  4541         if (eventLog.isLoggable(PlatformLogger.FINEST)) {
  4535             eventLog.log(Level.FINEST, "{0}", e);
  4542             eventLog.finest("{0}", e);
  4536         }
  4543         }
  4537 
  4544 
  4538         /*
  4545         /*
  4539          * 0. Set timestamp and modifiers of current event.
  4546          * 0. Set timestamp and modifiers of current event.
  4540          */
  4547          */
  4565                 dispatchEvent(e))
  4572                 dispatchEvent(e))
  4566             {
  4573             {
  4567                 return;
  4574                 return;
  4568             }
  4575             }
  4569         }
  4576         }
  4570         if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
  4577         if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
  4571             focusLog.log(Level.FINEST, "" + e);
  4578             focusLog.finest("" + e);
  4572         }
  4579         }
  4573         // MouseWheel may need to be retargeted here so that
  4580         // MouseWheel may need to be retargeted here so that
  4574         // AWTEventListener sees the event go to the correct
  4581         // AWTEventListener sees the event go to the correct
  4575         // Component.  If the MouseWheelEvent needs to go to an ancestor,
  4582         // Component.  If the MouseWheelEvent needs to go to an ancestor,
  4576         // the event is dispatched to the ancestor, and dispatching here
  4583         // the event is dispatched to the ancestor, and dispatching here
  4623 
  4630 
  4624 
  4631 
  4625                 if (inputContext != null) {
  4632                 if (inputContext != null) {
  4626                     inputContext.dispatchEvent(e);
  4633                     inputContext.dispatchEvent(e);
  4627                     if (e.isConsumed()) {
  4634                     if (e.isConsumed()) {
  4628                         if ((e instanceof FocusEvent) && focusLog.isLoggable(Level.FINEST)) {
  4635                         if ((e instanceof FocusEvent) && focusLog.isLoggable(PlatformLogger.FINEST)) {
  4629                             focusLog.log(Level.FINEST, "3579: Skipping " + e);
  4636                             focusLog.finest("3579: Skipping " + e);
  4630                         }
  4637                         }
  4631                         return;
  4638                         return;
  4632                     }
  4639                     }
  4633                 }
  4640                 }
  4634             }
  4641             }
  4658           case KeyEvent.KEY_RELEASED:
  4665           case KeyEvent.KEY_RELEASED:
  4659               Container p = (Container)((this instanceof Container) ? this : parent);
  4666               Container p = (Container)((this instanceof Container) ? this : parent);
  4660               if (p != null) {
  4667               if (p != null) {
  4661                   p.preProcessKeyEvent((KeyEvent)e);
  4668                   p.preProcessKeyEvent((KeyEvent)e);
  4662                   if (e.isConsumed()) {
  4669                   if (e.isConsumed()) {
  4663                         if (focusLog.isLoggable(Level.FINEST)) {
  4670                         if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  4664                             focusLog.log(Level.FINEST, "Pre-process consumed event");
  4671                             focusLog.finest("Pre-process consumed event");
  4665                         }
  4672                         }
  4666                       return;
  4673                       return;
  4667                   }
  4674                   }
  4668               }
  4675               }
  4669               break;
  4676               break;
  4791         newY = e.getY() + getY(); // the cursor's position relative to this
  4798         newY = e.getY() + getY(); // the cursor's position relative to this
  4792                                   // Component (e.getX()), and this Component's
  4799                                   // Component (e.getX()), and this Component's
  4793                                   // position relative to its parent.
  4800                                   // position relative to its parent.
  4794         MouseWheelEvent newMWE;
  4801         MouseWheelEvent newMWE;
  4795 
  4802 
  4796         if (eventLog.isLoggable(Level.FINEST)) {
  4803         if (eventLog.isLoggable(PlatformLogger.FINEST)) {
  4797             eventLog.log(Level.FINEST, "dispatchMouseWheelToAncestor");
  4804             eventLog.finest("dispatchMouseWheelToAncestor");
  4798             eventLog.log(Level.FINEST, "orig event src is of " + e.getSource().getClass());
  4805             eventLog.finest("orig event src is of " + e.getSource().getClass());
  4799         }
  4806         }
  4800 
  4807 
  4801         /* parent field for Window refers to the owning Window.
  4808         /* parent field for Window refers to the owning Window.
  4802          * MouseWheelEvents should NOT be propagated into owning Windows
  4809          * MouseWheelEvents should NOT be propagated into owning Windows
  4803          */
  4810          */
  4814                 else {
  4821                 else {
  4815                     break;
  4822                     break;
  4816                 }
  4823                 }
  4817             }
  4824             }
  4818 
  4825 
  4819             if (eventLog.isLoggable(Level.FINEST)) {
  4826             if (eventLog.isLoggable(PlatformLogger.FINEST)) {
  4820                 eventLog.log(Level.FINEST, "new event src is " + anc.getClass());
  4827                 eventLog.finest("new event src is " + anc.getClass());
  4821             }
  4828             }
  4822 
  4829 
  4823             if (anc != null && anc.eventEnabled(e)) {
  4830             if (anc != null && anc.eventEnabled(e)) {
  4824                 // Change event to be from new source, with new x,y
  4831                 // Change event to be from new source, with new x,y
  4825                 // For now, just create a new event - yucky
  4832                 // For now, just create a new event - yucky
  5310     }
  5317     }
  5311 
  5318 
  5312     // Should only be called while holding the tree lock
  5319     // Should only be called while holding the tree lock
  5313     int numListening(long mask) {
  5320     int numListening(long mask) {
  5314         // One mask or the other, but not neither or both.
  5321         // One mask or the other, but not neither or both.
  5315         if (eventLog.isLoggable(Level.FINE)) {
  5322         if (eventLog.isLoggable(PlatformLogger.FINE)) {
  5316             if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
  5323             if ((mask != AWTEvent.HIERARCHY_EVENT_MASK) &&
  5317                 (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
  5324                 (mask != AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK))
  5318             {
  5325             {
  5319                 eventLog.log(Level.FINE, "Assertion failed");
  5326                 eventLog.fine("Assertion failed");
  5320             }
  5327             }
  5321         }
  5328         }
  5322         if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
  5329         if ((mask == AWTEvent.HIERARCHY_EVENT_MASK &&
  5323              (hierarchyListener != null ||
  5330              (hierarchyListener != null ||
  5324               (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) ||
  5331               (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0)) ||
  5351                   return 1;
  5358                   return 1;
  5352               }
  5359               }
  5353               break;
  5360               break;
  5354           case HierarchyEvent.ANCESTOR_MOVED:
  5361           case HierarchyEvent.ANCESTOR_MOVED:
  5355           case HierarchyEvent.ANCESTOR_RESIZED:
  5362           case HierarchyEvent.ANCESTOR_RESIZED:
  5356               if (eventLog.isLoggable(Level.FINE)) {
  5363               if (eventLog.isLoggable(PlatformLogger.FINE)) {
  5357                   if (changeFlags != 0) {
  5364                   if (changeFlags != 0) {
  5358                       eventLog.log(Level.FINE, "Assertion (changeFlags == 0) failed");
  5365                       eventLog.fine("Assertion (changeFlags == 0) failed");
  5359                   }
  5366                   }
  5360               }
  5367               }
  5361               if (hierarchyBoundsListener != null ||
  5368               if (hierarchyBoundsListener != null ||
  5362                   (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
  5369                   (eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 ||
  5363                   enabledOnToolkit) {
  5370                   enabledOnToolkit) {
  5367                   return 1;
  5374                   return 1;
  5368               }
  5375               }
  5369               break;
  5376               break;
  5370           default:
  5377           default:
  5371               // assert false
  5378               // assert false
  5372               if (eventLog.isLoggable(Level.FINE)) {
  5379               if (eventLog.isLoggable(PlatformLogger.FINE)) {
  5373                   eventLog.log(Level.FINE, "This code must never be reached");
  5380                   eventLog.fine("This code must never be reached");
  5374               }
  5381               }
  5375               break;
  5382               break;
  5376         }
  5383         }
  5377         return 0;
  5384         return 0;
  5378     }
  5385     }
  7435     final boolean requestFocusHelper(boolean temporary,
  7442     final boolean requestFocusHelper(boolean temporary,
  7436                                      boolean focusedWindowChangeAllowed,
  7443                                      boolean focusedWindowChangeAllowed,
  7437                                      CausedFocusEvent.Cause cause)
  7444                                      CausedFocusEvent.Cause cause)
  7438     {
  7445     {
  7439         if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
  7446         if (!isRequestFocusAccepted(temporary, focusedWindowChangeAllowed, cause)) {
  7440             if (focusLog.isLoggable(Level.FINEST)) {
  7447             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7441                 focusLog.log(Level.FINEST, "requestFocus is not accepted");
  7448                 focusLog.finest("requestFocus is not accepted");
  7442             }
  7449             }
  7443             return false;
  7450             return false;
  7444         }
  7451         }
  7445 
  7452 
  7446         // Update most-recent map
  7453         // Update most-recent map
  7447         KeyboardFocusManager.setMostRecentFocusOwner(this);
  7454         KeyboardFocusManager.setMostRecentFocusOwner(this);
  7448 
  7455 
  7449         Component window = this;
  7456         Component window = this;
  7450         while ( (window != null) && !(window instanceof Window)) {
  7457         while ( (window != null) && !(window instanceof Window)) {
  7451             if (!window.isVisible()) {
  7458             if (!window.isVisible()) {
  7452                 if (focusLog.isLoggable(Level.FINEST)) {
  7459                 if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7453                     focusLog.log(Level.FINEST, "component is recurively invisible");
  7460                     focusLog.finest("component is recurively invisible");
  7454                 }
  7461                 }
  7455                 return false;
  7462                 return false;
  7456             }
  7463             }
  7457             window = window.parent;
  7464             window = window.parent;
  7458         }
  7465         }
  7459 
  7466 
  7460         ComponentPeer peer = this.peer;
  7467         ComponentPeer peer = this.peer;
  7461         Component heavyweight = (peer instanceof LightweightPeer)
  7468         Component heavyweight = (peer instanceof LightweightPeer)
  7462             ? getNativeContainer() : this;
  7469             ? getNativeContainer() : this;
  7463         if (heavyweight == null || !heavyweight.isVisible()) {
  7470         if (heavyweight == null || !heavyweight.isVisible()) {
  7464             if (focusLog.isLoggable(Level.FINEST)) {
  7471             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7465                 focusLog.log(Level.FINEST, "Component is not a part of visible hierarchy");
  7472                 focusLog.finest("Component is not a part of visible hierarchy");
  7466             }
  7473             }
  7467             return false;
  7474             return false;
  7468         }
  7475         }
  7469         peer = heavyweight.peer;
  7476         peer = heavyweight.peer;
  7470         if (peer == null) {
  7477         if (peer == null) {
  7471             if (focusLog.isLoggable(Level.FINEST)) {
  7478             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7472                 focusLog.log(Level.FINEST, "Peer is null");
  7479                 focusLog.finest("Peer is null");
  7473             }
  7480             }
  7474             return false;
  7481             return false;
  7475         }
  7482         }
  7476 
  7483 
  7477         // Focus this Component
  7484         // Focus this Component
  7479         boolean success = peer.requestFocus
  7486         boolean success = peer.requestFocus
  7480             (this, temporary, focusedWindowChangeAllowed, time, cause);
  7487             (this, temporary, focusedWindowChangeAllowed, time, cause);
  7481         if (!success) {
  7488         if (!success) {
  7482             KeyboardFocusManager.getCurrentKeyboardFocusManager
  7489             KeyboardFocusManager.getCurrentKeyboardFocusManager
  7483                 (appContext).dequeueKeyEvents(time, this);
  7490                 (appContext).dequeueKeyEvents(time, this);
  7484             if (focusLog.isLoggable(Level.FINEST)) {
  7491             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7485                 focusLog.log(Level.FINEST, "Peer request failed");
  7492                 focusLog.finest("Peer request failed");
  7486             }
  7493             }
  7487         } else {
  7494         } else {
  7488             if (focusLog.isLoggable(Level.FINEST)) {
  7495             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7489                 focusLog.log(Level.FINEST, "Pass for " + this);
  7496                 focusLog.finest("Pass for " + this);
  7490             }
  7497             }
  7491         }
  7498         }
  7492         return success;
  7499         return success;
  7493     }
  7500     }
  7494 
  7501 
  7495     private boolean isRequestFocusAccepted(boolean temporary,
  7502     private boolean isRequestFocusAccepted(boolean temporary,
  7496                                            boolean focusedWindowChangeAllowed,
  7503                                            boolean focusedWindowChangeAllowed,
  7497                                            CausedFocusEvent.Cause cause)
  7504                                            CausedFocusEvent.Cause cause)
  7498     {
  7505     {
  7499         if (!isFocusable() || !isVisible()) {
  7506         if (!isFocusable() || !isVisible()) {
  7500             if (focusLog.isLoggable(Level.FINEST)) {
  7507             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7501                 focusLog.log(Level.FINEST, "Not focusable or not visible");
  7508                 focusLog.finest("Not focusable or not visible");
  7502             }
  7509             }
  7503             return false;
  7510             return false;
  7504         }
  7511         }
  7505 
  7512 
  7506         ComponentPeer peer = this.peer;
  7513         ComponentPeer peer = this.peer;
  7507         if (peer == null) {
  7514         if (peer == null) {
  7508             if (focusLog.isLoggable(Level.FINEST)) {
  7515             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7509                 focusLog.log(Level.FINEST, "peer is null");
  7516                 focusLog.finest("peer is null");
  7510             }
  7517             }
  7511             return false;
  7518             return false;
  7512         }
  7519         }
  7513 
  7520 
  7514         Window window = getContainingWindow();
  7521         Window window = getContainingWindow();
  7515         if (window == null || !((Window)window).isFocusableWindow()) {
  7522         if (window == null || !((Window)window).isFocusableWindow()) {
  7516             if (focusLog.isLoggable(Level.FINEST)) {
  7523             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7517                 focusLog.log(Level.FINEST, "Component doesn't have toplevel");
  7524                 focusLog.finest("Component doesn't have toplevel");
  7518             }
  7525             }
  7519             return false;
  7526             return false;
  7520         }
  7527         }
  7521 
  7528 
  7522         // We have passed all regular checks for focus request,
  7529         // We have passed all regular checks for focus request,
  7533 
  7540 
  7534         if (focusOwner == this || focusOwner == null) {
  7541         if (focusOwner == this || focusOwner == null) {
  7535             // Controller is supposed to verify focus transfers and for this it
  7542             // Controller is supposed to verify focus transfers and for this it
  7536             // should know both from and to components.  And it shouldn't verify
  7543             // should know both from and to components.  And it shouldn't verify
  7537             // transfers from when these components are equal.
  7544             // transfers from when these components are equal.
  7538             if (focusLog.isLoggable(Level.FINEST)) {
  7545             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7539                 focusLog.log(Level.FINEST, "focus owner is null or this");
  7546                 focusLog.finest("focus owner is null or this");
  7540             }
  7547             }
  7541             return true;
  7548             return true;
  7542         }
  7549         }
  7543 
  7550 
  7544         if (CausedFocusEvent.Cause.ACTIVATION == cause) {
  7551         if (CausedFocusEvent.Cause.ACTIVATION == cause) {
  7546             // in activation.  We do request focus on component which
  7553             // in activation.  We do request focus on component which
  7547             // has got temporary focus lost and then on component which is
  7554             // has got temporary focus lost and then on component which is
  7548             // most recent focus owner.  But most recent focus owner can be
  7555             // most recent focus owner.  But most recent focus owner can be
  7549             // changed by requestFocsuXXX() call only, so this transfer has
  7556             // changed by requestFocsuXXX() call only, so this transfer has
  7550             // been already approved.
  7557             // been already approved.
  7551             if (focusLog.isLoggable(Level.FINEST)) {
  7558             if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7552                 focusLog.log(Level.FINEST, "cause is activation");
  7559                 focusLog.finest("cause is activation");
  7553             }
  7560             }
  7554             return true;
  7561             return true;
  7555         }
  7562         }
  7556 
  7563 
  7557         boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner,
  7564         boolean ret = Component.requestFocusController.acceptRequestFocus(focusOwner,
  7558                                                                           this,
  7565                                                                           this,
  7559                                                                           temporary,
  7566                                                                           temporary,
  7560                                                                           focusedWindowChangeAllowed,
  7567                                                                           focusedWindowChangeAllowed,
  7561                                                                           cause);
  7568                                                                           cause);
  7562         if (focusLog.isLoggable(Level.FINEST)) {
  7569         if (focusLog.isLoggable(PlatformLogger.FINEST)) {
  7563             focusLog.log(Level.FINEST, "RequestFocusController returns {0}", ret);
  7570             focusLog.finest("RequestFocusController returns {0}", ret);
  7564         }
  7571         }
  7565 
  7572 
  7566         return ret;
  7573         return ret;
  7567     }
  7574     }
  7568 
  7575 
  7649     public void nextFocus() {
  7656     public void nextFocus() {
  7650         transferFocus(false);
  7657         transferFocus(false);
  7651     }
  7658     }
  7652 
  7659 
  7653     boolean transferFocus(boolean clearOnFailure) {
  7660     boolean transferFocus(boolean clearOnFailure) {
  7654         if (focusLog.isLoggable(Level.FINER)) {
  7661         if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7655             focusLog.finer("clearOnFailure = " + clearOnFailure);
  7662             focusLog.finer("clearOnFailure = " + clearOnFailure);
  7656         }
  7663         }
  7657         Component toFocus = getNextFocusCandidate();
  7664         Component toFocus = getNextFocusCandidate();
  7658         boolean res = false;
  7665         boolean res = false;
  7659         if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
  7666         if (toFocus != null && !toFocus.isFocusOwner() && toFocus != this) {
  7660             res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
  7667             res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_FORWARD);
  7661         }
  7668         }
  7662         if (clearOnFailure && !res) {
  7669         if (clearOnFailure && !res) {
  7663             if (focusLog.isLoggable(Level.FINER)) {
  7670             if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7664                 focusLog.finer("clear global focus owner");
  7671                 focusLog.finer("clear global focus owner");
  7665             }
  7672             }
  7666             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
  7673             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
  7667         }
  7674         }
  7668         if (focusLog.isLoggable(Level.FINER)) {
  7675         if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7669             focusLog.finer("returning result: " + res);
  7676             focusLog.finer("returning result: " + res);
  7670         }
  7677         }
  7671         return res;
  7678         return res;
  7672     }
  7679     }
  7673 
  7680 
  7678                !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
  7685                !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner()))
  7679         {
  7686         {
  7680             comp = rootAncestor;
  7687             comp = rootAncestor;
  7681             rootAncestor = comp.getFocusCycleRootAncestor();
  7688             rootAncestor = comp.getFocusCycleRootAncestor();
  7682         }
  7689         }
  7683         if (focusLog.isLoggable(Level.FINER)) {
  7690         if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7684             focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
  7691             focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
  7685         }
  7692         }
  7686         Component candidate = null;
  7693         Component candidate = null;
  7687         if (rootAncestor != null) {
  7694         if (rootAncestor != null) {
  7688             FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
  7695             FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
  7689             Component toFocus = policy.getComponentAfter(rootAncestor, comp);
  7696             Component toFocus = policy.getComponentAfter(rootAncestor, comp);
  7690             if (focusLog.isLoggable(Level.FINER)) {
  7697             if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7691                 focusLog.finer("component after is " + toFocus);
  7698                 focusLog.finer("component after is " + toFocus);
  7692             }
  7699             }
  7693             if (toFocus == null) {
  7700             if (toFocus == null) {
  7694                 toFocus = policy.getDefaultComponent(rootAncestor);
  7701                 toFocus = policy.getDefaultComponent(rootAncestor);
  7695                 if (focusLog.isLoggable(Level.FINER)) {
  7702                 if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7696                     focusLog.finer("default component is " + toFocus);
  7703                     focusLog.finer("default component is " + toFocus);
  7697                 }
  7704                 }
  7698             }
  7705             }
  7699             if (toFocus == null) {
  7706             if (toFocus == null) {
  7700                 Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
  7707                 Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
  7702                     toFocus = applet;
  7709                     toFocus = applet;
  7703                 }
  7710                 }
  7704             }
  7711             }
  7705             candidate = toFocus;
  7712             candidate = toFocus;
  7706         }
  7713         }
  7707         if (focusLog.isLoggable(Level.FINER)) {
  7714         if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7708             focusLog.finer("Focus transfer candidate: " + candidate);
  7715             focusLog.finer("Focus transfer candidate: " + candidate);
  7709         }
  7716         }
  7710         return candidate;
  7717         return candidate;
  7711     }
  7718     }
  7712 
  7719 
  7739             if (toFocus != null) {
  7746             if (toFocus != null) {
  7740                 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
  7747                 res = toFocus.requestFocusInWindow(CausedFocusEvent.Cause.TRAVERSAL_BACKWARD);
  7741             }
  7748             }
  7742         }
  7749         }
  7743         if (!res) {
  7750         if (!res) {
  7744             if (focusLog.isLoggable(Level.FINER)) {
  7751             if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7745                 focusLog.finer("clear global focus owner");
  7752                 focusLog.finer("clear global focus owner");
  7746             }
  7753             }
  7747             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
  7754             KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
  7748         }
  7755         }
  7749         if (focusLog.isLoggable(Level.FINER)) {
  7756         if (focusLog.isLoggable(PlatformLogger.FINER)) {
  7750             focusLog.finer("returning result: " + res);
  7757             focusLog.finer("returning result: " + res);
  7751         }
  7758         }
  7752         return res;
  7759         return res;
  7753     }
  7760     }
  7754 
  7761 
  9510      */
  9517      */
  9511     void applyCompoundShape(Region shape) {
  9518     void applyCompoundShape(Region shape) {
  9512         checkTreeLock();
  9519         checkTreeLock();
  9513 
  9520 
  9514         if (!areBoundsValid()) {
  9521         if (!areBoundsValid()) {
  9515             if (mixingLog.isLoggable(Level.FINE)) {
  9522             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9516                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9523                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9517             }
  9524             }
  9518             return;
  9525             return;
  9519         }
  9526         }
  9520 
  9527 
  9546                     if (shape.equals(getAppliedShape())) {
  9553                     if (shape.equals(getAppliedShape())) {
  9547                         return;
  9554                         return;
  9548                     }
  9555                     }
  9549                     this.compoundShape = shape;
  9556                     this.compoundShape = shape;
  9550                     Point compAbsolute = getLocationOnWindow();
  9557                     Point compAbsolute = getLocationOnWindow();
  9551                     if (mixingLog.isLoggable(Level.FINER)) {
  9558                     if (mixingLog.isLoggable(PlatformLogger.FINER)) {
  9552                         mixingLog.fine("this = " + this +
  9559                         mixingLog.fine("this = " + this +
  9553                                 "; compAbsolute=" + compAbsolute + "; shape=" + shape);
  9560                                 "; compAbsolute=" + compAbsolute + "; shape=" + shape);
  9554                     }
  9561                     }
  9555                     peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y));
  9562                     peer.applyShape(shape.getTranslatedRegion(-compAbsolute.x, -compAbsolute.y));
  9556                 }
  9563                 }
  9680 
  9687 
  9681     private Region calculateCurrentShape() {
  9688     private Region calculateCurrentShape() {
  9682         checkTreeLock();
  9689         checkTreeLock();
  9683         Region s = getNormalShape();
  9690         Region s = getNormalShape();
  9684 
  9691 
  9685         if (mixingLog.isLoggable(Level.FINE)) {
  9692         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9686             mixingLog.fine("this = " + this + "; normalShape=" + s);
  9693             mixingLog.fine("this = " + this + "; normalShape=" + s);
  9687         }
  9694         }
  9688 
  9695 
  9689         if (getContainer() != null) {
  9696         if (getContainer() != null) {
  9690             Component comp = this;
  9697             Component comp = this;
  9714                 comp = cont;
  9721                 comp = cont;
  9715                 cont = cont.getContainer();
  9722                 cont = cont.getContainer();
  9716             }
  9723             }
  9717         }
  9724         }
  9718 
  9725 
  9719         if (mixingLog.isLoggable(Level.FINE)) {
  9726         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9720             mixingLog.fine("currentShape=" + s);
  9727             mixingLog.fine("currentShape=" + s);
  9721         }
  9728         }
  9722 
  9729 
  9723         return s;
  9730         return s;
  9724     }
  9731     }
  9725 
  9732 
  9726     void applyCurrentShape() {
  9733     void applyCurrentShape() {
  9727         checkTreeLock();
  9734         checkTreeLock();
  9728         if (!areBoundsValid()) {
  9735         if (!areBoundsValid()) {
  9729             if (mixingLog.isLoggable(Level.FINE)) {
  9736             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9730                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9737                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9731             }
  9738             }
  9732             return; // Because applyCompoundShape() ignores such components anyway
  9739             return; // Because applyCompoundShape() ignores such components anyway
  9733         }
  9740         }
  9734         if (mixingLog.isLoggable(Level.FINE)) {
  9741         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9735             mixingLog.fine("this = " + this);
  9742             mixingLog.fine("this = " + this);
  9736         }
  9743         }
  9737         applyCompoundShape(calculateCurrentShape());
  9744         applyCompoundShape(calculateCurrentShape());
  9738     }
  9745     }
  9739 
  9746 
  9740     final void subtractAndApplyShape(Region s) {
  9747     final void subtractAndApplyShape(Region s) {
  9741         checkTreeLock();
  9748         checkTreeLock();
  9742 
  9749 
  9743         if (mixingLog.isLoggable(Level.FINE)) {
  9750         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9744             mixingLog.fine("this = " + this + "; s=" + s);
  9751             mixingLog.fine("this = " + this + "; s=" + s);
  9745         }
  9752         }
  9746 
  9753 
  9747         applyCompoundShape(getAppliedShape().getDifference(s));
  9754         applyCompoundShape(getAppliedShape().getDifference(s));
  9748     }
  9755     }
  9785         }
  9792         }
  9786     }
  9793     }
  9787 
  9794 
  9788     void mixOnShowing() {
  9795     void mixOnShowing() {
  9789         synchronized (getTreeLock()) {
  9796         synchronized (getTreeLock()) {
  9790             if (mixingLog.isLoggable(Level.FINE)) {
  9797             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9791                 mixingLog.fine("this = " + this);
  9798                 mixingLog.fine("this = " + this);
  9792             }
  9799             }
  9793             if (!isMixingNeeded()) {
  9800             if (!isMixingNeeded()) {
  9794                 return;
  9801                 return;
  9795             }
  9802             }
  9803 
  9810 
  9804     void mixOnHiding(boolean isLightweight) {
  9811     void mixOnHiding(boolean isLightweight) {
  9805         // We cannot be sure that the peer exists at this point, so we need the argument
  9812         // We cannot be sure that the peer exists at this point, so we need the argument
  9806         //    to find out whether the hiding component is (well, actually was) a LW or a HW.
  9813         //    to find out whether the hiding component is (well, actually was) a LW or a HW.
  9807         synchronized (getTreeLock()) {
  9814         synchronized (getTreeLock()) {
  9808             if (mixingLog.isLoggable(Level.FINE)) {
  9815             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9809                 mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
  9816                 mixingLog.fine("this = " + this + "; isLightweight = " + isLightweight);
  9810             }
  9817             }
  9811             if (!isMixingNeeded()) {
  9818             if (!isMixingNeeded()) {
  9812                 return;
  9819                 return;
  9813             }
  9820             }
  9817         }
  9824         }
  9818     }
  9825     }
  9819 
  9826 
  9820     void mixOnReshaping() {
  9827     void mixOnReshaping() {
  9821         synchronized (getTreeLock()) {
  9828         synchronized (getTreeLock()) {
  9822             if (mixingLog.isLoggable(Level.FINE)) {
  9829             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9823                 mixingLog.fine("this = " + this);
  9830                 mixingLog.fine("this = " + this);
  9824             }
  9831             }
  9825             if (!isMixingNeeded()) {
  9832             if (!isMixingNeeded()) {
  9826                 return;
  9833                 return;
  9827             }
  9834             }
  9836     void mixOnZOrderChanging(int oldZorder, int newZorder) {
  9843     void mixOnZOrderChanging(int oldZorder, int newZorder) {
  9837         synchronized (getTreeLock()) {
  9844         synchronized (getTreeLock()) {
  9838             boolean becameHigher = newZorder < oldZorder;
  9845             boolean becameHigher = newZorder < oldZorder;
  9839             Container parent = getContainer();
  9846             Container parent = getContainer();
  9840 
  9847 
  9841             if (mixingLog.isLoggable(Level.FINE)) {
  9848             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9842                 mixingLog.fine("this = " + this +
  9849                 mixingLog.fine("this = " + this +
  9843                     "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
  9850                     "; oldZorder=" + oldZorder + "; newZorder=" + newZorder + "; parent=" + parent);
  9844             }
  9851             }
  9845             if (!isMixingNeeded()) {
  9852             if (!isMixingNeeded()) {
  9846                 return;
  9853                 return;
  9880         // non-container components don't need to handle validation.
  9887         // non-container components don't need to handle validation.
  9881     }
  9888     }
  9882 
  9889 
  9883     final boolean isMixingNeeded() {
  9890     final boolean isMixingNeeded() {
  9884         if (SunToolkit.getSunAwtDisableMixing()) {
  9891         if (SunToolkit.getSunAwtDisableMixing()) {
  9885             if (mixingLog.isLoggable(Level.FINEST)) {
  9892             if (mixingLog.isLoggable(PlatformLogger.FINEST)) {
  9886                 mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing");
  9893                 mixingLog.finest("this = " + this + "; Mixing disabled via sun.awt.disableMixing");
  9887             }
  9894             }
  9888             return false;
  9895             return false;
  9889         }
  9896         }
  9890         if (!areBoundsValid()) {
  9897         if (!areBoundsValid()) {
  9891             if (mixingLog.isLoggable(Level.FINE)) {
  9898             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9892                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9899                 mixingLog.fine("this = " + this + "; areBoundsValid = " + areBoundsValid());
  9893             }
  9900             }
  9894             return false;
  9901             return false;
  9895         }
  9902         }
  9896         Window window = getContainingWindow();
  9903         Window window = getContainingWindow();
  9897         if (window != null) {
  9904         if (window != null) {
  9898             if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) {
  9905             if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) {
  9899                 if (mixingLog.isLoggable(Level.FINE)) {
  9906                 if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9900                     mixingLog.fine("containing window = " + window +
  9907                     mixingLog.fine("containing window = " + window +
  9901                             "; has h/w descendants = " + window.hasHeavyweightDescendants() +
  9908                             "; has h/w descendants = " + window.hasHeavyweightDescendants() +
  9902                             "; has l/w descendants = " + window.hasLightweightDescendants());
  9909                             "; has l/w descendants = " + window.hasLightweightDescendants());
  9903                 }
  9910                 }
  9904                 return false;
  9911                 return false;
  9905             }
  9912             }
  9906         } else {
  9913         } else {
  9907             if (mixingLog.isLoggable(Level.FINE)) {
  9914             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  9908                 mixingLog.finest("this = " + this + "; containing window is null");
  9915                 mixingLog.fine("this = " + this + "; containing window is null");
  9909             }
  9916             }
  9910             return false;
  9917             return false;
  9911         }
  9918         }
  9912         return true;
  9919         return true;
  9913     }
  9920     }