jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java
author ant
Fri, 22 Feb 2013 15:13:13 +0400
changeset 15983 26a673dec5b2
parent 10096 f9ac9a52952d
child 23010 6dadb192ad81
permissions -rw-r--r--
8006406: lightweight embedding in other Java UI toolkits Reviewed-by: serb, anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
     2
 * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2459
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.SunGraphicsCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class XPanelPeer extends XCanvasPeer implements PanelPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    XEmbeddingContainer embedder = null; //new XEmbeddingContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
     * Embeds the given window into container using XEmbed protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    public void xembed(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
            embedder.add(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    XPanelPeer() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XPanelPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    XPanelPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            embedder.install(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        super.paint(g);
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    65
        SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    66
            runComponents(((Container)target).getComponents(), g,
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    67
                          SunGraphicsCallback.LIGHTWEIGHTS |
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    68
                          SunGraphicsCallback.HEAVYWEIGHTS);
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    69
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                          SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                          SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        Container cont = (Container) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            for(i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                ComponentPeer peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                    Color color = comp.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        peer.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        setForegroundForHierarchy((Container) target, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private void setForegroundForHierarchy(Container cont, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            for(int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                Component comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                Color color = comp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                    ComponentPeer cpeer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    if (cpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                        cpeer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    if (cpeer instanceof LightweightPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                        && comp instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                        setForegroundForHierarchy((Container) comp, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            embedder.deinstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected boolean shouldFocusOnClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        // Return false if this container has children so in that case it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // be focused. Return true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return ((Container)target).getComponentCount() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}