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.SunGraphicsCallback;
031:
032: public class XPanelPeer extends XCanvasPeer implements PanelPeer {
033:
034: XEmbeddingContainer embedder = null; //new XEmbeddingContainer();
035:
036: /**
037: * Embeds the given window into container using XEmbed protocol
038: */
039: public void xembed(long window) {
040: if (embedder != null) {
041: embedder.add(window);
042: }
043: }
044:
045: XPanelPeer() {
046: }
047:
048: XPanelPeer(XCreateWindowParams params) {
049: super (params);
050: }
051:
052: XPanelPeer(Component target) {
053: super (target);
054: }
055:
056: void postInit(XCreateWindowParams params) {
057: super .postInit(params);
058: if (embedder != null) {
059: embedder.install(this );
060: }
061: }
062:
063: public Insets getInsets() {
064: return new Insets(0, 0, 0, 0);
065: }
066:
067: public void paint(Graphics g) {
068: super .paint(g);
069: /* SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
070: runComponents(((Container)target).getComponents(), g,
071: SunGraphicsCallback.LIGHTWEIGHTS |
072: SunGraphicsCallback.HEAVYWEIGHTS);
073: */}
074:
075: public void print(Graphics g) {
076: super .print(g);
077: SunGraphicsCallback.PrintHeavyweightComponentsCallback
078: .getInstance().runComponents(
079: ((Container) target).getComponents(),
080: g,
081: SunGraphicsCallback.LIGHTWEIGHTS
082: | SunGraphicsCallback.HEAVYWEIGHTS);
083:
084: }
085:
086: public void setBackground(Color c) {
087: Component comp;
088: int i;
089:
090: Container cont = (Container) target;
091: synchronized (target.getTreeLock()) {
092: int n = cont.getComponentCount();
093: for (i = 0; i < n; i++) {
094: comp = cont.getComponent(i);
095: ComponentPeer peer = comp.getPeer();
096: if (peer != null) {
097: Color color = comp.getBackground();
098: if (color == null || color.equals(c)) {
099: peer.setBackground(c);
100: }
101: }
102: }
103: }
104: super .setBackground(c);
105: }
106:
107: public void setForeground(Color c) {
108: setForegroundForHierarchy((Container) target, c);
109: }
110:
111: private void setForegroundForHierarchy(Container cont, Color c) {
112: synchronized (target.getTreeLock()) {
113: int n = cont.getComponentCount();
114: for (int i = 0; i < n; i++) {
115: Component comp = cont.getComponent(i);
116: Color color = comp.getForeground();
117: if (color == null || color.equals(c)) {
118: ComponentPeer cpeer = comp.getPeer();
119: if (cpeer != null) {
120: cpeer.setForeground(c);
121: }
122: if (cpeer instanceof LightweightPeer
123: && comp instanceof Container) {
124: setForegroundForHierarchy((Container) comp, c);
125: }
126: }
127: }
128: }
129: }
130:
131: /**
132: * DEPRECATED: Replaced by getInsets().
133: */
134: public Insets insets() {
135: return getInsets();
136: }
137:
138: /*
139: * This method is called from XWindowPeer.displayChanged, when
140: * the window this Panel is on is moved to the new screen, or
141: * display mode is changed.
142: *
143: * The notification is propagated to the child Canvas components.
144: * Top-level windows and other Panels are notified too as their
145: * peers are subclasses of XCanvasPeer.
146: */
147: public void displayChanged(int screenNum) {
148: super .displayChanged(screenNum);
149: displayChanged((Container) target, screenNum);
150: }
151:
152: /*
153: * Recursively iterates through all the HW and LW children
154: * of the container and calls displayChanged() for HW peers.
155: * Iteration through children peers only is not enough as the
156: * displayChanged notification may not be propagated to HW
157: * components inside LW containers, see 4452373 for details.
158: */
159: private static void displayChanged(Container target, int screenNum) {
160: Component children[] = ((Container) target).getComponents();
161: for (Component child : children) {
162: ComponentPeer cpeer = child.getPeer();
163: if (cpeer instanceof XCanvasPeer) {
164: ((XCanvasPeer) cpeer).displayChanged(screenNum);
165: } else if (child instanceof Container) {
166: displayChanged((Container) child, screenNum);
167: }
168: }
169: }
170:
171: public void dispose() {
172: if (embedder != null) {
173: embedder.deinstall();
174: }
175: super .dispose();
176: }
177:
178: protected boolean shouldFocusOnClick() {
179: // Return false if this container has children so in that case it won't
180: // be focused. Return true otherwise.
181: return ((Container) target).getComponentCount() == 0;
182: }
183: }
|