jdk/src/java.desktop/unix/classes/sun/awt/X11/XAtom.java
author serb
Fri, 22 May 2015 23:26:00 +0300
changeset 30948 0a0972d3b58d
parent 26037 508779ce6619
child 33674 566777f73c32
permissions -rw-r--r--
6587235: Incorrect javadoc: "no parameter" in 2d source code Reviewed-by: azvegint, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 439
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 439
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 439
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 439
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 439
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * XAtom is a class that allows you to create and modify X Window properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * An X Atom is an identifier for a property that you can set on any X Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Standard X Atom are defined by X11 and these atoms are defined in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * for convenience. Common X Atoms like <code>XA_WM_NAME</code> are used to communicate with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Window manager to let it know the Window name. The use and protocol for these
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * atoms are defined in the Inter client communications converntions manual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * User specified XAtoms are defined by specifying a name that gets Interned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * by the XServer and an <code>XAtom</code> object is returned. An <code>XAtom</code> can also be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * by using a pre-exisiting atom like <code>XA_WM_CLASS</code>. A <code>display</code> has to be specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * in order to create an <code>XAtom</code>. <p> <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Once an <code>XAtom</code> instance is created, you can call get and set property methods to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * set the values for a particular window. <p> <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Example usage : To set the window name for a top level: <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * xa.setProperty(window,"Hello World");<p></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * To get the cut buffer :<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0);<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * String selection = xa.getProperty(root_window);<p></code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author  Bino George
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22584
diff changeset
    55
 * @since       1.5
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.misc.Unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
    61
public final class XAtom {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // Order of lock:  XAWTLock -> XAtom.class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /* Predefined Atoms - automatically extracted from XAtom.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static Unsafe unsafe = XlibWrapper.unsafe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static XAtom[] emptyList = new XAtom[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final long XA_PRIMARY=1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final long XA_SECONDARY=2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final long XA_ARC=3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final long XA_ATOM=4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final long XA_BITMAP=5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final long XA_CARDINAL=6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final long XA_COLORMAP=7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final long XA_CURSOR=8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final long XA_CUT_BUFFER0=9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final long XA_CUT_BUFFER1=10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final long XA_CUT_BUFFER2=11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final long XA_CUT_BUFFER3=12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final long XA_CUT_BUFFER4=13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final long XA_CUT_BUFFER5=14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final long XA_CUT_BUFFER6=15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final long XA_CUT_BUFFER7=16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final long XA_DRAWABLE=17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final long XA_FONT=18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final long XA_INTEGER=19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public static final long XA_PIXMAP=20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static final long XA_POINT=21;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final long XA_RECTANGLE=22;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public static final long XA_RESOURCE_MANAGER=23;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final long XA_RGB_COLOR_MAP=24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final long XA_RGB_BEST_MAP=25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public static final long XA_RGB_BLUE_MAP=26;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final long XA_RGB_DEFAULT_MAP=27;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public static final long XA_RGB_GRAY_MAP=28;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static final long XA_RGB_GREEN_MAP=29;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final long XA_RGB_RED_MAP=30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static final long XA_STRING=31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final long XA_VISUALID=32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static final long XA_WINDOW=33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final long XA_WM_COMMAND=34;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static final long XA_WM_HINTS=35;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public static final long XA_WM_CLIENT_MACHINE=36;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final long XA_WM_ICON_NAME=37;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static final long XA_WM_ICON_SIZE=38;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static final long XA_WM_NAME=39;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public static final long XA_WM_NORMAL_HINTS=40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static final long XA_WM_SIZE_HINTS=41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final long XA_WM_ZOOM_HINTS=42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static final long XA_MIN_SPACE=43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static final long XA_NORM_SPACE=44;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static final long XA_MAX_SPACE=45;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public static final long XA_END_SPACE=46;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final long XA_SUPERSCRIPT_X=47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static final long XA_SUPERSCRIPT_Y=48;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final long XA_SUBSCRIPT_X=49;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public static final long XA_SUBSCRIPT_Y=50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final long XA_UNDERLINE_POSITION=51;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final long XA_UNDERLINE_THICKNESS=52 ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public static final long XA_STRIKEOUT_ASCENT=53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static final long XA_STRIKEOUT_DESCENT=54;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final long XA_ITALIC_ANGLE=55;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public static final long XA_X_HEIGHT=56;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final long XA_QUAD_WIDTH=57;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static final long XA_WEIGHT=58;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static final long XA_POINT_SIZE=59;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static final long XA_RESOLUTION=60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static final long XA_COPYRIGHT=61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public static final long XA_NOTICE=62;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final long XA_FONT_NAME=63;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public static final long XA_FAMILY_NAME=64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final long XA_FULL_NAME=65;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static final long XA_CAP_HEIGHT=66;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final long XA_WM_CLASS=67;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public static final long XA_WM_TRANSIENT_FOR=68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final long XA_LAST_PREDEFINED=68;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    static HashMap<Long, XAtom> atomToAtom = new HashMap<Long, XAtom>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    static HashMap<String, XAtom> nameToAtom = new HashMap<String, XAtom>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static void register(XAtom at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            if (at.atom != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                atomToAtom.put(Long.valueOf(at.atom), at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if (at.name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                nameToAtom.put(at.name, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    static XAtom lookup(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return atomToAtom.get(Long.valueOf(atom));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    static XAtom lookup(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        synchronized (XAtom.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            return nameToAtom.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * [das]Suggestion:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * 1.Make XAtom immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * 2.Replace public ctors with factory methods (e.g. get() below).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    static XAtom get(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        XAtom xatom = lookup(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (xatom == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            xatom = new XAtom(XToolkit.getDisplay(), atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        return xatom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static XAtom get(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        XAtom xatom = lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (xatom == null) {
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
   178
            xatom = new XAtom(XToolkit.getDisplay(), name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return xatom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
26004
7507a1b93f67 6521783: Unnecessary final modifier for a method in a final class
serb
parents: 24865
diff changeset
   182
    public String getName() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                this.name = XlibWrapper.XGetAtomName(display, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    static String asString(long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        XAtom at = lookup(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return Long.toString(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            return at.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    void register() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        register(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            return name + ":" + atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            return Long.toString(atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /* interned value of Atom */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    long atom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /* name of atom */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* display for X connection */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    long display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**  This constructor will create and intern a new XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *  by the supplied name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param display X display to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param name name of the XAtom to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private XAtom(long display, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        this(display, name, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public XAtom(String name, boolean autoIntern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        this(XToolkit.getDisplay(), name, autoIntern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**  This constructor will create an instance of XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *  by the predefined XAtom specified by u <code> latom </code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param display X display to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param atom a predefined XAtom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public XAtom(long display, long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        this.atom = atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**  This constructor will create the instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *  and if <code>autoIntern</code> is true intern a new XAtom that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *  by the supplied name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param display X display to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param name name of the XAtom to create.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
114
a777da6f3f55 6636368: XAtom contains unused code
son
parents: 2
diff changeset
   261
    private XAtom(long display, String name, boolean autoIntern) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (autoIntern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                atom = XlibWrapper.InternAtom(display,name,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Creates uninitialized instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public XAtom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**  Sets the window property for the specified window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param window window id to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param str value to set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public void setProperty(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            XlibWrapper.SetProperty(display,window,atom,str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void setPropertyUTF8(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING");   /* like STRING but encoding is UTF-8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        byte[] bdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            bdata = str.getBytes("UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            uee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        if (bdata != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            setAtomData(window, XA_UTF8_STRING.atom, bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public void setProperty8(long window, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        byte[] bdata = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            bdata = str.getBytes("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        } catch (java.io.UnsupportedEncodingException uee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            uee.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (bdata != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            setAtomData(window, XA_STRING, bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
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
    /**  Gets the window property for the specified window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @param window window id to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @return string with the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public String getProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return XlibWrapper.GetProperty(display,window,atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Auxiliary function that returns the value of 'property' of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * 'property_type' on window 'window'.  Format of the property must be 32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public long get32Property(long window, long property_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            new WindowPropertyGetter(window, this, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                     false, property_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   372
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (getter.getActualType() != property_type || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return Native.getCard32(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *  Returns value of property of type CARDINAL/32 of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public long getCard32Property(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return get32Property(window.getWindow(), XA_CARDINAL);
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
     * Sets property of type CARDINAL on the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    public void setCard32Property(long window, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            Native.putCard32(XlibWrapper.larg1, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   403
                atom, XA_CARDINAL, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                XlibWrapper.larg1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Sets property of type CARDINAL/32 on the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void setCard32Property(XBaseWindow window, long value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        setCard32Property(window.getWindow(), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Gets uninterpreted set of data from property and stores them in data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Property type is the same as current atom, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Property format is 32. Property 'delete' is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Returns boolean if requested type, format, length match returned values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * and returned data pointer is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public boolean getAtomData(long window, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            new WindowPropertyGetter(window, this, 0, (long)length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                     false, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   434
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            if (getter.getActualType() != atom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                || getter.getActualFormat() != 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                || getter.getNumberOfItems() != length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Gets uninterpreted set of data from property and stores them in data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Property format is 32. Property 'delete' is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns boolean if requested type, format, length match returned values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * and returned data pointer is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public boolean getAtomData(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            new WindowPropertyGetter(window, this, 0, (long)length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                     false, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   468
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            if (getter.getActualType() != type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                || getter.getActualFormat() != 32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                || getter.getNumberOfItems() != length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
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
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Property type is the same as current atom, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * Property format is 32. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * of items pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    public void setAtomData(long window, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   499
                atom, atom, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Property format is 32. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * of items pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public void setAtomData(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   520
                atom, type, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Sets uninterpreted set of data into property from data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Property type is <code>type</code>, property is current atom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Property format is 8. Mode is PropModeReplace. length is a number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * of bytes pointer by data_ptr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public void setAtomData8(long window, long type, long data_ptr, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   541
                atom, type, 8, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                data_ptr, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Deletes property specified by this item on the window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public void DeleteProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
             XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Deletes property specified by this item on the window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public void DeleteProperty(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        checkWindow(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                window.getWindow(), atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
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 setAtomData(long window, long property_type, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        long bdata = Native.toData(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            setAtomData8(window, property_type, bdata, data.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            unsafe.freeMemory(bdata);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Auxiliary function that returns the value of 'property' of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * 'property_type' on window 'window'.  Format of the property must be 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public byte[] getByteArrayProperty(long window, long property_type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            new WindowPropertyGetter(window, this, 0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                     false, property_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   604
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (getter.getActualType() != property_type || getter.getActualFormat() != 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            byte[] res = XlibWrapper.getStringBytes(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            getter.dispose();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Interns the XAtom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public void intern(boolean onlyIfExists) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            atom = XlibWrapper.InternAtom(display,name, onlyIfExists?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public boolean isInterned() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                atom = XlibWrapper.InternAtom(display, name, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public void setValues(long display, String name, long atom) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        this.display = display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        this.atom = atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    static int getAtomSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        return Native.getLongSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Returns the value of property ATOM[]/32 as array of XAtom objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @return array of atoms, array of length 0 if the atom list is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *         or has different format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    XAtom[] getAtomListProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            new WindowPropertyGetter(window, this, 0, 0xFFFF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                     false, XA_ATOM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   676
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (getter.getActualType() != XA_ATOM || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
   683
            int count = getter.getNumberOfItems();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            if (count == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                return emptyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            long list_atoms = getter.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            XAtom[] res = new XAtom[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            for (int index = 0; index < count; index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                res[index] = XAtom.get(XAtom.getAtom(list_atoms+index*getAtomSize()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Returns the value of property of type ATOM[]/32 as XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @return list of atoms, empty list if the atom list is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *         or has different format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    XAtomList getAtomListPropertyList(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        return new XAtomList(getAtomListProperty(window));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    XAtomList getAtomListPropertyList(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        return getAtomListPropertyList(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    XAtom[] getAtomListProperty(XBaseWindow window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        return getAtomListProperty(window.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * Sets property value of type ATOM list to the list of atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    void setAtomListProperty(long window, XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        long data = toData(atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Sets property value of type ATOM list to the list of atoms specified by XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    void setAtomListProperty(long window, XAtomList atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        long data = atoms.getAtomsData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        unsafe.freeMemory(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * Sets property value of type ATOM list to the list of atoms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    public void setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        setAtomListProperty(window.getWindow(), atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Sets property value of type ATOM list to the list of atoms specified by XAtomList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public void setAtomListProperty(XBaseWindow window, XAtomList atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        setAtomListProperty(window.getWindow(), atoms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    long getAtom() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        return atom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    void putAtom(long ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        Native.putLong(ptr, atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    static long getAtom(long ptr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        return Native.getLong(ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Allocated memory to hold the list of native atom data and returns unsafe pointer to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Caller should free the memory by himself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    static long toData(XAtom[] atoms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        long data = unsafe.allocateMemory(getAtomSize() * atoms.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        for (int i = 0; i < atoms.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (atoms[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                atoms[i].putAtom(data + i * getAtomSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        return data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    void checkWindow(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (window == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            throw new IllegalArgumentException("Window must not be zero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        if (!(o instanceof XAtom)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        XAtom ot = (XAtom)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        return (atom == ot.atom && display == ot.display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        return (int)((atom ^ display)& 0xFFFFL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Sets property on the <code>window</code> to the value <code>window_value</window>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Property is assumed to be of type WINDOW/32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    public void setWindowProperty(long window, long window_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            Native.putWindow(XlibWrapper.larg1, window_value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   799
                                    atom, XA_WINDOW, 32, XConstants.PropModeReplace,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                                    XlibWrapper.larg1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public void setWindowProperty(XBaseWindow window, XBaseWindow window_value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        setWindowProperty(window.getWindow(), window_value.getWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * Gets property on the <code>window</code>. Property is assumed to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * of type WINDOW/32.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    public long getWindowProperty(long window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        if (atom == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            throw new IllegalStateException("Atom should be initialized");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        checkWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        WindowPropertyGetter getter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            new WindowPropertyGetter(window, this, 0, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                                     false, XA_WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            int status = getter.execute();
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 114
diff changeset
   823
            if (status != XConstants.Success || getter.getData() == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            if (getter.getActualType() != XA_WINDOW || getter.getActualFormat() != 32) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            return Native.getWindow(getter.getData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            getter.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
}