src/java.desktop/unix/classes/sun/awt/X11/XPanelPeer.java
author serb
Wed, 18 Apr 2018 14:07:41 -0700
changeset 49998 9070717a16a1
parent 47216 71c04702a3d5
permissions -rw-r--r--
8187392: Deprecated methods in the peers can be removed Reviewed-by: prr, kaddepalli
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
49998
9070717a16a1 8187392: Deprecated methods in the peers can be removed
serb
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, 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
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
    30
import sun.awt.AWTAccessor;
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
    31
import sun.awt.AWTAccessor.ComponentAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.awt.SunGraphicsCallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
public class XPanelPeer extends XCanvasPeer implements PanelPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    XEmbeddingContainer embedder = null; //new XEmbeddingContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
     * Embeds the given window into container using XEmbed protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public void xembed(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
            embedder.add(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    XPanelPeer() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    XPanelPeer(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    XPanelPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            embedder.install(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        super.paint(g);
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    67
        SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    68
            runComponents(((Container)target).getComponents(), g,
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    69
                          SunGraphicsCallback.LIGHTWEIGHTS |
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    70
                          SunGraphicsCallback.HEAVYWEIGHTS);
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
    71
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                          SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                          SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        Container cont = (Container) target;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
    86
        final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            for(i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                comp = cont.getComponent(i);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
    91
                ComponentPeer peer = acc.getPeer(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    Color color = comp.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                        peer.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        setForegroundForHierarchy((Container) target, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private void setForegroundForHierarchy(Container cont, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        synchronized(target.getTreeLock()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   109
            final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            for(int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                Component comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                Color color = comp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                if (color == null || color.equals(c)) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 28231
diff changeset
   115
                    ComponentPeer cpeer = acc.getPeer(comp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    if (cpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        cpeer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    if (cpeer instanceof LightweightPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        && comp instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        setForegroundForHierarchy((Container) comp, c);
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
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            embedder.deinstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    protected boolean shouldFocusOnClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        // Return false if this container has children so in that case it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        // be focused. Return true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return ((Container)target).getComponentCount() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
}