jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java
author dcherepanov
Thu, 09 Jul 2009 15:23:22 -0400
changeset 3234 f0007f6747b0
parent 2459 08f3416ff334
child 5506 202f599c92aa
permissions -rw-r--r--
6847958: MouseWheel event is getting triggered for the disabled Textarea in jdk7 b60 pit build. Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        super.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        /*      SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        */ }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        super.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            runComponents(((Container)target).getComponents(), g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                          SunGraphicsCallback.LIGHTWEIGHTS |
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                          SunGraphicsCallback.HEAVYWEIGHTS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Component comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        Container cont = (Container) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            for(i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                ComponentPeer peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    Color color = comp.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                    if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        peer.setBackground(c);
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
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        setForegroundForHierarchy((Container) target, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private void setForegroundForHierarchy(Container cont, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        synchronized(target.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            int n = cont.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            for(int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                Component comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                Color color = comp.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                if (color == null || color.equals(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    ComponentPeer cpeer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                    if (cpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                        cpeer.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    if (cpeer instanceof LightweightPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        && comp instanceof Container)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        setForegroundForHierarchy((Container) comp, c);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (embedder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            embedder.deinstall();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    protected boolean shouldFocusOnClick() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Return false if this container has children so in that case it won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        // be focused. Return true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return ((Container)target).getComponentCount() == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}