|
1 /* |
|
2 * Copyright 2002-2007 Sun Microsystems, Inc. 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. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 package sun.awt.X11; |
|
26 |
|
27 import java.awt.*; |
|
28 import java.awt.peer.*; |
|
29 |
|
30 import sun.awt.ComponentAccessor; |
|
31 import sun.awt.SunToolkit; |
|
32 |
|
33 import sun.awt.X11GraphicsConfig; |
|
34 import sun.awt.X11GraphicsDevice; |
|
35 |
|
36 class XCanvasPeer extends XComponentPeer implements CanvasPeer { |
|
37 |
|
38 private boolean eraseBackgroundDisabled; |
|
39 |
|
40 XCanvasPeer() {} |
|
41 |
|
42 XCanvasPeer(XCreateWindowParams params) { |
|
43 super(params); |
|
44 } |
|
45 |
|
46 XCanvasPeer(Component target) { |
|
47 super(target); |
|
48 } |
|
49 |
|
50 void preInit(XCreateWindowParams params) { |
|
51 super.preInit(params); |
|
52 if (SunToolkit.getSunAwtNoerasebackground()) { |
|
53 disableBackgroundErase(); |
|
54 } |
|
55 } |
|
56 |
|
57 void resetTargetGC(Component target) { |
|
58 ComponentAccessor.resetGC(target); |
|
59 } |
|
60 |
|
61 /* |
|
62 * Called when the Window this |
|
63 * Canvas is on is moved onto another Xinerama screen. |
|
64 * |
|
65 * Canvases can be created with a non-defulat GraphicsConfiguration. The |
|
66 * GraphicsConfiguration needs to be changed to one on the new screen, |
|
67 * preferably with the same visual ID. |
|
68 * |
|
69 * Up-called for other windows peer instances (XPanelPeer, XWindowPeer). |
|
70 * |
|
71 * Should only be called from the event thread. |
|
72 */ |
|
73 public void displayChanged(int screenNum) { |
|
74 resetLocalGC(screenNum); |
|
75 resetTargetGC(target); |
|
76 } |
|
77 |
|
78 /* Set graphicsConfig to a GraphicsConfig with the same visual on the new |
|
79 * screen, which should be easy in Xinerama mode. |
|
80 * |
|
81 * Should only be called from displayChanged(), and therefore only from |
|
82 * the event thread. |
|
83 */ |
|
84 void resetLocalGC(int screenNum) { |
|
85 // Opt: Only need to do if we're not using the default GC |
|
86 if (graphicsConfig != null) { |
|
87 X11GraphicsConfig parentgc; |
|
88 // save vis id of current gc |
|
89 int visual = graphicsConfig.getVisual(); |
|
90 |
|
91 X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment. |
|
92 getLocalGraphicsEnvironment(). |
|
93 getScreenDevices()[screenNum]; |
|
94 |
|
95 for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) { |
|
96 if (visual == newDev.getConfigVisualId(i, screenNum)) { |
|
97 // use that |
|
98 graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i]; |
|
99 break; |
|
100 } |
|
101 } |
|
102 // just in case... |
|
103 if (graphicsConfig == null) { |
|
104 graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment. |
|
105 getLocalGraphicsEnvironment(). |
|
106 getScreenDevices()[screenNum]. |
|
107 getDefaultConfiguration(); |
|
108 } |
|
109 } |
|
110 } |
|
111 protected boolean shouldFocusOnClick() { |
|
112 // Canvas should always be able to be focused by mouse clicks. |
|
113 return true; |
|
114 } |
|
115 |
|
116 public void disableBackgroundErase() { |
|
117 eraseBackgroundDisabled = true; |
|
118 } |
|
119 protected boolean doEraseBackground() { |
|
120 return !eraseBackgroundDisabled; |
|
121 } |
|
122 public void setBackground(Color c) { |
|
123 boolean doRepaint = false; |
|
124 if( getPeerBackground() == null || |
|
125 !getPeerBackground().equals( c ) ) { |
|
126 doRepaint = true; |
|
127 } |
|
128 super.setBackground(c); |
|
129 if( doRepaint ) { |
|
130 target.repaint(); |
|
131 } |
|
132 } |
|
133 } |