001: /*
002: * Copyright 2002-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt.X11;
026:
027: import java.awt.*;
028: import java.awt.peer.*;
029:
030: import sun.awt.ComponentAccessor;
031: import sun.awt.SunToolkit;
032:
033: import sun.awt.X11GraphicsConfig;
034: import sun.awt.X11GraphicsDevice;
035:
036: class XCanvasPeer extends XComponentPeer implements CanvasPeer {
037:
038: private boolean eraseBackgroundDisabled;
039:
040: XCanvasPeer() {
041: }
042:
043: XCanvasPeer(XCreateWindowParams params) {
044: super (params);
045: }
046:
047: XCanvasPeer(Component target) {
048: super (target);
049: }
050:
051: void preInit(XCreateWindowParams params) {
052: super .preInit(params);
053: if (SunToolkit.getSunAwtNoerasebackground()) {
054: disableBackgroundErase();
055: }
056: }
057:
058: void resetTargetGC(Component target) {
059: ComponentAccessor.resetGC(target);
060: }
061:
062: /*
063: * Called when the Window this
064: * Canvas is on is moved onto another Xinerama screen.
065: *
066: * Canvases can be created with a non-defulat GraphicsConfiguration. The
067: * GraphicsConfiguration needs to be changed to one on the new screen,
068: * preferably with the same visual ID.
069: *
070: * Up-called for other windows peer instances (XPanelPeer, XWindowPeer).
071: *
072: * Should only be called from the event thread.
073: */
074: public void displayChanged(int screenNum) {
075: resetLocalGC(screenNum);
076: resetTargetGC(target);
077: }
078:
079: /* Set graphicsConfig to a GraphicsConfig with the same visual on the new
080: * screen, which should be easy in Xinerama mode.
081: *
082: * Should only be called from displayChanged(), and therefore only from
083: * the event thread.
084: */
085: void resetLocalGC(int screenNum) {
086: // Opt: Only need to do if we're not using the default GC
087: if (graphicsConfig != null) {
088: X11GraphicsConfig parentgc;
089: // save vis id of current gc
090: int visual = graphicsConfig.getVisual();
091:
092: X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment
093: .getLocalGraphicsEnvironment().getScreenDevices()[screenNum];
094:
095: for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) {
096: if (visual == newDev.getConfigVisualId(i, screenNum)) {
097: // use that
098: graphicsConfig = (X11GraphicsConfig) newDev
099: .getConfigurations()[i];
100: break;
101: }
102: }
103: // just in case...
104: if (graphicsConfig == null) {
105: graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment
106: .getLocalGraphicsEnvironment()
107: .getScreenDevices()[screenNum]
108: .getDefaultConfiguration();
109: }
110: }
111: }
112:
113: protected boolean shouldFocusOnClick() {
114: // Canvas should always be able to be focused by mouse clicks.
115: return true;
116: }
117:
118: public void disableBackgroundErase() {
119: eraseBackgroundDisabled = true;
120: }
121:
122: protected boolean doEraseBackground() {
123: return !eraseBackgroundDisabled;
124: }
125:
126: public void setBackground(Color c) {
127: boolean doRepaint = false;
128: if (getPeerBackground() == null
129: || !getPeerBackground().equals(c)) {
130: doRepaint = true;
131: }
132: super.setBackground(c);
133: if (doRepaint) {
134: target.repaint();
135: }
136: }
137: }
|