src/macosx/classes/sun/lwawt/LWComponentPeer.java

Print this page




 446                 applyConstrain(g);
 447             }
 448         }
 449         return g;
 450     }
 451 
 452     /*
 453      * Peer Graphics is borrowed from the parent peer, while
 454      * foreground and background colors and font are specific to
 455      * this peer.
 456      */
 457     public final Graphics getOnscreenGraphics() {
 458         final LWWindowPeer wp = getWindowPeerOrSelf();
 459         return wp.getOnscreenGraphics(getForeground(), getBackground(),
 460                                       getFont());
 461 
 462     }
 463 
 464     private void applyConstrain(final Graphics g) {
 465         final SunGraphics2D sg2d = (SunGraphics2D) g;
 466         final Rectangle constr = localToWindow(getSize());
 467         // translate and set rectangle constrain.
 468         sg2d.constrain(constr.x, constr.y, constr.width, constr.height);
 469         // set region constrain.
 470         //sg2d.constrain(getVisibleRegion());
 471         SG2DConstraint(sg2d, getVisibleRegion());
 472     }
 473 
 474     //TODO Move this method to SG2D?
 475     void SG2DConstraint(final SunGraphics2D sg2d, Region r) {
 476         sg2d.constrainX = sg2d.transX;
 477         sg2d.constrainY = sg2d.transY;
 478 
 479         Region c = sg2d.constrainClip;
 480         if ((sg2d.constrainX | sg2d.constrainY) != 0) {
 481             r = r.getTranslatedRegion(sg2d.constrainX, sg2d.constrainY);
 482         }
 483         if (c == null) {
 484             c = r;
 485         } else {
 486             c = c.getIntersection(r);
 487             if (c == sg2d.constrainClip) {
 488                 // Common case to ignore
 489                 return;
 490             }
 491         }
 492         sg2d.constrainClip = c;
 493         //validateCompClip() forced call.
 494         sg2d.setDevClip(r.getLoX(), r.getLoY(), r.getWidth(), r.getHeight());
 495     }
 496 
 497     public Region getVisibleRegion() {
 498         return computeVisibleRect(this, getRegion());
 499     }
 500 
 501     static final Region computeVisibleRect(LWComponentPeer c, Region region) {
 502         final LWContainerPeer p = c.getContainerPeer();
 503         if (p != null) {
 504             final Rectangle r = c.getBounds();
 505             region = region.getTranslatedRegion(r.x, r.y);
 506             region = region.getIntersection(p.getRegion());
 507             region = region.getIntersection(p.getContentSize());
 508             region = p.cutChildren(region, c);
 509             region = computeVisibleRect(p, region);
 510             region = region.getTranslatedRegion(-r.x, -r.y);
 511         }
 512         return region;
 513     }
 514 




 446                 applyConstrain(g);
 447             }
 448         }
 449         return g;
 450     }
 451 
 452     /*
 453      * Peer Graphics is borrowed from the parent peer, while
 454      * foreground and background colors and font are specific to
 455      * this peer.
 456      */
 457     public final Graphics getOnscreenGraphics() {
 458         final LWWindowPeer wp = getWindowPeerOrSelf();
 459         return wp.getOnscreenGraphics(getForeground(), getBackground(),
 460                                       getFont());
 461 
 462     }
 463 
 464     private void applyConstrain(final Graphics g) {
 465         final SunGraphics2D sg2d = (SunGraphics2D) g;
 466         final Rectangle size = localToWindow(getSize());
 467         sg2d.constrain(size.x, size.y, size.width, size.height, getVisibleRegion());



























 468     }
 469 
 470     public Region getVisibleRegion() {
 471         return computeVisibleRect(this, getRegion());
 472     }
 473 
 474     static final Region computeVisibleRect(LWComponentPeer c, Region region) {
 475         final LWContainerPeer p = c.getContainerPeer();
 476         if (p != null) {
 477             final Rectangle r = c.getBounds();
 478             region = region.getTranslatedRegion(r.x, r.y);
 479             region = region.getIntersection(p.getRegion());
 480             region = region.getIntersection(p.getContentSize());
 481             region = p.cutChildren(region, c);
 482             region = computeVisibleRect(p, region);
 483             region = region.getTranslatedRegion(-r.x, -r.y);
 484         }
 485         return region;
 486     }
 487