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