src/java.desktop/share/classes/java/awt/Component.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54397 65030bbf5ac1
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   350      *
   350      *
   351      * @since 1.4
   351      * @since 1.4
   352      * @see java.awt.image.BufferStrategy
   352      * @see java.awt.image.BufferStrategy
   353      * @see #getBufferStrategy()
   353      * @see #getBufferStrategy()
   354      */
   354      */
   355     transient BufferStrategy bufferStrategy = null;
   355     private transient BufferStrategy bufferStrategy = null;
   356 
   356 
   357     /**
   357     /**
   358      * True when the object should ignore all repaint events.
   358      * True when the object should ignore all repaint events.
   359      *
   359      *
   360      * @since 1.4
   360      * @since 1.4
   467      * @serial
   467      * @serial
   468      * @see #setFocusTraversalKeys
   468      * @see #setFocusTraversalKeys
   469      * @see #getFocusTraversalKeys
   469      * @see #getFocusTraversalKeys
   470      * @since 1.4
   470      * @since 1.4
   471      */
   471      */
       
   472     @SuppressWarnings("serial") // Not statically typed as Serializable
   472     Set<AWTKeyStroke>[] focusTraversalKeys;
   473     Set<AWTKeyStroke>[] focusTraversalKeys;
   473 
   474 
   474     private static final String[] focusTraversalKeyPropertyNames = {
   475     private static final String[] focusTraversalKeyPropertyNames = {
   475         "forwardFocusTraversalKeys",
   476         "forwardFocusTraversalKeys",
   476         "backwardFocusTraversalKeys",
   477         "backwardFocusTraversalKeys",
  4036          */
  4037          */
  4037 
  4038 
  4038          /**
  4039          /**
  4039           * The width of the back buffers
  4040           * The width of the back buffers
  4040           */
  4041           */
  4041         int width;
  4042         private int width;
  4042 
  4043 
  4043         /**
  4044         /**
  4044          * The height of the back buffers
  4045          * The height of the back buffers
  4045          */
  4046          */
  4046         int height;
  4047         private int height;
  4047 
  4048 
  4048         /**
  4049         /**
  4049          * Creates a new flipping buffer strategy for this component.
  4050          * Creates a new flipping buffer strategy for this component.
  4050          * The component must be a {@code Canvas} or {@code Window} or
  4051          * The component must be a {@code Canvas} or {@code Window} or
  4051          * {@code Applet}.
  4052          * {@code Applet}.
  4114             width = getWidth();
  4115             width = getWidth();
  4115             height = getHeight();
  4116             height = getHeight();
  4116 
  4117 
  4117             if (drawBuffer != null) {
  4118             if (drawBuffer != null) {
  4118                 // dispose the existing backbuffers
  4119                 // dispose the existing backbuffers
  4119                 drawBuffer = null;
  4120                 invalidate();
  4120                 drawVBuffer = null;
       
  4121                 destroyBuffers();
       
  4122                 // ... then recreate the backbuffers
  4121                 // ... then recreate the backbuffers
  4123             }
  4122             }
  4124 
  4123 
  4125             if (caps instanceof ExtendedBufferCapabilities) {
  4124             if (caps instanceof ExtendedBufferCapabilities) {
  4126                 ExtendedBufferCapabilities ebc =
  4125                 ExtendedBufferCapabilities ebc =
  4204                     "Component must have a valid peer");
  4203                     "Component must have a valid peer");
  4205             }
  4204             }
  4206         }
  4205         }
  4207 
  4206 
  4208         /**
  4207         /**
       
  4208          * Destroys the buffers and invalidates the state of FlipBufferStrategy.
       
  4209          */
       
  4210         private void invalidate() {
       
  4211             drawBuffer = null;
       
  4212             drawVBuffer = null;
       
  4213             destroyBuffers();
       
  4214         }
       
  4215 
       
  4216         /**
  4209          * Destroys the buffers created through this object
  4217          * Destroys the buffers created through this object
  4210          */
  4218          */
  4211         protected void destroyBuffers() {
  4219         protected void destroyBuffers() {
  4212             VSyncedBSManager.releaseVsync(this);
  4220             VSyncedBSManager.releaseVsync(this);
  4213             if (peer != null) {
  4221             if (peer != null) {
  4242 
  4250 
  4243         /**
  4251         /**
  4244          * Restore the drawing buffer if it has been lost
  4252          * Restore the drawing buffer if it has been lost
  4245          */
  4253          */
  4246         protected void revalidate() {
  4254         protected void revalidate() {
  4247             revalidate(true);
       
  4248         }
       
  4249 
       
  4250         void revalidate(boolean checkSize) {
       
  4251             validatedContents = false;
  4255             validatedContents = false;
  4252 
  4256             if (getWidth() != width || getHeight() != height
  4253             if (checkSize && (getWidth() != width || getHeight() != height)) {
  4257                     || drawBuffer == null) {
  4254                 // component has been resized; recreate the backbuffers
  4258                 // component has been resized or the peer was recreated;
       
  4259                 // recreate the backbuffers
  4255                 try {
  4260                 try {
  4256                     createBuffers(numBuffers, caps);
  4261                     createBuffers(numBuffers, caps);
  4257                 } catch (AWTException e) {
  4262                 } catch (AWTException e) {
  4258                     // shouldn't be possible
  4263                     // shouldn't be possible
  4259                 }
  4264                 }
  4327          */
  4332          */
  4328         public void dispose() {
  4333         public void dispose() {
  4329             if (Component.this.bufferStrategy == this) {
  4334             if (Component.this.bufferStrategy == this) {
  4330                 Component.this.bufferStrategy = null;
  4335                 Component.this.bufferStrategy = null;
  4331                 if (peer != null) {
  4336                 if (peer != null) {
  4332                     destroyBuffers();
  4337                     invalidate();
  4333                 }
  4338                 }
  4334             }
  4339             }
  4335         }
  4340         }
  4336 
  4341 
  4337     } // Inner class FlipBufferStrategy
  4342     } // Inner class FlipBufferStrategy
  7154             ComponentPeer p = peer;
  7159             ComponentPeer p = peer;
  7155             if (p != null) {
  7160             if (p != null) {
  7156                 boolean isLightweight = isLightweight();
  7161                 boolean isLightweight = isLightweight();
  7157 
  7162 
  7158                 if (bufferStrategy instanceof FlipBufferStrategy) {
  7163                 if (bufferStrategy instanceof FlipBufferStrategy) {
  7159                     ((FlipBufferStrategy)bufferStrategy).destroyBuffers();
  7164                     ((FlipBufferStrategy)bufferStrategy).invalidate();
  7160                 }
  7165                 }
  7161 
  7166 
  7162                 if (dropTarget != null) dropTarget.removeNotify();
  7167                 if (dropTarget != null) dropTarget.removeNotify();
  7163 
  7168 
  7164                 // Hide peer first to stop system events such as cursor moves.
  7169                 // Hide peer first to stop system events such as cursor moves.
  9287      */
  9292      */
  9288 
  9293 
  9289     /**
  9294     /**
  9290      * The {@code AccessibleContext} associated with this {@code Component}.
  9295      * The {@code AccessibleContext} associated with this {@code Component}.
  9291      */
  9296      */
       
  9297     @SuppressWarnings("serial") // Not statically typed as Serializable
  9292     protected AccessibleContext accessibleContext = null;
  9298     protected AccessibleContext accessibleContext = null;
  9293 
  9299 
  9294     /**
  9300     /**
  9295      * Gets the {@code AccessibleContext} associated
  9301      * Gets the {@code AccessibleContext} associated
  9296      * with this {@code Component}.
  9302      * with this {@code Component}.
  9338 
  9344 
  9339         /**
  9345         /**
  9340          * A component listener to track show/hide/resize events
  9346          * A component listener to track show/hide/resize events
  9341          * and convert them to PropertyChange events.
  9347          * and convert them to PropertyChange events.
  9342          */
  9348          */
       
  9349         @SuppressWarnings("serial") // Not statically typed as Serializable
  9343         protected ComponentListener accessibleAWTComponentHandler = null;
  9350         protected ComponentListener accessibleAWTComponentHandler = null;
  9344 
  9351 
  9345         /**
  9352         /**
  9346          * A listener to track focus events
  9353          * A listener to track focus events
  9347          * and convert them to PropertyChange events.
  9354          * and convert them to PropertyChange events.
  9348          */
  9355          */
       
  9356         @SuppressWarnings("serial") // Not statically typed as Serializable
  9349         protected FocusListener accessibleAWTFocusHandler = null;
  9357         protected FocusListener accessibleAWTFocusHandler = null;
  9350 
  9358 
  9351         /**
  9359         /**
  9352          * Fire PropertyChange listener, if one is registered,
  9360          * Fire PropertyChange listener, if one is registered,
  9353          * when shown/hidden..
  9361          * when shown/hidden..