src/java.desktop/share/classes/java/awt/Canvas.java

Print this page


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


  53 
  54     /**
  55      * Constructs a new Canvas.
  56      */
  57     public Canvas() {
  58     }
  59 
  60     /**
  61      * Constructs a new Canvas given a GraphicsConfiguration object.
  62      *
  63      * @param config a reference to a GraphicsConfiguration object.
  64      *
  65      * @see GraphicsConfiguration
  66      */
  67     public Canvas(GraphicsConfiguration config) {
  68         this();
  69         setGraphicsConfiguration(config);
  70     }
  71 
  72     @Override
  73     @SuppressWarnings("deprecation")
  74     void setGraphicsConfiguration(GraphicsConfiguration gc) {
  75         synchronized(getTreeLock()) {
  76             CanvasPeer peer = (CanvasPeer)getPeer();
  77             if (peer != null) {
  78                 gc = peer.getAppropriateGraphicsConfiguration(gc);
  79             }
  80             super.setGraphicsConfiguration(gc);
  81         }
  82     }
  83 
  84     /**
  85      * Construct a name for this component.  Called by getName() when the
  86      * name is null.
  87      */
  88     String constructComponentName() {
  89         synchronized (Canvas.class) {
  90             return base + nameCounter++;
  91         }
  92     }
  93 
  94     /**
  95      * Creates the peer of the canvas.  This peer allows you to change the
  96      * user interface of the canvas without changing its functionality.


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


  53 
  54     /**
  55      * Constructs a new Canvas.
  56      */
  57     public Canvas() {
  58     }
  59 
  60     /**
  61      * Constructs a new Canvas given a GraphicsConfiguration object.
  62      *
  63      * @param config a reference to a GraphicsConfiguration object.
  64      *
  65      * @see GraphicsConfiguration
  66      */
  67     public Canvas(GraphicsConfiguration config) {
  68         this();
  69         setGraphicsConfiguration(config);
  70     }
  71 
  72     @Override

  73     void setGraphicsConfiguration(GraphicsConfiguration gc) {
  74         synchronized(getTreeLock()) {
  75             CanvasPeer peer = (CanvasPeer) this.peer;
  76             if (peer != null) {
  77                 gc = peer.getAppropriateGraphicsConfiguration(gc);
  78             }
  79             super.setGraphicsConfiguration(gc);
  80         }
  81     }
  82 
  83     /**
  84      * Construct a name for this component.  Called by getName() when the
  85      * name is null.
  86      */
  87     String constructComponentName() {
  88         synchronized (Canvas.class) {
  89             return base + nameCounter++;
  90         }
  91     }
  92 
  93     /**
  94      * Creates the peer of the canvas.  This peer allows you to change the
  95      * user interface of the canvas without changing its functionality.