jdk/src/share/classes/sun/awt/EmbeddedFrame.java
changeset 11264 54f2f4c6bd30
parent 7668 d4a77089c587
child 12813 c10ab96dcf41
equal deleted inserted replaced
11103:e156ce2c4a96 11264:54f2f4c6bd30
   178      * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
   178      * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
   179      * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
   179      * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
   180      * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
   180      * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
   181      * add listeners in show() and remove them in hide().
   181      * add listeners in show() and remove them in hide().
   182      */
   182      */
       
   183     @SuppressWarnings("deprecation")
   183     public void show() {
   184     public void show() {
   184         if (appletKFM != null) {
   185         if (appletKFM != null) {
   185             addTraversingOutListeners(appletKFM);
   186             addTraversingOutListeners(appletKFM);
   186         }
   187         }
   187         super.show();
   188         super.show();
   191      * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
   192      * Needed to avoid memory leak: we register this EmbeddedFrame as a listener with
   192      * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
   193      * KeyboardFocusManager of applet's AppContext. We don't want the KFM to keep
   193      * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
   194      * reference to our EmbeddedFrame forever if the Frame is no longer in use, so we
   194      * add listeners in show() and remove them in hide().
   195      * add listeners in show() and remove them in hide().
   195      */
   196      */
       
   197     @SuppressWarnings("deprecation")
   196     public void hide() {
   198     public void hide() {
   197         if (appletKFM != null) {
   199         if (appletKFM != null) {
   198             removeTraversingOutListeners(appletKFM);
   200             removeTraversingOutListeners(appletKFM);
   199         }
   201         }
   200         super.hide();
   202         super.hide();
   210 
   212 
   211         // We can't guarantee that this is called on the same AppContext as EmbeddedFrame
   213         // We can't guarantee that this is called on the same AppContext as EmbeddedFrame
   212         // belongs to. That's why we can't use public methods to find current focus cycle
   214         // belongs to. That's why we can't use public methods to find current focus cycle
   213         // root. Instead, we access KFM's private field directly.
   215         // root. Instead, we access KFM's private field directly.
   214         if (currentCycleRoot == null) {
   216         if (currentCycleRoot == null) {
   215             currentCycleRoot = (Field)AccessController.doPrivileged(new PrivilegedAction() {
   217             currentCycleRoot = AccessController.doPrivileged(new PrivilegedAction<Field>() {
   216                 public Object run() {
   218                 public Field run() {
   217                     try {
   219                     try {
   218                         Field unaccessibleRoot = KeyboardFocusManager.class.
   220                         Field unaccessibleRoot = KeyboardFocusManager.class.
   219                                                      getDeclaredField("currentFocusCycleRoot");
   221                                                      getDeclaredField("currentFocusCycleRoot");
   220                         if (unaccessibleRoot != null) {
   222                         if (unaccessibleRoot != null) {
   221                             unaccessibleRoot.setAccessible(true);
   223                             unaccessibleRoot.setAccessible(true);
   255         if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
   257         if (!getFocusTraversalKeysEnabled() || e.isConsumed()) {
   256             return false;
   258             return false;
   257         }
   259         }
   258 
   260 
   259         AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
   261         AWTKeyStroke stroke = AWTKeyStroke.getAWTKeyStrokeForEvent(e);
   260         Set toTest;
   262         Set<AWTKeyStroke> toTest;
   261         Component currentFocused = e.getComponent();
   263         Component currentFocused = e.getComponent();
   262 
   264 
   263         toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
   265         toTest = getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
   264         if (toTest.contains(stroke)) {
   266         if (toTest.contains(stroke)) {
   265             // 6581899: performance improvement for SortingFocusTraversalPolicy
   267             // 6581899: performance improvement for SortingFocusTraversalPolicy
   355 
   357 
   356     public boolean isResizable() {
   358     public boolean isResizable() {
   357         return true;
   359         return true;
   358     }
   360     }
   359 
   361 
       
   362     @SuppressWarnings("deprecation")
   360     public void addNotify() {
   363     public void addNotify() {
   361         synchronized (getTreeLock()) {
   364         synchronized (getTreeLock()) {
   362             if (getPeer() == null) {
   365             if (getPeer() == null) {
   363                 setPeer(new NullEmbeddedFramePeer());
   366                 setPeer(new NullEmbeddedFramePeer());
   364             }
   367             }
   365             super.addNotify();
   368             super.addNotify();
   366         }
   369         }
   367     }
   370     }
   368 
   371 
   369     // These three functions consitute RFE 4100710. Do not remove.
   372     // These three functions consitute RFE 4100710. Do not remove.
       
   373     @SuppressWarnings("deprecation")
   370     public void setCursorAllowed(boolean isCursorAllowed) {
   374     public void setCursorAllowed(boolean isCursorAllowed) {
   371         this.isCursorAllowed = isCursorAllowed;
   375         this.isCursorAllowed = isCursorAllowed;
   372         getPeer().updateCursorImmediately();
   376         getPeer().updateCursorImmediately();
   373     }
   377     }
   374     public boolean isCursorAllowed() {
   378     public boolean isCursorAllowed() {
   378         return (isCursorAllowed)
   382         return (isCursorAllowed)
   379             ? super.getCursor()
   383             ? super.getCursor()
   380             : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
   384             : Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
   381     }
   385     }
   382 
   386 
   383     protected  void setPeer(final ComponentPeer p){
   387     @SuppressWarnings("deprecation")
       
   388     protected void setPeer(final ComponentPeer p){
   384         if (fieldPeer == null) {
   389         if (fieldPeer == null) {
   385             fieldPeer = (Field)AccessController.doPrivileged(new PrivilegedAction() {
   390             fieldPeer = AccessController.doPrivileged(new PrivilegedAction<Field>() {
   386                     public Object run() {
   391                 public Field run() {
   387                         try {
   392                     try {
   388                             Field lnkPeer = Component.class.getDeclaredField("peer");
   393                         Field lnkPeer = Component.class.getDeclaredField("peer");
   389                             if (lnkPeer != null) {
   394                         if (lnkPeer != null) {
   390                                 lnkPeer.setAccessible(true);
   395                             lnkPeer.setAccessible(true);
   391                             }
       
   392                             return lnkPeer;
       
   393                         } catch (NoSuchFieldException e) {
       
   394                             assert false;
       
   395                         } catch (SecurityException e) {
       
   396                             assert false;
       
   397                         }
   396                         }
   398                         return null;
   397                         return lnkPeer;
   399                     }//run
   398                     } catch (NoSuchFieldException e) {
   400                 });
   399                         assert false;
       
   400                     } catch (SecurityException e) {
       
   401                         assert false;
       
   402                     }
       
   403                     return null;
       
   404                 }//run
       
   405             });
   401         }
   406         }
   402         try{
   407         try{
   403             if (fieldPeer !=null){
   408             if (fieldPeer != null){
   404                 fieldPeer.set(EmbeddedFrame.this, p);
   409                 fieldPeer.set(EmbeddedFrame.this, p);
   405             }
   410             }
   406         } catch (IllegalAccessException e) {
   411         } catch (IllegalAccessException e) {
   407             assert false;
   412             assert false;
   408         }
   413         }
   505      * @see #setLocationPrivate
   510      * @see #setLocationPrivate
   506      * @see #getLocationPrivate
   511      * @see #getLocationPrivate
   507      * @see #getBoundsPrivate
   512      * @see #getBoundsPrivate
   508      * @since 1.5
   513      * @since 1.5
   509      */
   514      */
       
   515     @SuppressWarnings("deprecation")
   510     protected void setBoundsPrivate(int x, int y, int width, int height) {
   516     protected void setBoundsPrivate(int x, int y, int width, int height) {
   511         final FramePeer peer = (FramePeer)getPeer();
   517         final FramePeer peer = (FramePeer)getPeer();
   512         if (peer != null) {
   518         if (peer != null) {
   513             peer.setBoundsPrivate(x, y, width, height);
   519             peer.setBoundsPrivate(x, y, width, height);
   514         }
   520         }
   536      * @see #setLocationPrivate
   542      * @see #setLocationPrivate
   537      * @see #getLocationPrivate
   543      * @see #getLocationPrivate
   538      * @see #setBoundsPrivate
   544      * @see #setBoundsPrivate
   539      * @since 1.6
   545      * @since 1.6
   540      */
   546      */
       
   547     @SuppressWarnings("deprecation")
   541     protected Rectangle getBoundsPrivate() {
   548     protected Rectangle getBoundsPrivate() {
   542         final FramePeer peer = (FramePeer)getPeer();
   549         final FramePeer peer = (FramePeer)getPeer();
   543         if (peer != null) {
   550         if (peer != null) {
   544             return peer.getBoundsPrivate();
   551             return peer.getBoundsPrivate();
   545         }
   552         }