jdk/src/java.desktop/share/classes/java/awt/Component.java
changeset 26749 b6598aa90114
parent 25859 3317bb8137f4
child 27502 4a8eca9c6f19
equal deleted inserted replaced
26748:fba66a2e8961 26749:b6598aa90114
   165  *             aButton.addActionListener(new MyActionListener());
   165  *             aButton.addActionListener(new MyActionListener());
   166  *         }
   166  *         }
   167  *    }
   167  *    }
   168  * </pre>
   168  * </pre>
   169  * <p>
   169  * <p>
   170  * <b>Note</b>: For more information on the paint mechanisms utilitized
   170  * <b>Note</b>: For more information on the paint mechanisms utilized
   171  * by AWT and Swing, including information on how to write the most
   171  * by AWT and Swing, including information on how to write the most
   172  * efficient painting code, see
   172  * efficient painting code, see
   173  * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
   173  * <a href="http://www.oracle.com/technetwork/java/painting-140037.html">Painting in AWT and Swing</a>.
   174  * <p>
   174  * <p>
   175  * For details on the focus subsystem, see
   175  * For details on the focus subsystem, see
   353      */
   353      */
   354     boolean enabled = true;
   354     boolean enabled = true;
   355 
   355 
   356     /**
   356     /**
   357      * True when the object is valid. An invalid object needs to
   357      * True when the object is valid. An invalid object needs to
   358      * be layed out. This flag is set to false when the object
   358      * be laid out. This flag is set to false when the object
   359      * size is changed.
   359      * size is changed.
   360      *
   360      *
   361      * @serial
   361      * @serial
   362      * @see #isValid
   362      * @see #isValid
   363      * @see #validate
   363      * @see #validate
   416     private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
   416     private static final int FOCUS_TRAVERSABLE_UNKNOWN = 0;
   417     private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
   417     private static final int FOCUS_TRAVERSABLE_DEFAULT = 1;
   418     private static final int FOCUS_TRAVERSABLE_SET = 2;
   418     private static final int FOCUS_TRAVERSABLE_SET = 2;
   419 
   419 
   420     /**
   420     /**
   421      * Tracks whether this Component is relying on default focus travesability.
   421      * Tracks whether this Component is relying on default focus traversability.
   422      *
   422      *
   423      * @serial
   423      * @serial
   424      * @since 1.4
   424      * @since 1.4
   425      */
   425      */
   426     private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
   426     private int isFocusTraversableOverridden = FOCUS_TRAVERSABLE_UNKNOWN;
   659     /*
   659     /*
   660      * In some cases using "this" as an object to synchronize by
   660      * In some cases using "this" as an object to synchronize by
   661      * can lead to a deadlock if client code also uses synchronization
   661      * can lead to a deadlock if client code also uses synchronization
   662      * by a component object. For every such situation revealed we should
   662      * by a component object. For every such situation revealed we should
   663      * consider possibility of replacing "this" with the package private
   663      * consider possibility of replacing "this" with the package private
   664      * objectLock object introduced below. So far there're 3 issues known:
   664      * objectLock object introduced below. So far there are 3 issues known:
   665      * - CR 6708322 (the getName/setName methods);
   665      * - CR 6708322 (the getName/setName methods);
   666      * - CR 6608764 (the PropertyChangeListener machinery);
   666      * - CR 6608764 (the PropertyChangeListener machinery);
   667      * - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
   667      * - CR 7108598 (the Container.paint/KeyboardFocusManager.clearMostRecentFocusOwner methods).
   668      *
   668      *
   669      * Note: this field is considered final, though readObject() prohibits
   669      * Note: this field is considered final, though readObject() prohibits
   781          */
   781          */
   782         OTHER
   782         OTHER
   783     }
   783     }
   784 
   784 
   785     /*
   785     /*
   786      * The shape set with the applyCompoundShape() method. It uncludes the result
   786      * The shape set with the applyCompoundShape() method. It includes the result
   787      * of the HW/LW mixing related shape computation. It may also include
   787      * of the HW/LW mixing related shape computation. It may also include
   788      * the user-specified shape of the component.
   788      * the user-specified shape of the component.
   789      * The 'null' value means the component has normal shape (or has no shape at all)
   789      * The 'null' value means the component has normal shape (or has no shape at all)
   790      * and applyCompoundShape() will skip the following shape identical to normal.
   790      * and applyCompoundShape() will skip the following shape identical to normal.
   791      */
   791      */
   806      */
   806      */
   807     private transient boolean isAddNotifyComplete = false;
   807     private transient boolean isAddNotifyComplete = false;
   808 
   808 
   809     /**
   809     /**
   810      * Should only be used in subclass getBounds to check that part of bounds
   810      * Should only be used in subclass getBounds to check that part of bounds
   811      * is actualy changing
   811      * is actually changing
   812      */
   812      */
   813     int getBoundsOp() {
   813     int getBoundsOp() {
   814         assert Thread.holdsLock(getTreeLock());
   814         assert Thread.holdsLock(getTreeLock());
   815         return boundsOp;
   815         return boundsOp;
   816     }
   816     }
  1689     void clearCurrentFocusCycleRootOnHide() {
  1689     void clearCurrentFocusCycleRootOnHide() {
  1690         /* do nothing */
  1690         /* do nothing */
  1691     }
  1691     }
  1692 
  1692 
  1693     /*
  1693     /*
  1694      * Delete references from LightweithDispatcher of a heavyweight parent
  1694      * Delete references from LightweightDispatcher of a heavyweight parent
  1695      */
  1695      */
  1696     void clearLightweightDispatcherOnRemove(Component removedComponent) {
  1696     void clearLightweightDispatcherOnRemove(Component removedComponent) {
  1697         if (parent != null) {
  1697         if (parent != null) {
  1698             parent.clearLightweightDispatcherOnRemove(removedComponent);
  1698             parent.clearLightweightDispatcherOnRemove(removedComponent);
  1699         }
  1699         }
  2335                 }
  2335                 }
  2336 
  2336 
  2337                 boolean needNotify = true;
  2337                 boolean needNotify = true;
  2338                 mixOnReshaping();
  2338                 mixOnReshaping();
  2339                 if (peer != null) {
  2339                 if (peer != null) {
  2340                     // LightwightPeer is an empty stub so can skip peer.reshape
  2340                     // LightweightPeer is an empty stub so can skip peer.reshape
  2341                     if (!(peer instanceof LightweightPeer)) {
  2341                     if (!(peer instanceof LightweightPeer)) {
  2342                         reshapeNativePeer(x, y, width, height, getBoundsOp());
  2342                         reshapeNativePeer(x, y, width, height, getBoundsOp());
  2343                         // Check peer actualy changed coordinates
  2343                         // Check peer actually changed coordinates
  2344                         resized = (oldWidth != this.width) || (oldHeight != this.height);
  2344                         resized = (oldWidth != this.width) || (oldHeight != this.height);
  2345                         moved = (oldX != this.x) || (oldY != this.y);
  2345                         moved = (oldX != this.x) || (oldY != this.y);
  2346                         // fix for 5025858: do not send ComponentEvents for toplevel
  2346                         // fix for 5025858: do not send ComponentEvents for toplevel
  2347                         // windows here as it is done from peer or native code when
  2347                         // windows here as it is done from peer or native code when
  2348                         // the window is really resized or moved, otherwise some
  2348                         // the window is really resized or moved, otherwise some
  5104                 ((AWTEvent)e).copyPrivateDataInto(newMWE);
  5104                 ((AWTEvent)e).copyPrivateDataInto(newMWE);
  5105                 // When dispatching a wheel event to
  5105                 // When dispatching a wheel event to
  5106                 // ancestor, there is no need trying to find descendant
  5106                 // ancestor, there is no need trying to find descendant
  5107                 // lightweights to dispatch event to.
  5107                 // lightweights to dispatch event to.
  5108                 // If we dispatch the event to toplevel ancestor,
  5108                 // If we dispatch the event to toplevel ancestor,
  5109                 // this could encolse the loop: 6480024.
  5109                 // this could enclose the loop: 6480024.
  5110                 anc.dispatchEventToSelf(newMWE);
  5110                 anc.dispatchEventToSelf(newMWE);
  5111                 if (newMWE.isConsumed()) {
  5111                 if (newMWE.isConsumed()) {
  5112                     e.consume();
  5112                     e.consume();
  5113                 }
  5113                 }
  5114                 return true;
  5114                 return true;
  6201 
  6201 
  6202     /**
  6202     /**
  6203      * Indicates whether this class overrides coalesceEvents.
  6203      * Indicates whether this class overrides coalesceEvents.
  6204      * It is assumed that all classes that are loaded from the bootstrap
  6204      * It is assumed that all classes that are loaded from the bootstrap
  6205      *   do not.
  6205      *   do not.
  6206      * The boostrap class loader is assumed to be represented by null.
  6206      * The bootstrap class loader is assumed to be represented by null.
  6207      * We do not check that the method really overrides
  6207      * We do not check that the method really overrides
  6208      *   (it might be static, private or package private).
  6208      *   (it might be static, private or package private).
  6209      */
  6209      */
  6210      private boolean checkCoalescing() {
  6210      private boolean checkCoalescing() {
  6211          if (getClass().getClassLoader()==null) {
  6211          if (getClass().getClassLoader()==null) {
  6249 
  6249 
  6250         // First check superclass - we may not need to bother ourselves.
  6250         // First check superclass - we may not need to bother ourselves.
  6251         Class<?> superclass = clazz.getSuperclass();
  6251         Class<?> superclass = clazz.getSuperclass();
  6252         if (superclass == null) {
  6252         if (superclass == null) {
  6253             // Only occurs on implementations that
  6253             // Only occurs on implementations that
  6254             //   do not use null to represent the bootsrap class loader.
  6254             //   do not use null to represent the bootstrap class loader.
  6255             return false;
  6255             return false;
  6256         }
  6256         }
  6257         if (superclass.getClassLoader() != null) {
  6257         if (superclass.getClassLoader() != null) {
  6258             Boolean value = coalesceMap.get(superclass);
  6258             Boolean value = coalesceMap.get(superclass);
  6259             if (value == null) {
  6259             if (value == null) {
  7759 
  7759 
  7760         Component window = this;
  7760         Component window = this;
  7761         while ( (window != null) && !(window instanceof Window)) {
  7761         while ( (window != null) && !(window instanceof Window)) {
  7762             if (!window.isVisible()) {
  7762             if (!window.isVisible()) {
  7763                 if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
  7763                 if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
  7764                     focusLog.finest("component is recurively invisible");
  7764                     focusLog.finest("component is recursively invisible");
  7765                 }
  7765                 }
  7766                 return false;
  7766                 return false;
  7767             }
  7767             }
  7768             window = window.parent;
  7768             window = window.parent;
  7769         }
  7769         }
  7863         if (CausedFocusEvent.Cause.ACTIVATION == cause) {
  7863         if (CausedFocusEvent.Cause.ACTIVATION == cause) {
  7864             // we shouldn't call RequestFocusController in case we are
  7864             // we shouldn't call RequestFocusController in case we are
  7865             // in activation.  We do request focus on component which
  7865             // in activation.  We do request focus on component which
  7866             // has got temporary focus lost and then on component which is
  7866             // has got temporary focus lost and then on component which is
  7867             // most recent focus owner.  But most recent focus owner can be
  7867             // most recent focus owner.  But most recent focus owner can be
  7868             // changed by requestFocsuXXX() call only, so this transfer has
  7868             // changed by requestFocusXXX() call only, so this transfer has
  7869             // been already approved.
  7869             // been already approved.
  7870             if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
  7870             if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
  7871                 focusLog.finest("cause is activation");
  7871                 focusLog.finest("cause is activation");
  7872             }
  7872             }
  7873             return true;
  7873             return true;
  8690      */
  8690      */
  8691     private void doSwingSerialization() {
  8691     private void doSwingSerialization() {
  8692         Package swingPackage = Package.getPackage("javax.swing");
  8692         Package swingPackage = Package.getPackage("javax.swing");
  8693         // For Swing serialization to correctly work Swing needs to
  8693         // For Swing serialization to correctly work Swing needs to
  8694         // be notified before Component does it's serialization.  This
  8694         // be notified before Component does it's serialization.  This
  8695         // hack accomodates this.
  8695         // hack accommodates this.
  8696         //
  8696         //
  8697         // Swing classes MUST be loaded by the bootstrap class loader,
  8697         // Swing classes MUST be loaded by the bootstrap class loader,
  8698         // otherwise we don't consider them.
  8698         // otherwise we don't consider them.
  8699         for (Class<?> klass = Component.this.getClass(); klass != null;
  8699         for (Class<?> klass = Component.this.getClass(); klass != null;
  8700                    klass = klass.getSuperclass()) {
  8700                    klass = klass.getSuperclass()) {
  9038         }
  9038         }
  9039         return false;
  9039         return false;
  9040     }
  9040     }
  9041 
  9041 
  9042     /**
  9042     /**
  9043      * Checks that this component meets the prerequesites to be focus owner:
  9043      * Checks that this component meets the prerequisites to be focus owner:
  9044      * - it is enabled, visible, focusable
  9044      * - it is enabled, visible, focusable
  9045      * - it's parents are all enabled and showing
  9045      * - it's parents are all enabled and showing
  9046      * - top-level window is focusable
  9046      * - top-level window is focusable
  9047      * - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts
  9047      * - if focus cycle root has DefaultFocusTraversalPolicy then it also checks that this policy accepts
  9048      * this component as focus owner
  9048      * this component as focus owner
  9647         }
  9647         }
  9648 
  9648 
  9649         /**
  9649         /**
  9650          * Returns the size of this object in the form of a
  9650          * Returns the size of this object in the form of a
  9651          * <code>Dimension</code> object. The height field of the
  9651          * <code>Dimension</code> object. The height field of the
  9652          * <code>Dimension</code> object contains this objects's
  9652          * <code>Dimension</code> object contains this object's
  9653          * height, and the width field of the <code>Dimension</code>
  9653          * height, and the width field of the <code>Dimension</code>
  9654          * object contains this object's width.
  9654          * object contains this object's width.
  9655          *
  9655          *
  9656          * @return a <code>Dimension</code> object that indicates
  9656          * @return a <code>Dimension</code> object that indicates
  9657          *     the size of this component; <code>null</code> if
  9657          *     the size of this component; <code>null</code> if
  9831     // ************************** MIXING CODE *******************************
  9831     // ************************** MIXING CODE *******************************
  9832 
  9832 
  9833     /**
  9833     /**
  9834      * Check whether we can trust the current bounds of the component.
  9834      * Check whether we can trust the current bounds of the component.
  9835      * The return value of false indicates that the container of the
  9835      * The return value of false indicates that the container of the
  9836      * component is invalid, and therefore needs to be layed out, which would
  9836      * component is invalid, and therefore needs to be laid out, which would
  9837      * probably mean changing the bounds of its children.
  9837      * probably mean changing the bounds of its children.
  9838      * Null-layout of the container or absence of the container mean
  9838      * Null-layout of the container or absence of the container mean
  9839      * the bounds of the component are final and can be trusted.
  9839      * the bounds of the component are final and can be trusted.
  9840      */
  9840      */
  9841     final boolean areBoundsValid() {
  9841     final boolean areBoundsValid() {