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.SunGraphicsCallback;
|
|
31 |
|
|
32 |
public class XPanelPeer extends XCanvasPeer implements PanelPeer {
|
|
33 |
|
|
34 |
XEmbeddingContainer embedder = null; //new XEmbeddingContainer();
|
|
35 |
/**
|
|
36 |
* Embeds the given window into container using XEmbed protocol
|
|
37 |
*/
|
|
38 |
public void xembed(long window) {
|
|
39 |
if (embedder != null) {
|
|
40 |
embedder.add(window);
|
|
41 |
}
|
|
42 |
}
|
|
43 |
XPanelPeer() {}
|
|
44 |
|
|
45 |
XPanelPeer(XCreateWindowParams params) {
|
|
46 |
super(params);
|
|
47 |
}
|
|
48 |
|
|
49 |
XPanelPeer(Component target) {
|
|
50 |
super(target);
|
|
51 |
}
|
|
52 |
|
|
53 |
void postInit(XCreateWindowParams params) {
|
|
54 |
super.postInit(params);
|
|
55 |
if (embedder != null) {
|
|
56 |
embedder.install(this);
|
|
57 |
}
|
|
58 |
}
|
|
59 |
|
|
60 |
public Insets getInsets() {
|
|
61 |
return new Insets(0, 0, 0, 0);
|
|
62 |
}
|
|
63 |
|
|
64 |
public void paint(Graphics g) {
|
|
65 |
super.paint(g);
|
|
66 |
/* SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
|
|
67 |
runComponents(((Container)target).getComponents(), g,
|
|
68 |
SunGraphicsCallback.LIGHTWEIGHTS |
|
|
69 |
SunGraphicsCallback.HEAVYWEIGHTS);
|
|
70 |
*/ }
|
|
71 |
public void print(Graphics g) {
|
|
72 |
super.print(g);
|
|
73 |
SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
|
|
74 |
runComponents(((Container)target).getComponents(), g,
|
|
75 |
SunGraphicsCallback.LIGHTWEIGHTS |
|
|
76 |
SunGraphicsCallback.HEAVYWEIGHTS);
|
|
77 |
|
|
78 |
}
|
|
79 |
|
|
80 |
public void setBackground(Color c) {
|
|
81 |
Component comp;
|
|
82 |
int i;
|
|
83 |
|
|
84 |
Container cont = (Container) target;
|
|
85 |
synchronized(target.getTreeLock()) {
|
|
86 |
int n = cont.getComponentCount();
|
|
87 |
for(i=0; i < n; i++) {
|
|
88 |
comp = cont.getComponent(i);
|
|
89 |
ComponentPeer peer = comp.getPeer();
|
|
90 |
if (peer != null) {
|
|
91 |
Color color = comp.getBackground();
|
|
92 |
if (color == null || color.equals(c)) {
|
|
93 |
peer.setBackground(c);
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
}
|
|
98 |
super.setBackground(c);
|
|
99 |
}
|
|
100 |
|
|
101 |
public void setForeground(Color c) {
|
|
102 |
setForegroundForHierarchy((Container) target, c);
|
|
103 |
}
|
|
104 |
|
|
105 |
private void setForegroundForHierarchy(Container cont, Color c) {
|
|
106 |
synchronized(target.getTreeLock()) {
|
|
107 |
int n = cont.getComponentCount();
|
|
108 |
for(int i=0; i < n; i++) {
|
|
109 |
Component comp = cont.getComponent(i);
|
|
110 |
Color color = comp.getForeground();
|
|
111 |
if (color == null || color.equals(c)) {
|
|
112 |
ComponentPeer cpeer = comp.getPeer();
|
|
113 |
if (cpeer != null) {
|
|
114 |
cpeer.setForeground(c);
|
|
115 |
}
|
|
116 |
if (cpeer instanceof LightweightPeer
|
|
117 |
&& comp instanceof Container)
|
|
118 |
{
|
|
119 |
setForegroundForHierarchy((Container) comp, c);
|
|
120 |
}
|
|
121 |
}
|
|
122 |
}
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
/**
|
|
127 |
* DEPRECATED: Replaced by getInsets().
|
|
128 |
*/
|
|
129 |
public Insets insets() {
|
|
130 |
return getInsets();
|
|
131 |
}
|
|
132 |
|
|
133 |
/*
|
|
134 |
* This method is called from XWindowPeer.displayChanged, when
|
|
135 |
* the window this Panel is on is moved to the new screen, or
|
|
136 |
* display mode is changed.
|
|
137 |
*
|
|
138 |
* The notification is propagated to the child Canvas components.
|
|
139 |
* Top-level windows and other Panels are notified too as their
|
|
140 |
* peers are subclasses of XCanvasPeer.
|
|
141 |
*/
|
|
142 |
public void displayChanged(int screenNum) {
|
|
143 |
super.displayChanged(screenNum);
|
|
144 |
displayChanged((Container)target, screenNum);
|
|
145 |
}
|
|
146 |
|
|
147 |
/*
|
|
148 |
* Recursively iterates through all the HW and LW children
|
|
149 |
* of the container and calls displayChanged() for HW peers.
|
|
150 |
* Iteration through children peers only is not enough as the
|
|
151 |
* displayChanged notification may not be propagated to HW
|
|
152 |
* components inside LW containers, see 4452373 for details.
|
|
153 |
*/
|
|
154 |
private static void displayChanged(Container target, int screenNum) {
|
|
155 |
Component children[] = ((Container)target).getComponents();
|
|
156 |
for (Component child : children) {
|
|
157 |
ComponentPeer cpeer = child.getPeer();
|
|
158 |
if (cpeer instanceof XCanvasPeer) {
|
|
159 |
((XCanvasPeer)cpeer).displayChanged(screenNum);
|
|
160 |
} else if (child instanceof Container) {
|
|
161 |
displayChanged((Container)child, screenNum);
|
|
162 |
}
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
public void dispose() {
|
|
167 |
if (embedder != null) {
|
|
168 |
embedder.deinstall();
|
|
169 |
}
|
|
170 |
super.dispose();
|
|
171 |
}
|
|
172 |
|
|
173 |
protected boolean shouldFocusOnClick() {
|
|
174 |
// Return false if this container has children so in that case it won't
|
|
175 |
// be focused. Return true otherwise.
|
|
176 |
return ((Container)target).getComponentCount() == 0;
|
|
177 |
}
|
|
178 |
}
|