< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1996, 2014, 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


  52     void initialize() {
  53         eraseBackground = !SunToolkit.getSunAwtNoerasebackground();
  54         boolean eraseBackgroundOnResize = SunToolkit.getSunAwtErasebackgroundonresize();
  55         // Optimization: the default value in the native code is true, so we
  56         // call setNativeBackgroundErase only when the value changes to false
  57         if (!PaintEventDispatcher.getPaintEventDispatcher().
  58                 shouldDoNativeBackgroundErase((Component)target)) {
  59             eraseBackground = false;
  60         }
  61         setNativeBackgroundErase(eraseBackground, eraseBackgroundOnResize);
  62         super.initialize();
  63         Color bg = ((Component)target).getBackground();
  64         if (bg != null) {
  65             setBackground(bg);
  66         }
  67     }
  68 
  69     @Override
  70     public void paint(Graphics g) {
  71         Dimension d = ((Component)target).getSize();
  72         if (g instanceof Graphics2D ||
  73             g instanceof sun.awt.Graphics2Delegate) {
  74             // background color is setup correctly, so just use clearRect
  75             g.clearRect(0, 0, d.width, d.height);
  76         } else {
  77             // emulate clearRect
  78             g.setColor(((Component)target).getBackground());
  79             g.fillRect(0, 0, d.width, d.height);
  80             g.setColor(((Component)target).getForeground());
  81         }
  82         super.paint(g);
  83     }
  84 
  85     @Override
  86     public boolean shouldClearRectBeforePaint() {
  87         return eraseBackground;
  88     }
  89 
  90     /*
  91      * Disables background erasing for this canvas, both for resizing
  92      * and not-resizing repaints.
  93      */


   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


  52     void initialize() {
  53         eraseBackground = !SunToolkit.getSunAwtNoerasebackground();
  54         boolean eraseBackgroundOnResize = SunToolkit.getSunAwtErasebackgroundonresize();
  55         // Optimization: the default value in the native code is true, so we
  56         // call setNativeBackgroundErase only when the value changes to false
  57         if (!PaintEventDispatcher.getPaintEventDispatcher().
  58                 shouldDoNativeBackgroundErase((Component)target)) {
  59             eraseBackground = false;
  60         }
  61         setNativeBackgroundErase(eraseBackground, eraseBackgroundOnResize);
  62         super.initialize();
  63         Color bg = ((Component)target).getBackground();
  64         if (bg != null) {
  65             setBackground(bg);
  66         }
  67     }
  68 
  69     @Override
  70     public void paint(Graphics g) {
  71         Dimension d = ((Component)target).getSize();
  72         if (g instanceof Graphics2D) {

  73             // background color is setup correctly, so just use clearRect
  74             g.clearRect(0, 0, d.width, d.height);
  75         } else {
  76             // emulate clearRect
  77             g.setColor(((Component)target).getBackground());
  78             g.fillRect(0, 0, d.width, d.height);
  79             g.setColor(((Component)target).getForeground());
  80         }
  81         super.paint(g);
  82     }
  83 
  84     @Override
  85     public boolean shouldClearRectBeforePaint() {
  86         return eraseBackground;
  87     }
  88 
  89     /*
  90      * Disables background erasing for this canvas, both for resizing
  91      * and not-resizing repaints.
  92      */


< prev index next >