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

Print this page




 280                                       CausedFocusEvent.Cause cause)
 281     {
 282         if (XKeyboardFocusManagerPeer.
 283             processSynchronousLightweightTransfer(target, lightweightChild, temporary,
 284                                                   focusedWindowChangeAllowed, time))
 285         {
 286             return true;
 287         }
 288 
 289         int result = XKeyboardFocusManagerPeer.
 290             shouldNativelyFocusHeavyweight(target, lightweightChild,
 291                                            temporary, focusedWindowChangeAllowed,
 292                                            time, cause);
 293 
 294         switch (result) {
 295           case XKeyboardFocusManagerPeer.SNFH_FAILURE:
 296               return false;
 297           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 298               // Currently we just generate focus events like we deal with lightweight instead of calling
 299               // XSetInputFocus on native window
 300               if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Proceeding with request to " +

 301                   lightweightChild + " in " + target);

 302               /**
 303                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
 304                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
 305                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
 306                * in requests list - and it breaks our requests sequence as first record on WGF should be the last
 307                * focus owner which had focus before WLF. So, we should not add request record for such requests
 308                * but store this component in mostRecent - and return true as before for compatibility.
 309                */
 310               Window parentWindow = SunToolkit.getContainingWindow(target);
 311               if (parentWindow == null) {
 312                   return rejectFocusRequestHelper("WARNING: Parent window is null");
 313               }
 314               XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer();
 315               if (wpeer == null) {
 316                   return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
 317               }
 318               /*
 319                * Passing null 'actualFocusedWindow' as we don't want to restore focus on it
 320                * when a component inside a Frame is requesting focus.
 321                * See 6314575 for details.
 322                */
 323               boolean res = wpeer.requestWindowFocus(null);
 324 
 325               if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res);


 326               // If parent window can be made focused and has been made focused(synchronously)
 327               // then we can proceed with children, otherwise we retreat.
 328               if (!(res && parentWindow.isFocused())) {
 329                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
 330               }
 331               return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
 332                                                             (Component)target,
 333                                                             temporary,
 334                                                             focusedWindowChangeAllowed,
 335                                                             time, cause);
 336               // Motif compatibility code
 337           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
 338               // Either lightweight or excessive request - all events are generated.
 339               return true;
 340         }
 341         return false;
 342     }
 343 
 344     private boolean rejectFocusRequestHelper(String logMsg) {
 345         if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg);


 346         XKeyboardFocusManagerPeer.removeLastFocusRequest(target);
 347         return false;
 348     }
 349 
 350     void handleJavaFocusEvent(AWTEvent e) {
 351         if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(e.toString());


 352         if (e.getID() == FocusEvent.FOCUS_GAINED) {
 353             focusGained((FocusEvent)e);
 354         } else {
 355             focusLost((FocusEvent)e);
 356         }
 357     }
 358 
 359     void handleJavaWindowFocusEvent(AWTEvent e) {
 360     }
 361 
 362     /*************************************************
 363      * END OF FOCUS STUFF
 364      *************************************************/
 365 
 366 
 367 
 368     public void setVisible(boolean b) {
 369         xSetVisible(b);
 370     }
 371 


 614 
 615     /*
 616      * Draw a 3D rectangle using the Motif colors.
 617      * "Normal" rectangles have shadows on the bottom.
 618      * "Depressed" rectangles (such as pressed buttons) have shadows on the top,
 619      * in which case true should be passed for topShadow.
 620      */
 621     public void drawMotif3DRect(Graphics g,
 622                                           int x, int y, int width, int height,
 623                                           boolean topShadow) {
 624         g.setColor(topShadow ? darkShadow : lightShadow);
 625         g.drawLine(x, y, x+width, y);       // top
 626         g.drawLine(x, y+height, x, y);      // left
 627 
 628         g.setColor(topShadow ? lightShadow : darkShadow );
 629         g.drawLine(x+1, y+height, x+width, y+height); // bottom
 630         g.drawLine(x+width, y+height, x+width, y+1);  // right
 631     }
 632 
 633     public void setBackground(Color c) {
 634         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set background to " + c);


 635         synchronized (getStateLock()) {
 636             background = c;
 637         }
 638         super.setBackground(c);
 639         repaint();
 640     }
 641 
 642     public void setForeground(Color c) {
 643         if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set foreground to " + c);


 644         synchronized (getStateLock()) {
 645             foreground = c;
 646         }
 647         repaint();
 648     }
 649 
 650     /**
 651      * Gets the font metrics for the specified font.
 652      * @param font the font for which font metrics is to be
 653      *      obtained
 654      * @return the font metrics for <code>font</code>
 655      * @see       #getFont
 656      * @see       #getPeer
 657      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
 658      * @see       Toolkit#getFontMetrics(Font)
 659      * @since     JDK1.0
 660      */
 661     public FontMetrics getFontMetrics(Font font) {
 662         if (fontLog.isLoggable(PlatformLogger.FINE)) fontLog.fine("Getting font metrics for " + font);


 663         return sun.font.FontDesignMetrics.getMetrics(font);
 664     }
 665 
 666     public void setFont(Font f) {
 667         synchronized (getStateLock()) {
 668             if (f == null) {
 669                 f = XWindow.getDefaultFont();
 670             }
 671             font = f;
 672         }
 673         // as it stands currently we dont need to do layout or repaint since
 674         // layout is done in the Component upon setFont.
 675         //layout();
 676         // target.repaint();
 677         //repaint()?
 678     }
 679 
 680     public Font getFont() {
 681         return font;
 682     }




 280                                       CausedFocusEvent.Cause cause)
 281     {
 282         if (XKeyboardFocusManagerPeer.
 283             processSynchronousLightweightTransfer(target, lightweightChild, temporary,
 284                                                   focusedWindowChangeAllowed, time))
 285         {
 286             return true;
 287         }
 288 
 289         int result = XKeyboardFocusManagerPeer.
 290             shouldNativelyFocusHeavyweight(target, lightweightChild,
 291                                            temporary, focusedWindowChangeAllowed,
 292                                            time, cause);
 293 
 294         switch (result) {
 295           case XKeyboardFocusManagerPeer.SNFH_FAILURE:
 296               return false;
 297           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 298               // Currently we just generate focus events like we deal with lightweight instead of calling
 299               // XSetInputFocus on native window
 300               if (focusLog.isLoggable(PlatformLogger.FINER)) {
 301                   focusLog.finer("Proceeding with request to " +
 302                                  lightweightChild + " in " + target);
 303               }
 304               /**
 305                * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
 306                * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
 307                * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
 308                * in requests list - and it breaks our requests sequence as first record on WGF should be the last
 309                * focus owner which had focus before WLF. So, we should not add request record for such requests
 310                * but store this component in mostRecent - and return true as before for compatibility.
 311                */
 312               Window parentWindow = SunToolkit.getContainingWindow(target);
 313               if (parentWindow == null) {
 314                   return rejectFocusRequestHelper("WARNING: Parent window is null");
 315               }
 316               XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer();
 317               if (wpeer == null) {
 318                   return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
 319               }
 320               /*
 321                * Passing null 'actualFocusedWindow' as we don't want to restore focus on it
 322                * when a component inside a Frame is requesting focus.
 323                * See 6314575 for details.
 324                */
 325               boolean res = wpeer.requestWindowFocus(null);
 326 
 327               if (focusLog.isLoggable(PlatformLogger.FINER)) {
 328                   focusLog.finer("Requested window focus: " + res);
 329               }
 330               // If parent window can be made focused and has been made focused(synchronously)
 331               // then we can proceed with children, otherwise we retreat.
 332               if (!(res && parentWindow.isFocused())) {
 333                   return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
 334               }
 335               return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
 336                                                             (Component)target,
 337                                                             temporary,
 338                                                             focusedWindowChangeAllowed,
 339                                                             time, cause);
 340               // Motif compatibility code
 341           case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
 342               // Either lightweight or excessive request - all events are generated.
 343               return true;
 344         }
 345         return false;
 346     }
 347 
 348     private boolean rejectFocusRequestHelper(String logMsg) {
 349         if (focusLog.isLoggable(PlatformLogger.FINER)) {
 350             focusLog.finer(logMsg);
 351         }
 352         XKeyboardFocusManagerPeer.removeLastFocusRequest(target);
 353         return false;
 354     }
 355 
 356     void handleJavaFocusEvent(AWTEvent e) {
 357         if (focusLog.isLoggable(PlatformLogger.FINER)) {
 358             focusLog.finer(e.toString());
 359         }
 360         if (e.getID() == FocusEvent.FOCUS_GAINED) {
 361             focusGained((FocusEvent)e);
 362         } else {
 363             focusLost((FocusEvent)e);
 364         }
 365     }
 366 
 367     void handleJavaWindowFocusEvent(AWTEvent e) {
 368     }
 369 
 370     /*************************************************
 371      * END OF FOCUS STUFF
 372      *************************************************/
 373 
 374 
 375 
 376     public void setVisible(boolean b) {
 377         xSetVisible(b);
 378     }
 379 


 622 
 623     /*
 624      * Draw a 3D rectangle using the Motif colors.
 625      * "Normal" rectangles have shadows on the bottom.
 626      * "Depressed" rectangles (such as pressed buttons) have shadows on the top,
 627      * in which case true should be passed for topShadow.
 628      */
 629     public void drawMotif3DRect(Graphics g,
 630                                           int x, int y, int width, int height,
 631                                           boolean topShadow) {
 632         g.setColor(topShadow ? darkShadow : lightShadow);
 633         g.drawLine(x, y, x+width, y);       // top
 634         g.drawLine(x, y+height, x, y);      // left
 635 
 636         g.setColor(topShadow ? lightShadow : darkShadow );
 637         g.drawLine(x+1, y+height, x+width, y+height); // bottom
 638         g.drawLine(x+width, y+height, x+width, y+1);  // right
 639     }
 640 
 641     public void setBackground(Color c) {
 642         if (log.isLoggable(PlatformLogger.FINE)) {
 643             log.fine("Set background to " + c);
 644         }
 645         synchronized (getStateLock()) {
 646             background = c;
 647         }
 648         super.setBackground(c);
 649         repaint();
 650     }
 651 
 652     public void setForeground(Color c) {
 653         if (log.isLoggable(PlatformLogger.FINE)) {
 654             log.fine("Set foreground to " + c);
 655         }
 656         synchronized (getStateLock()) {
 657             foreground = c;
 658         }
 659         repaint();
 660     }
 661 
 662     /**
 663      * Gets the font metrics for the specified font.
 664      * @param font the font for which font metrics is to be
 665      *      obtained
 666      * @return the font metrics for <code>font</code>
 667      * @see       #getFont
 668      * @see       #getPeer
 669      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
 670      * @see       Toolkit#getFontMetrics(Font)
 671      * @since     JDK1.0
 672      */
 673     public FontMetrics getFontMetrics(Font font) {
 674         if (fontLog.isLoggable(PlatformLogger.FINE)) {
 675             fontLog.fine("Getting font metrics for " + font);
 676         }
 677         return sun.font.FontDesignMetrics.getMetrics(font);
 678     }
 679 
 680     public void setFont(Font f) {
 681         synchronized (getStateLock()) {
 682             if (f == null) {
 683                 f = XWindow.getDefaultFont();
 684             }
 685             font = f;
 686         }
 687         // as it stands currently we dont need to do layout or repaint since
 688         // layout is done in the Component upon setFont.
 689         //layout();
 690         // target.repaint();
 691         //repaint()?
 692     }
 693 
 694     public Font getFont() {
 695         return font;
 696     }