author | dcherepanov |
Wed, 30 Sep 2009 13:21:51 +0400 | |
changeset 3968 | 7f37f405ff5a |
parent 2459 | 08f3416ff334 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 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.SunToolkit; |
|
31 |
||
32 |
import sun.awt.X11GraphicsConfig; |
|
33 |
import sun.awt.X11GraphicsDevice; |
|
34 |
||
35 |
class XCanvasPeer extends XComponentPeer implements CanvasPeer { |
|
36 |
||
37 |
private boolean eraseBackgroundDisabled; |
|
38 |
||
39 |
XCanvasPeer() {} |
|
40 |
||
41 |
XCanvasPeer(XCreateWindowParams params) { |
|
42 |
super(params); |
|
43 |
} |
|
44 |
||
45 |
XCanvasPeer(Component target) { |
|
46 |
super(target); |
|
47 |
} |
|
48 |
||
49 |
void preInit(XCreateWindowParams params) { |
|
50 |
super.preInit(params); |
|
51 |
if (SunToolkit.getSunAwtNoerasebackground()) { |
|
52 |
disableBackgroundErase(); |
|
53 |
} |
|
54 |
} |
|
55 |
||
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
56 |
/* Get a GraphicsConfig with the same visual on the new |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
57 |
* screen, which should be easy in Xinerama mode. |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
58 |
*/ |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
59 |
public GraphicsConfiguration getAppropriateGraphicsConfiguration( |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
60 |
GraphicsConfiguration gc) |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
61 |
{ |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
62 |
if (graphicsConfig == null || gc == null) { |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
63 |
return gc; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
64 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
65 |
// Opt: Only need to do if we're not using the default GC |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
66 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
67 |
int screenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen(); |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
68 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
69 |
X11GraphicsConfig parentgc; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
70 |
// save vis id of current gc |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
71 |
int visual = graphicsConfig.getVisual(); |
2 | 72 |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
73 |
X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment. |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
74 |
getLocalGraphicsEnvironment(). |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
75 |
getScreenDevices()[screenNum]; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
76 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
77 |
for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) { |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
78 |
if (visual == newDev.getConfigVisualId(i, screenNum)) { |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
79 |
// use that |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
80 |
graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i]; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
81 |
break; |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
82 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
83 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
84 |
// just in case... |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
85 |
if (graphicsConfig == null) { |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
86 |
graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment. |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
87 |
getLocalGraphicsEnvironment(). |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
88 |
getScreenDevices()[screenNum]. |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
89 |
getDefaultConfiguration(); |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
90 |
} |
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
91 |
|
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2
diff
changeset
|
92 |
return graphicsConfig; |
2 | 93 |
} |
94 |
||
95 |
protected boolean shouldFocusOnClick() { |
|
96 |
// Canvas should always be able to be focused by mouse clicks. |
|
97 |
return true; |
|
98 |
} |
|
99 |
||
100 |
public void disableBackgroundErase() { |
|
101 |
eraseBackgroundDisabled = true; |
|
102 |
} |
|
103 |
protected boolean doEraseBackground() { |
|
104 |
return !eraseBackgroundDisabled; |
|
105 |
} |
|
106 |
public void setBackground(Color c) { |
|
107 |
boolean doRepaint = false; |
|
108 |
if( getPeerBackground() == null || |
|
109 |
!getPeerBackground().equals( c ) ) { |
|
110 |
doRepaint = true; |
|
111 |
} |
|
112 |
super.setBackground(c); |
|
113 |
if( doRepaint ) { |
|
114 |
target.repaint(); |
|
115 |
} |
|
116 |
} |
|
117 |
} |