< prev index next >

src/solaris/classes/sun/awt/X11/XComponentPeer.java

Print this page
rev 1571 : 8010297: Missing isLoggable() checks in logging code
Summary: Add isLoggable() checks
Reviewed-by: anthony, mchung, serb
Contributed-by: Laurent Bourges <bourges.laurent@gmail.com>


 399 
 400     final public boolean requestFocus(Component lightweightChild, boolean temporary,
 401                                       boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
 402     {
 403         if (processSynchronousLightweightTransfer(target, lightweightChild, temporary,
 404                                                   focusedWindowChangeAllowed, time))
 405         {
 406             return true;
 407         }
 408 
 409         int result = XKeyboardFocusManagerPeer
 410             .shouldNativelyFocusHeavyweight(target, lightweightChild,
 411                                             temporary, focusedWindowChangeAllowed, time, cause);
 412 
 413         switch (result) {
 414           case SNFH_FAILURE:
 415               return false;
 416           case SNFH_SUCCESS_PROCEED:
 417               // Currently we just generate focus events like we deal with lightweight instead of calling
 418               // XSetInputFocus on native window
 419               if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Proceeding with request to " + lightweightChild + " in " + target);



 420               /**
 421                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
 422                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
 423                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
 424                * in requests list - and it breaks our requests sequence as first record on WGF should be the last focus
 425                * owner which had focus before WLF. So, we should not add request record for such requests
 426                * but store this component in mostRecent - and return true as before for compatibility.
 427                */
 428               Window parentWindow = getContainingWindow(target);
 429               if (parentWindow != null) {
 430                   // and check that it is focused
 431                   if (!parentWindow.isFocused()) {
 432                       XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer();
 433                       /*
 434                        * Fix for 6314575.
 435                        * Shouldn't restore focus on 'actualFocusedWindow'
 436                        * when a component inside a Frame is requesting it.
 437                        */
 438                       wpeer.setActualFocusedWindow(null);
 439 
 440                       boolean res = wpeer.requestWindowFocus();
 441                       if (focusLog.isLoggable(Level.FINER)) focusLog.finer("Requested window focus: " + res);


 442                       // If parent window can be made focused and has been made focused(synchronously)
 443                       // then we can proceed with children, otherwise we retreat.
 444                       if (!(res && parentWindow.isFocused())) {

 445                           focusLog.finer("Waiting for asynchronous processing of window focus request");

 446                           KeyboardFocusManagerPeerImpl.removeLastFocusRequest(target);
 447                           return false;
 448                       }
 449                   }
 450               } else {
 451                   if (focusLog.isLoggable(Level.FINER)) focusLog.finer("WARNING: Parent window is null");


 452                   return false;
 453               }
 454 
 455               // NOTE: We simulate heavyweight behavior of Motif - component receives focus right
 456               // after request, not after event. Normally, we should better listen for event
 457               // by listeners.
 458               return XKeyboardFocusManagerPeer.simulateMotifRequestFocus(lightweightChild, target, temporary,
 459                                                                          focusedWindowChangeAllowed, time, cause);
 460               // Motif compatibility code
 461           case SNFH_SUCCESS_HANDLED:
 462               // Either lightweight or excessive request - all events are generated.
 463               return true;
 464         }
 465         return false;
 466     }
 467 
 468     void handleJavaFocusEvent(AWTEvent e) {
 469         if (focusLog.isLoggable(Level.FINER)) focusLog.finer(e.toString());


 470         if (e.getID() == FocusEvent.FOCUS_GAINED) {
 471             focusGained((FocusEvent)e);
 472         } else {
 473             focusLost((FocusEvent)e);
 474         }
 475     }
 476 
 477     void handleJavaWindowFocusEvent(AWTEvent e) {
 478     }
 479 
 480     /*************************************************
 481      * END OF FOCUS STUFF
 482      *************************************************/
 483 
 484 
 485 
 486     public void setVisible(boolean b) {
 487         xSetVisible(b);
 488     }
 489 


 761 
 762     /*
 763      * Draw a 3D rectangle using the Motif colors.
 764      * "Normal" rectangles have shadows on the bottom.
 765      * "Depressed" rectangles (such as pressed buttons) have shadows on the top,
 766      * in which case true should be passed for topShadow.
 767      */
 768     public void drawMotif3DRect(Graphics g,
 769                                           int x, int y, int width, int height,
 770                                           boolean topShadow) {
 771         g.setColor(topShadow ? darkShadow : lightShadow);
 772         g.drawLine(x, y, x+width, y);       // top
 773         g.drawLine(x, y+height, x, y);      // left
 774 
 775         g.setColor(topShadow ? lightShadow : darkShadow );
 776         g.drawLine(x+1, y+height, x+width, y+height); // bottom
 777         g.drawLine(x+width, y+height, x+width, y+1);  // right
 778     }
 779 
 780     public void setBackground(Color c) {
 781         if (log.isLoggable(Level.FINE)) log.fine("Set background to " + c);


 782         synchronized (getStateLock()) {
 783             if (background == null) {
 784                 if (c == null) return;
 785             } else if (background.equals(c)) {
 786                 return;
 787             }
 788             background = c;
 789         }
 790         super.setBackground(c);
 791         repaint();
 792     }
 793 
 794     public void setForeground(Color c) {
 795         if (log.isLoggable(Level.FINE)) log.fine("Set foreground to " + c);


 796         synchronized (getStateLock()) {
 797             if (foreground == null) {
 798                 if (c == null) return;
 799             } else if (foreground.equals(c)) {
 800                 return;
 801             }
 802             foreground = c;
 803         }
 804         repaint();
 805     }
 806 
 807     /**
 808      * Gets the font metrics for the specified font.
 809      * @param font the font for which font metrics is to be
 810      *      obtained
 811      * @return the font metrics for <code>font</code>
 812      * @see       #getFont
 813      * @see       #getPeer
 814      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
 815      * @see       Toolkit#getFontMetrics(Font)
 816      * @since     JDK1.0
 817      */
 818     public FontMetrics getFontMetrics(Font font) {
 819         if (fontLog.isLoggable(Level.FINE)) fontLog.fine("Getting font metrics for " + font);


 820         return sun.font.FontDesignMetrics.getMetrics(font);
 821     }
 822 
 823     public void setFont(Font f) {
 824         if (f == null) {
 825             f = defaultFont;
 826         }
 827         synchronized (getStateLock()) {
 828             if (f.equals(font)) {
 829                 return;
 830             }
 831             font = f;
 832         }
 833         // as it stands currently we dont need to do layout since
 834         // layout is done in the Component upon setFont.
 835         //layout();
 836         repaint();
 837     }
 838 
 839     public Font getFont() {




 399 
 400     final public boolean requestFocus(Component lightweightChild, boolean temporary,
 401                                       boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause)
 402     {
 403         if (processSynchronousLightweightTransfer(target, lightweightChild, temporary,
 404                                                   focusedWindowChangeAllowed, time))
 405         {
 406             return true;
 407         }
 408 
 409         int result = XKeyboardFocusManagerPeer
 410             .shouldNativelyFocusHeavyweight(target, lightweightChild,
 411                                             temporary, focusedWindowChangeAllowed, time, cause);
 412 
 413         switch (result) {
 414           case SNFH_FAILURE:
 415               return false;
 416           case SNFH_SUCCESS_PROCEED:
 417               // Currently we just generate focus events like we deal with lightweight instead of calling
 418               // XSetInputFocus on native window
 419               if (focusLog.isLoggable(Level.FINER)) {
 420                   focusLog.finer("Proceeding with request to " +
 421                                  lightweightChild + " in " + target);
 422               }
 423               /**
 424                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
 425                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
 426                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
 427                * in requests list - and it breaks our requests sequence as first record on WGF should be the last focus
 428                * owner which had focus before WLF. So, we should not add request record for such requests
 429                * but store this component in mostRecent - and return true as before for compatibility.
 430                */
 431               Window parentWindow = getContainingWindow(target);
 432               if (parentWindow != null) {
 433                   // and check that it is focused
 434                   if (!parentWindow.isFocused()) {
 435                       XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer();
 436                       /*
 437                        * Fix for 6314575.
 438                        * Shouldn't restore focus on 'actualFocusedWindow'
 439                        * when a component inside a Frame is requesting it.
 440                        */
 441                       wpeer.setActualFocusedWindow(null);
 442 
 443                       boolean res = wpeer.requestWindowFocus();
 444                       if (focusLog.isLoggable(Level.FINER)) {
 445                           focusLog.finer("Requested window focus: " + res);
 446                       }
 447                       // If parent window can be made focused and has been made focused(synchronously)
 448                       // then we can proceed with children, otherwise we retreat.
 449                       if (!(res && parentWindow.isFocused())) {
 450                           if (focusLog.isLoggable(Level.FINER)) {
 451                               focusLog.finer("Waiting for asynchronous processing of window focus request");
 452                           }
 453                           KeyboardFocusManagerPeerImpl.removeLastFocusRequest(target);
 454                           return false;
 455                       }
 456                   }
 457               } else {
 458                   if (focusLog.isLoggable(Level.FINER)) {
 459                       focusLog.finer("WARNING: Parent window is null");
 460                   }
 461                   return false;
 462               }
 463 
 464               // NOTE: We simulate heavyweight behavior of Motif - component receives focus right
 465               // after request, not after event. Normally, we should better listen for event
 466               // by listeners.
 467               return XKeyboardFocusManagerPeer.simulateMotifRequestFocus(lightweightChild, target, temporary,
 468                                                                          focusedWindowChangeAllowed, time, cause);
 469               // Motif compatibility code
 470           case SNFH_SUCCESS_HANDLED:
 471               // Either lightweight or excessive request - all events are generated.
 472               return true;
 473         }
 474         return false;
 475     }
 476 
 477     void handleJavaFocusEvent(AWTEvent e) {
 478         if (focusLog.isLoggable(Level.FINER)) {
 479             focusLog.finer(e.toString());
 480         }
 481         if (e.getID() == FocusEvent.FOCUS_GAINED) {
 482             focusGained((FocusEvent)e);
 483         } else {
 484             focusLost((FocusEvent)e);
 485         }
 486     }
 487 
 488     void handleJavaWindowFocusEvent(AWTEvent e) {
 489     }
 490 
 491     /*************************************************
 492      * END OF FOCUS STUFF
 493      *************************************************/
 494 
 495 
 496 
 497     public void setVisible(boolean b) {
 498         xSetVisible(b);
 499     }
 500 


 772 
 773     /*
 774      * Draw a 3D rectangle using the Motif colors.
 775      * "Normal" rectangles have shadows on the bottom.
 776      * "Depressed" rectangles (such as pressed buttons) have shadows on the top,
 777      * in which case true should be passed for topShadow.
 778      */
 779     public void drawMotif3DRect(Graphics g,
 780                                           int x, int y, int width, int height,
 781                                           boolean topShadow) {
 782         g.setColor(topShadow ? darkShadow : lightShadow);
 783         g.drawLine(x, y, x+width, y);       // top
 784         g.drawLine(x, y+height, x, y);      // left
 785 
 786         g.setColor(topShadow ? lightShadow : darkShadow );
 787         g.drawLine(x+1, y+height, x+width, y+height); // bottom
 788         g.drawLine(x+width, y+height, x+width, y+1);  // right
 789     }
 790 
 791     public void setBackground(Color c) {
 792         if (log.isLoggable(Level.FINE)) {
 793             log.fine("Set background to " + c);
 794         }
 795         synchronized (getStateLock()) {
 796             if (background == null) {
 797                 if (c == null) return;
 798             } else if (background.equals(c)) {
 799                 return;
 800             }
 801             background = c;
 802         }
 803         super.setBackground(c);
 804         repaint();
 805     }
 806 
 807     public void setForeground(Color c) {
 808         if (log.isLoggable(Level.FINE)) {
 809             log.fine("Set foreground to " + c);
 810         }
 811         synchronized (getStateLock()) {
 812             if (foreground == null) {
 813                 if (c == null) return;
 814             } else if (foreground.equals(c)) {
 815                 return;
 816             }
 817             foreground = c;
 818         }
 819         repaint();
 820     }
 821 
 822     /**
 823      * Gets the font metrics for the specified font.
 824      * @param font the font for which font metrics is to be
 825      *      obtained
 826      * @return the font metrics for <code>font</code>
 827      * @see       #getFont
 828      * @see       #getPeer
 829      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
 830      * @see       Toolkit#getFontMetrics(Font)
 831      * @since     JDK1.0
 832      */
 833     public FontMetrics getFontMetrics(Font font) {
 834         if (fontLog.isLoggable(Level.FINE)) {
 835             fontLog.fine("Getting font metrics for " + font);
 836         }
 837         return sun.font.FontDesignMetrics.getMetrics(font);
 838     }
 839 
 840     public void setFont(Font f) {
 841         if (f == null) {
 842             f = defaultFont;
 843         }
 844         synchronized (getStateLock()) {
 845             if (f.equals(font)) {
 846                 return;
 847             }
 848             font = f;
 849         }
 850         // as it stands currently we dont need to do layout since
 851         // layout is done in the Component upon setFont.
 852         //layout();
 853         repaint();
 854     }
 855 
 856     public Font getFont() {


< prev index next >