jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 12406 fc209a5d3c85
child 13648 90effcfc064f
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8133
diff changeset
     2
 * Copyright (c) 2002, 2011, 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: 4371
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: 4371
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: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
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.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.BufferCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Graphics;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2458
diff changeset
    38
import java.awt.GraphicsConfiguration;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.SystemColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.dnd.DropTarget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.dnd.peer.DropTargetPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.event.InputMethodEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.event.MouseWheelEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.event.PaintEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.event.InvocationEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.image.ImageProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.peer.ContainerPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.util.Set;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    65
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import sun.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import sun.awt.event.IgnorePaintEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import sun.awt.image.SunVolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import sun.awt.image.ToolkitImage;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
    70
import sun.java2d.BackBufferCapsProvider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 12406
diff changeset
    73
import javax.tools.annotation.GenerateNativeHeader;
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 12406
diff changeset
    74
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 12406
diff changeset
    75
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 12406
diff changeset
    76
@GenerateNativeHeader
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
    77
public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
    78
    BackBufferCapsProvider
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
    79
{
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    80
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    81
    private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    82
    private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    83
    private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    84
    private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer");
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
    85
    private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    boolean paintPending = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    boolean isLayouting = false;
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
    89
    private boolean enabled;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Actually used only by XDecoratedPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected int boundsOperation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    Color foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    Color background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // Colors calculated as on Motif using MotifColorUtilties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // If you use these, call updateMotifColors() in the peer's Constructor and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // setBackground().  Examples are XCheckboxPeer and XButtonPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    Color lightShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    Color selectColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private long backBuffer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private VolatileImage xBackBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    static Color[] systemColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    XComponentPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    XComponentPeer (XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    XComponentPeer(Component target, long parentWindow, Rectangle bounds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(target, parentWindow, bounds);
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
     * Standard peer constructor, with corresponding Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    XComponentPeer(Component target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        super(target);
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
    void preInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        super.preInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        boundsOperation = DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    void postInit(XCreateWindowParams params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        super.postInit(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        pSetCursor(target.getCursor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        foreground = target.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        background = target.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        font = target.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (isInitialReshape()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            Rectangle r = target.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            reshape(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   147
        setEnabled(target.isEnabled());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (target.isVisible()) {
2458
f4bee3ba17ee 6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents: 1978
diff changeset
   150
            setVisible(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    protected boolean isInitialReshape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void reparent(ContainerPeer newNativeParent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        XComponentPeer newPeer = (XComponentPeer)newNativeParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            parentWindow = newPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public boolean isReparentSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return System.getProperty("sun.awt.X11.XComponentPeer.reparentNotSupported", "false").equals("false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public boolean isObscured() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Container container  = (target instanceof Container) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            (Container)target : target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (container == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Container parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        while ((parent = container.getParent()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            container = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (container instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            XWindowPeer wpeer = (XWindowPeer)(container.getPeer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (wpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                return (wpeer.winAttr.visibilityState !=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        wpeer.winAttr.AWT_UNOBSCURED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public boolean canDetermineObscurity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /*************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * FOCUS STUFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Keeps the track of focused state of the _NATIVE_ window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    boolean bHasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Descendants should use this method to determine whether or not native window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    final public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return bHasFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Called when component receives focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void focusGained(FocusEvent e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   220
        focusLog.fine("{0}", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        bHasFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Called when component loses focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public void focusLost(FocusEvent e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   228
        focusLog.fine("{0}", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        bHasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        /* should be implemented by other sub-classes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static Class seClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static Constructor seCtor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    final static AWTEvent wrapInSequenced(AWTEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (seClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                seClass = Class.forName("java.awt.SequencedEvent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (seCtor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                seCtor = (Constructor) AccessController.doPrivileged(new PrivilegedExceptionAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                        public Object run() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                            Constructor ctor = seClass.getConstructor(new Class[] { AWTEvent.class });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                            ctor.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            return ctor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return (AWTEvent) seCtor.newInstance(new Object[] { event });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new NoClassDefFoundError("java.awt.SequencedEvent.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        catch (PrivilegedActionException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            throw new NoClassDefFoundError("java.awt.SequencedEvent.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   277
    // TODO: consider moving it to KeyboardFocusManagerPeerImpl
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   278
    final public boolean requestFocus(Component lightweightChild, boolean temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   279
                                      boolean focusedWindowChangeAllowed, long time,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   280
                                      CausedFocusEvent.Cause cause)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   282
        if (XKeyboardFocusManagerPeer.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   283
            processSynchronousLightweightTransfer(target, lightweightChild, temporary,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                                  focusedWindowChangeAllowed, time))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   289
        int result = XKeyboardFocusManagerPeer.
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   290
            shouldNativelyFocusHeavyweight(target, lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   291
                                           temporary, focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   292
                                           time, cause);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        switch (result) {
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   295
          case XKeyboardFocusManagerPeer.SNFH_FAILURE:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
              return false;
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   297
          case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
              // Currently we just generate focus events like we deal with lightweight instead of calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
              // XSetInputFocus on native window
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   300
              if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Proceeding with request to " +
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   301
                  lightweightChild + " in " + target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
              /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
               * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
               * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
               * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   306
               * in requests list - and it breaks our requests sequence as first record on WGF should be the last
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   307
               * focus owner which had focus before WLF. So, we should not add request record for such requests
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
               * but store this component in mostRecent - and return true as before for compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
               */
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   310
              Window parentWindow = SunToolkit.getContainingWindow(target);
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   311
              if (parentWindow == null) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   312
                  return rejectFocusRequestHelper("WARNING: Parent window is null");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   313
              }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   314
              XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer();
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   315
              if (wpeer == null) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   316
                  return rejectFocusRequestHelper("WARNING: Parent window's peer is null");
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   317
              }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   318
              /*
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   319
               * Passing null 'actualFocusedWindow' as we don't want to restore focus on it
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   320
               * when a component inside a Frame is requesting focus.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   321
               * See 6314575 for details.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   322
               */
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   323
              boolean res = wpeer.requestWindowFocus(null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   325
              if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res);
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   326
              // If parent window can be made focused and has been made focused(synchronously)
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   327
              // then we can proceed with children, otherwise we retreat.
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   328
              if (!(res && parentWindow.isFocused())) {
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   329
                  return rejectFocusRequestHelper("Waiting for asynchronous processing of the request");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
              }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   331
              return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   332
                                                            (Component)target,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   333
                                                            temporary,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   334
                                                            focusedWindowChangeAllowed,
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   335
                                                            time, cause);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
              // Motif compatibility code
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   337
          case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
              // Either lightweight or excessive request - all events are generated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   344
    private boolean rejectFocusRequestHelper(String logMsg) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   345
        if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg);
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   346
        XKeyboardFocusManagerPeer.removeLastFocusRequest(target);
442
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   347
        return false;
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   348
    }
687798d7d7b6 6522725: Component in a minimized Frame has focus and receives key events
ant
parents: 439
diff changeset
   349
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    void handleJavaFocusEvent(AWTEvent e) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   351
        if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(e.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (e.getID() == FocusEvent.FOCUS_GAINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            focusGained((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            focusLost((FocusEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    void handleJavaWindowFocusEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /*************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * END OF FOCUS STUFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        xSetVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see java.awt.peer.ComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   379
    public void setEnabled(final boolean value) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   380
        if (enableLog.isLoggable(PlatformLogger.FINE)) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   381
            enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this);
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   382
        }
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   383
        boolean status = value;
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   384
        // If any of our heavyweight ancestors are disable, we should be too
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   385
        // See 6176875 for more information
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   386
        final Container cp = SunToolkit.getNativeContainer(target);
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   387
        if (cp != null) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   388
            status &= ((XComponentPeer) cp.getPeer()).isEnabled();
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   389
        }
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   390
        synchronized (getStateLock()) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   391
            if (enabled == status) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   392
                return;
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   393
            }
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   394
            enabled = status;
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   395
        }
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   396
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (target instanceof Container) {
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   398
            final Component[] list = ((Container) target).getComponents();
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   399
            for (final Component child : list) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   400
                final ComponentPeer p = child.getPeer();
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   401
                if (p != null) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   402
                    p.setEnabled(status && child.isEnabled());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   406
        repaint();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    // public so aw/Window can call it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    //
12406
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   412
    public final boolean isEnabled() {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   413
        synchronized (getStateLock()) {
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   414
            return enabled;
fc209a5d3c85 7097771: setEnabled does not work for components in disabled containers.
serb
parents: 10871
diff changeset
   415
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   418
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   419
    public void paint(final Graphics g) {
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   420
        super.paint(g);
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   421
        // allow target to change the picture
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   422
        target.paint(g);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        // clear rect here to emulate X clears rect before Expose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        g.setColor(target.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        g.fillRect(0, 0, target.getWidth(), target.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        g.setColor(target.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // paint peer
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 9035
diff changeset
   434
        paintPeer(g);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        // allow target to change the picture
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        target.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        xSetBounds(x,y,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        validateSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public void coalescePaintEvent(PaintEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        Rectangle r = e.getUpdateRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (!(e instanceof IgnorePaintEvent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            paintArea.add(r, e.getID());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
              case PaintEvent.UPDATE:
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   461
                  if (log.isLoggable(PlatformLogger.FINER)) {
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   462
                      log.finer("XCP coalescePaintEvent : UPDATE : add : x = " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                            r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   464
                  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
              case PaintEvent.PAINT:
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   467
                  if (log.isLoggable(PlatformLogger.FINER)) {
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   468
                      log.finer("XCP coalescePaintEvent : PAINT : add : x = " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                            r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height);
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
   470
                  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    XWindowPeer getParentTopLevel() {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   477
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   478
        Container parent = (target instanceof Container) ? ((Container)target) : (compAccessor.getParent(target));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // Search for parent window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        while (parent != null && !(parent instanceof Window)) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   481
            parent = compAccessor.getParent(parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (parent != null) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   484
            return (XWindowPeer)compAccessor.getPeer(parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /* This method is intended to be over-ridden by peers to perform user interaction */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    void handleJavaMouseEvent(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
          case MouseEvent.MOUSE_PRESSED:
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   494
              if (target == e.getSource() &&
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   495
                  !target.isFocusOwner() &&
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   496
                  XKeyboardFocusManagerPeer.shouldFocusOnClick(target))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
              {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                  XWindowPeer parentXWindow = getParentTopLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                  Window parentWindow = ((Window)parentXWindow.getTarget());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                  // Simple windows are non-focusable in X terms but focusable in Java terms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                  // As X-non-focusable they don't receive any focus events - we should generate them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                  // by ourselfves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
//                   if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
//                       !(getCurrentNativeFocusedWindow() == parentWindow))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
//                   {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
//                       setCurrentNativeFocusedWindow(parentWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
//                       WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
//                       parentWindow.dispatchEvent(wfg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
//                   }
2464
3c6755bdc55f 6806217: implement synthetic focus model for MS Windows
ant
parents: 2462
diff changeset
   510
                  XKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /* This method is intended to be over-ridden by peers to perform user interaction */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    void handleJavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    /* This method is intended to be over-ridden by peers to perform user interaction */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    void handleJavaMouseWheelEvent(MouseWheelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /* This method is intended to be over-ridden by peers to perform user interaction */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    void handleJavaInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    void handleF10JavaKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_F10) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            XWindowPeer winPeer = this.getToplevelXWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            if (winPeer instanceof XFramePeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                XMenuBarPeer mPeer = ((XFramePeer)winPeer).getMenubarPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                if (mPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    mPeer.handleF10KeyPress(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public void handleEvent(java.awt.AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled())  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (e instanceof MouseEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                if (e instanceof MouseWheelEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    handleJavaMouseWheelEvent((MouseWheelEvent) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    handleJavaMouseEvent((MouseEvent) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            else if (e instanceof KeyEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                handleF10JavaKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                handleJavaKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            // even if target is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            handleF10JavaKeyEvent((KeyEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        else if (e instanceof InputMethodEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            handleJavaInputMethodEvent((InputMethodEvent) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
          case PaintEvent.PAINT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
              // Got native painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
              paintPending = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
              // Fallthrough to next statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
          case PaintEvent.UPDATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
              // Skip all painting while layouting and all UPDATEs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
              // while waiting for native paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
              if (!isLayouting && !paintPending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                  paintArea.paint(target,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
              return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
          case FocusEvent.FOCUS_LOST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
          case FocusEvent.FOCUS_GAINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
              handleJavaFocusEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
          case WindowEvent.WINDOW_LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
          case WindowEvent.WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
              handleJavaWindowFocusEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public void handleButtonPressRelease(XEvent xev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * Fix for 6385277.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         * We request focus on simple Window by click in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
         * to make it behave like Frame/Dialog in this case and also to unify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
         * the behaviour with what we have on MS Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
         * handleJavaMouseEvent() would be more suitable place to do this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         * but we want Swing to have this functionality also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         */
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
   600
        if (xev.get_type() == XConstants.ButtonPress) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            final XWindowPeer parentXWindow = getParentTopLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            Window parentWindow = (Window)parentXWindow.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                postEvent(new InvocationEvent(parentWindow, new  Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                            // Request focus on the EDT of 'parentWindow' because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                            // XDecoratedPeer.requestWindowFocus() calls client code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                            parentXWindow.requestXFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        super.handleButtonPressRelease(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return target.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public void layout() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public java.awt.Toolkit getToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        return Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    void updateMotifColors(Color bg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        int red = bg.getRed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        int green = bg.getGreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        int blue = bg.getBlue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        darkShadow = new Color(MotifColorUtilities.calculateBottomShadowFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        lightShadow = new Color(MotifColorUtilities.calculateTopShadowFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        selectColor= new Color(MotifColorUtilities.calculateSelectFromBackground(red,green,blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Draw a 3D rectangle using the Motif colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * "Normal" rectangles have shadows on the bottom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * "Depressed" rectangles (such as pressed buttons) have shadows on the top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * in which case true should be passed for topShadow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void drawMotif3DRect(Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                          int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                          boolean topShadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        g.setColor(topShadow ? darkShadow : lightShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        g.drawLine(x, y, x+width, y);       // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        g.drawLine(x, y+height, x, y);      // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        g.setColor(topShadow ? lightShadow : darkShadow );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        g.drawLine(x+1, y+height, x+width, y+height); // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        g.drawLine(x+width, y+height, x+width, y+1);  // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public void setBackground(Color c) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   661
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set background to " + c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public void setForeground(Color c) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   670
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set foreground to " + c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Gets the font metrics for the specified font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @param font the font for which font metrics is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *      obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @return the font metrics for <code>font</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see       #getFont
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @see       #getPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @see       Toolkit#getFontMetrics(Font)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public FontMetrics getFontMetrics(Font font) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
   689
        if (fontLog.isLoggable(PlatformLogger.FINE)) fontLog.fine("Getting font metrics for " + font);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return sun.font.FontDesignMetrics.getMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            if (f == null) {
116
9c43d9eb1029 6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents: 2
diff changeset
   696
                f = XWindow.getDefaultFont();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        // as it stands currently we dont need to do layout or repaint since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // layout is done in the Component upon setFont.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        //layout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        //repaint()?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public void updateCursorImmediately() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        XGlobalCursorManager.getCursorManager().updateCursorImmediately();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   715
    public final void pSetCursor(Cursor cursor) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   716
        this.pSetCursor(cursor, true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   717
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   718
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   719
    /*
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   720
     * The method changes the cursor.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   721
     * @param cursor - a new cursor to change to.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   722
     * @param ignoreSubComponents - if {@code true} is passed then
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   723
     *                              the new cursor will be installed on window.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   724
     *                              if {@code false} is passed then
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   725
     *                              subsequent components will try to handle
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   726
     *                              this request and install their cursor.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   727
     */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   728
    //ignoreSubComponents not used here
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 5506
diff changeset
   729
    public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            long xcursor = XGlobalCursorManager.getCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            XSetWindowAttributes xwa = new XSetWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            xwa.set_cursor(xcursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
   737
            long valuemask = XConstants.CWCursor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            XlibWrapper.XFlush(XToolkit.getDisplay());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            xwa.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public Image createImage(ImageProducer producer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return new ToolkitImage(producer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public Image createImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return graphicsConfig.createAcceleratedImage(target, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public VolatileImage createVolatileImage(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        return new SunVolatileImage(target, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        return getToolkit().prepareImage(img, w, h, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public int checkImage(Image img, int w, int h, ImageObserver o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        return getToolkit().checkImage(img, w, h, o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public Dimension preferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        return getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public Insets getInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        return new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    public void beginValidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public void endValidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * DEPRECATED:  Replaced by getInsets().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    public Insets insets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    // Returns true if we are inside begin/endLayout and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    // are waiting for native painting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    public boolean isPaintPending() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return paintPending && isLayouting;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public boolean handlesWheelScrolling() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public void beginLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        // Skip all painting till endLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        isLayouting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    public void endLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (!paintPending && !paintArea.isEmpty()
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
   812
            && !AWTAccessor.getComponentAccessor().getIgnoreRepaint(target))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            // if not waiting for native painting repaint damaged area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            postEvent(new PaintEvent(target, PaintEvent.PAINT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                                     new Rectangle()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        isLayouting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public Color getWinBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return getPeerBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    static int[] getRGBvals(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        int rgbvals[] = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        rgbvals[0] = c.getRed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        rgbvals[1] = c.getGreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        rgbvals[2] = c.getBlue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return rgbvals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    static final int BACKGROUND_COLOR = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    static final int HIGHLIGHT_COLOR = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    static final int SHADOW_COLOR = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    static final int FOREGROUND_COLOR = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    public Color[] getGUIcolors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        Color c[] = new Color[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        float backb, highb, shadowb, hue, saturation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        c[BACKGROUND_COLOR] = getWinBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (c[BACKGROUND_COLOR] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            c[BACKGROUND_COLOR] = super.getWinBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (c[BACKGROUND_COLOR] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            c[BACKGROUND_COLOR] = Color.lightGray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        int[] rgb = getRGBvals(c[BACKGROUND_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        float[] hsb = Color.RGBtoHSB(rgb[0],rgb[1],rgb[2],null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        hue = hsb[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        saturation = hsb[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        backb = hsb[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
/*      Calculate Highlight Brightness  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        highb = backb + 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        shadowb = backb - 0.4f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if ((highb > 1.0) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if  ((1.0 - backb) < 0.05) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                highb = shadowb + 0.25f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                highb = 1.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (shadowb < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                if ((backb - 0.0) < 0.25) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    highb = backb + 0.75f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    shadowb = highb - 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    shadowb = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        c[HIGHLIGHT_COLOR] = Color.getHSBColor(hue,saturation,highb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        c[SHADOW_COLOR] = Color.getHSBColor(hue,saturation,shadowb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
  c[SHADOW_COLOR] = c[BACKGROUND_COLOR].darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
  int r2 = c[SHADOW_COLOR].getRed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
  int g2 = c[SHADOW_COLOR].getGreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
  int b2 = c[SHADOW_COLOR].getBlue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        c[FOREGROUND_COLOR] = getPeerForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if (c[FOREGROUND_COLOR] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            c[FOREGROUND_COLOR] = Color.black;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
  if ((c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
  && (c[BACKGROUND_COLOR].equals(c[SHADOW_COLOR]))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
  c[SHADOW_COLOR] = new Color(c[BACKGROUND_COLOR].getRed() + 75,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
  c[BACKGROUND_COLOR].getGreen() + 75,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
  c[BACKGROUND_COLOR].getBlue() + 75);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
  c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR].brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
  } else if (c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
  c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
  c[SHADOW_COLOR] = c[SHADOW_COLOR].darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        if (! isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            c[BACKGROUND_COLOR] = c[BACKGROUND_COLOR].darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            // Reduce the contrast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            // Calculate the NTSC gray (NB: REC709 L* might be better!)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            // for foreground and background; then multiply the foreground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            // by the average lightness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            Color tc = c[BACKGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            int bg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            tc = c[FOREGROUND_COLOR];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            int fg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            float ave = (float) ((fg + bg) / 51000.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            // 255 * 100 * 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            Color newForeground = new Color((int) (tc.getRed() * ave),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                            (int) (tc.getGreen() * ave),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                                            (int) (tc.getBlue() * ave));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if (newForeground.equals(c[FOREGROUND_COLOR])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                // This probably means the foreground color is black or white
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                newForeground = new Color(ave, ave, ave);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            c[FOREGROUND_COLOR] = newForeground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * Returns an array of Colors similar to getGUIcolors(), but using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * System colors.  This is useful if pieces of a Component (such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * the integrated scrollbars of a List) should retain the System color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * instead of the background color set by Component.setBackground().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    static Color[] getSystemColors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        if (systemColors == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            systemColors = new Color[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            systemColors[BACKGROUND_COLOR] = SystemColor.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            systemColors[SHADOW_COLOR] = SystemColor.controlShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            systemColors[FOREGROUND_COLOR] = SystemColor.windowText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        return systemColors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * Draw a 3D oval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    public void draw3DOval(Graphics g, Color colors[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                           int x, int y, int w, int h, boolean raised)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        g.drawArc(x, y, w, h, 45, 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        g.drawArc(x, y, w, h, 225, 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    public void draw3DRect(Graphics g, Color colors[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                           int x, int y, int width, int height, boolean raised)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
            g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            g.drawLine(x, y, x, y + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            g.drawLine(x + 1, y, x + width - 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            g.drawLine(x + 1, y + height, x + width, y + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            g.drawLine(x + width, y, x + width, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * drawXXX() methods are used to print the native components by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * rendering the Motif look ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * ToDo(aim): needs to query native motif for more accurate color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    void draw3DOval(Graphics g, Color bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                    int x, int y, int w, int h, boolean raised)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            Color shadow = bg.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            Color highlight = bg.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            g.setColor(raised ? highlight : shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            g.drawArc(x, y, w, h, 45, 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            g.setColor(raised ? shadow : highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            g.drawArc(x, y, w, h, 225, 180);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    void draw3DRect(Graphics g, Color bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                    int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    boolean raised) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        Color shadow = bg.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        Color highlight = bg.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        g.setColor(raised ? highlight : shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        g.drawLine(x, y, x, y + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        g.drawLine(x + 1, y, x + width - 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        g.setColor(raised ? shadow : highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        g.drawLine(x + 1, y + height, x + width, y + height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        g.drawLine(x + width, y, x + width, y + height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    void drawScrollbar(Graphics g, Color bg, int thickness, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
               int min, int max, int val, int vis, boolean horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        Color c = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        double f = (double)(length - 2*(thickness-1)) / Math.max(1, ((max - min) + vis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        int v1 = thickness + (int)(f * (val - min));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        int v2 = (int)(f * vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        int w2 = thickness-4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        int tpts_x[] = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        int tpts_y[] = new int[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        if (length < 3*w2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            v1 = v2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            if (length < 2*w2 + 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                w2 = (length-2)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        } else  if (v2 < 7) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            // enforce a minimum handle size
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            v1 = Math.max(0, v1 - ((7 - v2)>>1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            v2 = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        int ctr   = thickness/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        int sbmin = ctr - w2/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        int sbmax = ctr + w2/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        // paint the background slightly darker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            Color d = new Color((int) (bg.getRed()   * 0.85),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                (int) (bg.getGreen() * 0.85),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                (int) (bg.getBlue()  * 0.85));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            g.setColor(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                g.fillRect(0, 0, length, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                g.fillRect(0, 0, thickness, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        // paint the thumb and arrows in the normal background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        if (v1 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                g.fillRect(v1, 3, v2, thickness-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                g.fillRect(3, v1, thickness-3, v2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        tpts_x[0] = ctr;    tpts_y[0] = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        tpts_x[1] = sbmin;  tpts_y[1] = w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        tpts_x[2] = sbmax;  tpts_y[2] = w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            g.fillPolygon(tpts_y, tpts_x, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            g.fillPolygon(tpts_x, tpts_y, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        tpts_y[0] = length-2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        tpts_y[1] = length-w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        tpts_y[2] = length-w2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            g.fillPolygon(tpts_y, tpts_x, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            g.fillPolygon(tpts_x, tpts_y, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        Color highlight = bg.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        // // // // draw the "highlighted" edges
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        // outline & arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            g.drawLine(1, thickness, length - 1, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            g.drawLine(length - 1, 1, length - 1, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            // arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            g.drawLine(1, ctr, w2, sbmin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            g.drawLine(length - w2, sbmin, length - w2, sbmax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            g.drawLine(length - w2, sbmin, length - 2, ctr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            g.drawLine(thickness, 1, thickness, length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            g.drawLine(1, length - 1, thickness, length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            // arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            g.drawLine(ctr, 1, sbmin, w2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            g.drawLine(sbmin, length - w2, sbmax, length - w2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            g.drawLine(sbmin, length - w2, ctr, length - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        // thumb
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        if (v1 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                g.drawLine(v1, 2, v1 + v2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                g.drawLine(v1, 2, v1, thickness-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                g.drawLine(2, v1, 2, v1 + v2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                g.drawLine(2, v1, thickness-3, v1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        Color shadow = bg.darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        // // // // draw the "shadowed" edges
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        // outline && arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            g.drawLine(0, 0, 0, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            g.drawLine(0, 0, length - 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            // arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            g.drawLine(w2, sbmin, w2, sbmax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            g.drawLine(w2, sbmax, 1, ctr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            g.drawLine(length-2, ctr, length-w2, sbmax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            g.drawLine(0, 0, thickness, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            g.drawLine(0, 0, 0, length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            // arrows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            g.drawLine(sbmin, w2, sbmax, w2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            g.drawLine(sbmax, w2, ctr, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            g.drawLine(ctr, length-2, sbmax, length-w2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        // thumb
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        if (v1 > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            if (horizontal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                g.drawLine(v1 + v2, 2, v1 + v2, thickness-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                g.drawLine(v1, thickness-2, v1 + v2, thickness-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                g.drawLine(2, v1 + v2, thickness-2, v1 + v2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                g.drawLine(thickness-2, v1, thickness-2, v1 + v2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        g.setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * The following multibuffering-related methods delegate to our
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * associated GraphicsConfig (X11 or GLX) to handle the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * native windowing system specific actions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1168
    private BufferCapabilities backBufferCaps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1169
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    public void createBuffers(int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
      throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1173
        if (buffersLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1176
        // set the caps first, they're used when creating the bb
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1177
        backBufferCaps = caps;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        xBackBuffer = graphicsConfig.createBackBufferImage(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                                           backBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1183
    @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1184
    public BufferCapabilities getBackBufferCaps() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1185
        return backBufferCaps;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1186
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1187
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1188
    public void flip(int x1, int y1, int x2, int y2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1189
                     BufferCapabilities.FlipContents flipAction)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1190
    {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1191
        if (buffersLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            buffersLog.fine("flip(" + flipAction + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if (backBuffer == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            throw new IllegalStateException("Buffers have not been created");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1197
        graphicsConfig.flip(this, target, xBackBuffer,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 442
diff changeset
  1198
                            x1, y1, x2, y2, flipAction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    public Image getBackBuffer() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1202
        if (buffersLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            buffersLog.fine("getBackBuffer()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (backBuffer == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            throw new IllegalStateException("Buffers have not been created");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        return xBackBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    public void destroyBuffers() {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1212
        if (buffersLog.isLoggable(PlatformLogger.FINE)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            buffersLog.fine("destroyBuffers()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        graphicsConfig.destroyBackBuffer(backBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        backBuffer = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        xBackBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    // End of multi-buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    public void notifyTextComponentChange(boolean add){
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
  1223
        Container parent = AWTAccessor.getComponentAccessor().getParent(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        while(!(parent == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                parent instanceof java.awt.Frame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                parent instanceof java.awt.Dialog)) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4214
diff changeset
  1227
            parent = AWTAccessor.getComponentAccessor().getParent(parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
/*      FIX ME - FIX ME need to implement InputMethods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    if (parent instanceof java.awt.Frame ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        parent instanceof java.awt.Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (add)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        ((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        ((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * Returns true if this event is disabled and shouldn't be processed by window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * Currently if target component is disabled the following event will be disabled on window:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    protected boolean isEventDisabled(XEvent e) {
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1247
        if (enableLog.isLoggable(PlatformLogger.FINEST)) {
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1248
            enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable"));
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1249
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            switch (e.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1252
              case XConstants.ButtonPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1253
              case XConstants.ButtonRelease:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1254
              case XConstants.KeyPress:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1255
              case XConstants.KeyRelease:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1256
              case XConstants.EnterNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1257
              case XConstants.LeaveNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1258
              case XConstants.MotionNotify:
10871
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1259
                  if (enableLog.isLoggable(PlatformLogger.FINER)) {
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1260
                      enableLog.finer("Event {0} is disable", e);
c0aeb0b14df1 7104625: sun.awt.X11.XEvent is creating 600 MB of char[] for no good reason
anthony
parents: 10096
diff changeset
  1261
                  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                  return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        switch(e.get_type()) {
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1266
          case XConstants.MapNotify:
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 116
diff changeset
  1267
          case XConstants.UnmapNotify:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
              return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        return super.isEventDisabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    Color getPeerBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        return background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    Color getPeerForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        return foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    Font getPeerFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    Dimension getPeerSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        return new Dimension(width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    public void setBoundsOperation(int operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        synchronized(getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            if (boundsOperation == DEFAULT_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                boundsOperation = operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            } else if (operation == RESET_OPERATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                boundsOperation = DEFAULT_OPERATION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    static String operationToString(int operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        switch (operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
          case SET_LOCATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
              return "SET_LOCATION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
          case SET_SIZE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
              return "SET_SIZE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
          case SET_CLIENT_SIZE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
              return "SET_CLIENT_SIZE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
          case SET_BOUNDS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
              return "SET_BOUNDS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1313
    /**
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1314
     * Lowers this component at the bottom of the above HW peer. If the above parameter
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1315
     * is null then the method places this component at the top of the Z-order.
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1316
     */
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1317
    public void setZOrder(ComponentPeer above) {
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1318
        long aboveWindow = (above != null) ? ((XComponentPeer)above).getWindow() : 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
2462
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1320
        XToolkit.awtLock();
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1321
        try{
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1322
            XlibWrapper.SetZOrder(XToolkit.getDisplay(), getWindow(), aboveWindow);
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1323
        }finally{
192552ca8292 6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents: 2459
diff changeset
  1324
            XToolkit.awtUnlock();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    private void addTree(Collection order, Set set, Container cont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        for (int i = 0; i < cont.getComponentCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            Component comp = cont.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            ComponentPeer peer = comp.getPeer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            if (peer instanceof XComponentPeer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                if (!set.contains(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    set.add(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    order.add(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            } else if (comp instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                // It is lightweight container, it might contain heavyweight components attached to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                // peer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                addTree(order, set, (Container)comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    /****** DropTargetPeer implementation ********************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    public void addDropTarget(DropTarget dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        Component comp = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        while(!(comp == null || comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        if (comp instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            if (wpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                wpeer.addDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
    public void removeDropTarget(DropTarget dt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        Component comp = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        while(!(comp == null || comp instanceof Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            comp = comp.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        if (comp instanceof Window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            XWindowPeer wpeer = (XWindowPeer)(comp.getPeer());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            if (wpeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                wpeer.removeDropTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * Applies the shape to the X-window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    public void applyShape(Region shape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        if (XlibUtil.isShapingSupported()) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1382
            if (shapeLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                shapeLog.finer(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                        "*** INFO: Setting shape: PEER: " + this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        + "; WINDOW: " + getWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        + "; TARGET: " + target
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                        + "; SHAPE: " + shape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            try {
1978
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1391
                if (shape != null) {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1392
                    XlibWrapper.SetRectangularShape(
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1393
                            XToolkit.getDisplay(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1394
                            getWindow(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1395
                            shape.getLoX(), shape.getLoY(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1396
                            shape.getHiX(), shape.getHiY(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1397
                            (shape.isRectangular() ? null : shape)
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1398
                            );
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1399
                } else {
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1400
                    XlibWrapper.SetRectangularShape(
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1401
                            XToolkit.getDisplay(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1402
                            getWindow(),
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1403
                            0, 0,
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1404
                            0, 0,
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1405
                            null
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1406
                            );
8b981ce05cd0 6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents: 887
diff changeset
  1407
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        } else {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2805
diff changeset
  1412
            if (shapeLog.isLoggable(PlatformLogger.FINER)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                shapeLog.finer("*** WARNING: Shaping is NOT supported!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    }
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2458
diff changeset
  1417
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1418
    public boolean updateGraphicsData(GraphicsConfiguration gc) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1419
        int oldVisual = -1, newVisual = -1;
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1420
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1421
        if (graphicsConfig != null) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1422
            oldVisual = graphicsConfig.getVisual();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1423
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1424
        if (gc != null && gc instanceof X11GraphicsConfig) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1425
            newVisual = ((X11GraphicsConfig)gc).getVisual();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1426
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1427
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1428
        // If the new visual differs from the old one, the peer must be
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1429
        // recreated because X11 does not allow changing the visual on the fly.
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1430
        // So we even skip the initGraphicsConfiguration() call.
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1431
        // The initial assignment should happen though, hence the != -1 thing.
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1432
        if (oldVisual != -1 && oldVisual != newVisual) {
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1433
            return true;
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1434
        }
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1435
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2458
diff changeset
  1436
        initGraphicsConfiguration();
2805
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1437
        doValidateSurface();
9f18d7e66042 6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents: 2464
diff changeset
  1438
        return false;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2458
diff changeset
  1439
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
}