Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java
32288 views
/*1* Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.awt.X11;2526import java.awt.*;27import java.awt.peer.*;2829import sun.awt.SunToolkit;3031import sun.awt.X11GraphicsConfig;32import sun.awt.X11GraphicsDevice;3334class XCanvasPeer extends XComponentPeer implements CanvasPeer {3536private boolean eraseBackgroundDisabled;3738XCanvasPeer() {}3940XCanvasPeer(XCreateWindowParams params) {41super(params);42}4344XCanvasPeer(Component target) {45super(target);46}4748void preInit(XCreateWindowParams params) {49super.preInit(params);50if (SunToolkit.getSunAwtNoerasebackground()) {51disableBackgroundErase();52}53}5455/* Get a GraphicsConfig with the same visual on the new56* screen, which should be easy in Xinerama mode.57*/58public GraphicsConfiguration getAppropriateGraphicsConfiguration(59GraphicsConfiguration gc)60{61if (graphicsConfig == null || gc == null) {62return gc;63}64// Opt: Only need to do if we're not using the default GC6566int screenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen();6768X11GraphicsConfig parentgc;69// save vis id of current gc70int visual = graphicsConfig.getVisual();7172X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment.73getLocalGraphicsEnvironment().74getScreenDevices()[screenNum];7576for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {77if (visual == newDev.getConfigVisualId(i, screenNum)) {78// use that79graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i];80break;81}82}83// just in case...84if (graphicsConfig == null) {85graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment.86getLocalGraphicsEnvironment().87getScreenDevices()[screenNum].88getDefaultConfiguration();89}9091return graphicsConfig;92}9394protected boolean shouldFocusOnClick() {95// Canvas should always be able to be focused by mouse clicks.96return true;97}9899public void disableBackgroundErase() {100eraseBackgroundDisabled = true;101}102protected boolean doEraseBackground() {103return !eraseBackgroundDisabled;104}105}106107108