< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WComponentPeer.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 562         }
 563         else {
 564             return null;
 565         }
 566     }
 567 
 568     // fallback default font object
 569     static final Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
 570 
 571     @Override
 572     public Graphics getGraphics() {
 573         if (isDisposed()) {
 574             return null;
 575         }
 576 
 577         Component target = (Component)getTarget();
 578         Window window = SunToolkit.getContainingWindow(target);
 579         if (window != null) {
 580             final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
 581                                                  .getPeer(window);

 582             Graphics g = wpeer.getTranslucentGraphics();
 583             // getTranslucentGraphics() returns non-null value for non-opaque windows only
 584             if (g != null) {
 585                 // Non-opaque windows do not support heavyweight children.
 586                 // Redirect all painting to the Window's Graphics instead.
 587                 // The caller is responsible for calling the
 588                 // WindowPeer.updateWindow() after painting has finished.
 589                 int x = 0, y = 0;
 590                 for (Component c = target; c != window; c = c.getParent()) {
 591                     x += c.getX();
 592                     y += c.getY();
 593                 }
 594 
 595                 g.translate(x, y);
 596                 g.clipRect(0, 0, target.getWidth(), target.getHeight());
 597 
 598                 return g;
 599             }
 600         }

 601 
 602         SurfaceData surfaceData = this.surfaceData;
 603         if (surfaceData != null) {
 604             /* Fix for bug 4746122. Color and Font shouldn't be null */
 605             Color bgColor = background;
 606             if (bgColor == null) {
 607                 bgColor = SystemColor.window;
 608             }
 609             Color fgColor = foreground;
 610             if (fgColor == null) {
 611                 fgColor = SystemColor.windowText;
 612             }
 613             Font font = this.font;
 614             if (font == null) {
 615                 font = defaultFont;
 616             }
 617             ScreenUpdateManager mgr =
 618                 ScreenUpdateManager.getInstance();
 619             return mgr.createGraphics(surfaceData, this, fgColor,
 620                                       bgColor, font);


   1 /*
   2  * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 562         }
 563         else {
 564             return null;
 565         }
 566     }
 567 
 568     // fallback default font object
 569     static final Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
 570 
 571     @Override
 572     public Graphics getGraphics() {
 573         if (isDisposed()) {
 574             return null;
 575         }
 576 
 577         Component target = (Component)getTarget();
 578         Window window = SunToolkit.getContainingWindow(target);
 579         if (window != null) {
 580             final WWindowPeer wpeer = AWTAccessor.getComponentAccessor()
 581                                                  .getPeer(window);
 582             if (wpeer != null) {
 583                 Graphics g = wpeer.getTranslucentGraphics();
 584                 // getTranslucentGraphics() returns non-null value for non-opaque windows only
 585                 if (g != null) {
 586                     // Non-opaque windows do not support heavyweight children.
 587                     // Redirect all painting to the Window's Graphics instead.
 588                     // The caller is responsible for calling the
 589                     // WindowPeer.updateWindow() after painting has finished.
 590                     int x = 0, y = 0;
 591                     for (Component c = target; c != window; c = c.getParent()) {
 592                         x += c.getX();
 593                         y += c.getY();
 594                     }
 595 
 596                     g.translate(x, y);
 597                     g.clipRect(0, 0, target.getWidth(), target.getHeight());
 598 
 599                     return g;
 600                 }
 601             }
 602         }
 603 
 604         SurfaceData surfaceData = this.surfaceData;
 605         if (surfaceData != null) {
 606             /* Fix for bug 4746122. Color and Font shouldn't be null */
 607             Color bgColor = background;
 608             if (bgColor == null) {
 609                 bgColor = SystemColor.window;
 610             }
 611             Color fgColor = foreground;
 612             if (fgColor == null) {
 613                 fgColor = SystemColor.windowText;
 614             }
 615             Font font = this.font;
 616             if (font == null) {
 617                 font = defaultFont;
 618             }
 619             ScreenUpdateManager mgr =
 620                 ScreenUpdateManager.getInstance();
 621             return mgr.createGraphics(surfaceData, this, fgColor,
 622                                       bgColor, font);


< prev index next >