0N/A/*
2362N/A * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.awt.X11;
0N/A
0N/A/**
0N/A * XAtom is a class that allows you to create and modify X Window properties.
0N/A * An X Atom is an identifier for a property that you can set on any X Window.
0N/A * Standard X Atom are defined by X11 and these atoms are defined in this class
0N/A * for convenience. Common X Atoms like <code>XA_WM_NAME</code> are used to communicate with the
0N/A * Window manager to let it know the Window name. The use and protocol for these
0N/A * atoms are defined in the Inter client communications converntions manual.
0N/A * User specified XAtoms are defined by specifying a name that gets Interned
0N/A * by the XServer and an <code>XAtom</code> object is returned. An <code>XAtom</code> can also be created
0N/A * by using a pre-exisiting atom like <code>XA_WM_CLASS</code>. A <code>display</code> has to be specified
0N/A * in order to create an <code>XAtom</code>. <p> <p>
0N/A *
0N/A * Once an <code>XAtom</code> instance is created, you can call get and set property methods to
0N/A * set the values for a particular window. <p> <p>
0N/A *
0N/A *
0N/A * Example usage : To set the window name for a top level: <p>
0N/A * <code>
0N/A * XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); <p>
0N/A * xa.setProperty(window,"Hello World");<p></code>
0N/A *<p>
0N/A *<p>
0N/A * To get the cut buffer :<p>
0N/A * <p><code>
0N/A * XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0);<p>
0N/A * String selection = xa.getProperty(root_window);<p></code>
0N/A * @author Bino George
0N/A * @since JDK1.5
0N/A */
0N/A
0N/Aimport sun.misc.Unsafe;
0N/Aimport java.util.HashMap;
0N/A
91N/Apublic final class XAtom {
0N/A
0N/A // Order of lock: XAWTLock -> XAtom.class
0N/A
0N/A /* Predefined Atoms - automatically extracted from XAtom.h */
0N/A private static Unsafe unsafe = XlibWrapper.unsafe;
0N/A private static XAtom[] emptyList = new XAtom[0];
0N/A
0N/A public static final long XA_PRIMARY=1;
0N/A public static final long XA_SECONDARY=2;
0N/A public static final long XA_ARC=3;
0N/A public static final long XA_ATOM=4;
0N/A public static final long XA_BITMAP=5;
0N/A public static final long XA_CARDINAL=6;
0N/A public static final long XA_COLORMAP=7;
0N/A public static final long XA_CURSOR=8;
0N/A public static final long XA_CUT_BUFFER0=9;
0N/A public static final long XA_CUT_BUFFER1=10;
0N/A public static final long XA_CUT_BUFFER2=11;
0N/A public static final long XA_CUT_BUFFER3=12;
0N/A public static final long XA_CUT_BUFFER4=13;
0N/A public static final long XA_CUT_BUFFER5=14;
0N/A public static final long XA_CUT_BUFFER6=15;
0N/A public static final long XA_CUT_BUFFER7=16;
0N/A public static final long XA_DRAWABLE=17;
0N/A public static final long XA_FONT=18;
0N/A public static final long XA_INTEGER=19;
0N/A public static final long XA_PIXMAP=20;
0N/A public static final long XA_POINT=21;
0N/A public static final long XA_RECTANGLE=22;
0N/A public static final long XA_RESOURCE_MANAGER=23;
0N/A public static final long XA_RGB_COLOR_MAP=24;
0N/A public static final long XA_RGB_BEST_MAP=25;
0N/A public static final long XA_RGB_BLUE_MAP=26;
0N/A public static final long XA_RGB_DEFAULT_MAP=27;
0N/A public static final long XA_RGB_GRAY_MAP=28;
0N/A public static final long XA_RGB_GREEN_MAP=29;
0N/A public static final long XA_RGB_RED_MAP=30;
0N/A public static final long XA_STRING=31;
0N/A public static final long XA_VISUALID=32;
0N/A public static final long XA_WINDOW=33;
0N/A public static final long XA_WM_COMMAND=34;
0N/A public static final long XA_WM_HINTS=35;
0N/A public static final long XA_WM_CLIENT_MACHINE=36;
0N/A public static final long XA_WM_ICON_NAME=37;
0N/A public static final long XA_WM_ICON_SIZE=38;
0N/A public static final long XA_WM_NAME=39;
0N/A public static final long XA_WM_NORMAL_HINTS=40;
0N/A public static final long XA_WM_SIZE_HINTS=41;
0N/A public static final long XA_WM_ZOOM_HINTS=42;
0N/A public static final long XA_MIN_SPACE=43;
0N/A public static final long XA_NORM_SPACE=44;
0N/A public static final long XA_MAX_SPACE=45;
0N/A public static final long XA_END_SPACE=46;
0N/A public static final long XA_SUPERSCRIPT_X=47;
0N/A public static final long XA_SUPERSCRIPT_Y=48;
0N/A public static final long XA_SUBSCRIPT_X=49;
0N/A public static final long XA_SUBSCRIPT_Y=50;
0N/A public static final long XA_UNDERLINE_POSITION=51;
0N/A public static final long XA_UNDERLINE_THICKNESS=52 ;
0N/A public static final long XA_STRIKEOUT_ASCENT=53;
0N/A public static final long XA_STRIKEOUT_DESCENT=54;
0N/A public static final long XA_ITALIC_ANGLE=55;
0N/A public static final long XA_X_HEIGHT=56;
0N/A public static final long XA_QUAD_WIDTH=57;
0N/A public static final long XA_WEIGHT=58;
0N/A public static final long XA_POINT_SIZE=59;
0N/A public static final long XA_RESOLUTION=60;
0N/A public static final long XA_COPYRIGHT=61;
0N/A public static final long XA_NOTICE=62;
0N/A public static final long XA_FONT_NAME=63;
0N/A public static final long XA_FAMILY_NAME=64;
0N/A public static final long XA_FULL_NAME=65;
0N/A public static final long XA_CAP_HEIGHT=66;
0N/A public static final long XA_WM_CLASS=67;
0N/A public static final long XA_WM_TRANSIENT_FOR=68;
0N/A public static final long XA_LAST_PREDEFINED=68;
0N/A static HashMap<Long, XAtom> atomToAtom = new HashMap<Long, XAtom>();
0N/A static HashMap<String, XAtom> nameToAtom = new HashMap<String, XAtom>();
0N/A static void register(XAtom at) {
0N/A if (at == null) {
0N/A return;
0N/A }
0N/A synchronized (XAtom.class) {
0N/A if (at.atom != 0) {
0N/A atomToAtom.put(Long.valueOf(at.atom), at);
0N/A }
0N/A if (at.name != null) {
0N/A nameToAtom.put(at.name, at);
0N/A }
0N/A }
0N/A }
0N/A static XAtom lookup(long atom) {
0N/A synchronized (XAtom.class) {
0N/A return atomToAtom.get(Long.valueOf(atom));
0N/A }
0N/A }
0N/A static XAtom lookup(String name) {
0N/A synchronized (XAtom.class) {
0N/A return nameToAtom.get(name);
0N/A }
0N/A }
0N/A /*
0N/A * [das]Suggestion:
0N/A * 1.Make XAtom immutable.
0N/A * 2.Replace public ctors with factory methods (e.g. get() below).
0N/A */
0N/A static XAtom get(long atom) {
0N/A XAtom xatom = lookup(atom);
0N/A if (xatom == null) {
0N/A xatom = new XAtom(XToolkit.getDisplay(), atom);
0N/A }
0N/A return xatom;
0N/A }
0N/A public static XAtom get(String name) {
0N/A XAtom xatom = lookup(name);
0N/A if (xatom == null) {
91N/A xatom = new XAtom(XToolkit.getDisplay(), name);
0N/A }
0N/A return xatom;
0N/A }
0N/A public final String getName() {
0N/A if (name == null) {
0N/A XToolkit.awtLock();
0N/A try {
0N/A this.name = XlibWrapper.XGetAtomName(display, atom);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A register();
0N/A }
0N/A return name;
0N/A }
0N/A static String asString(long atom) {
0N/A XAtom at = lookup(atom);
0N/A if (at == null) {
0N/A return Long.toString(atom);
0N/A } else {
0N/A return at.toString();
0N/A }
0N/A }
0N/A void register() {
0N/A register(this);
0N/A }
0N/A public String toString() {
0N/A if (name != null) {
0N/A return name + ":" + atom;
0N/A } else {
0N/A return Long.toString(atom);
0N/A }
0N/A }
0N/A
0N/A /* interned value of Atom */
0N/A long atom = 0;
0N/A
0N/A /* name of atom */
0N/A String name;
0N/A
0N/A /* display for X connection */
0N/A long display;
0N/A
0N/A
0N/A /** This constructor will create and intern a new XAtom that is specified
0N/A * by the supplied name.
0N/A *
0N/A * @param display X display to use
0N/A * @param name name of the XAtom to create.
0N/A * @since 1.5
0N/A */
0N/A
0N/A private XAtom(long display, String name) {
0N/A this(display, name, true);
0N/A }
0N/A
0N/A public XAtom(String name, boolean autoIntern) {
0N/A this(XToolkit.getDisplay(), name, autoIntern);
0N/A }
0N/A
0N/A /** This constructor will create an instance of XAtom that is specified
0N/A * by the predefined XAtom specified by u <code> latom </code>
0N/A *
0N/A * @param display X display to use.
0N/A * @param atom a predefined XAtom.
0N/A * @since 1.5
0N/A */
0N/A public XAtom(long display, long atom) {
0N/A this.atom = atom;
0N/A this.display = display;
0N/A register();
0N/A }
0N/A
0N/A /** This constructor will create the instance,
0N/A * and if <code>autoIntern</code> is true intern a new XAtom that is specified
0N/A * by the supplied name.
0N/A *
0N/A * @param display X display to use
0N/A * @param name name of the XAtom to create.
0N/A * @since 1.5
0N/A */
0N/A
91N/A private XAtom(long display, String name, boolean autoIntern) {
0N/A this.name = name;
0N/A this.display = display;
0N/A if (autoIntern) {
0N/A XToolkit.awtLock();
0N/A try {
0N/A atom = XlibWrapper.InternAtom(display,name,0);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A register();
0N/A }
0N/A
0N/A /**
0N/A * Creates uninitialized instance of
0N/A */
0N/A public XAtom() {
0N/A }
0N/A
0N/A /** Sets the window property for the specified window
0N/A * @param window window id to use
0N/A * @param str value to set to.
0N/A * @since 1.5
0N/A */
0N/A public void setProperty(long window, String str) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.SetProperty(display,window,atom,str);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
0N/A */
0N/A public void setPropertyUTF8(long window, String str) {
0N/A XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING"); /* like STRING but encoding is UTF-8 */
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A byte[] bdata = null;
0N/A try {
0N/A bdata = str.getBytes("UTF-8");
0N/A } catch (java.io.UnsupportedEncodingException uee) {
0N/A uee.printStackTrace();
0N/A }
0N/A if (bdata != null) {
0N/A setAtomData(window, XA_UTF8_STRING.atom, bdata);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
0N/A */
0N/A public void setProperty8(long window, String str) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A byte[] bdata = null;
0N/A try {
0N/A bdata = str.getBytes("ISO-8859-1");
0N/A } catch (java.io.UnsupportedEncodingException uee) {
0N/A uee.printStackTrace();
0N/A }
0N/A if (bdata != null) {
0N/A setAtomData(window, XA_STRING, bdata);
0N/A }
0N/A }
0N/A
0N/A
0N/A /** Gets the window property for the specified window
0N/A * @param window window id to use
0N/A * @param str value to set to.
0N/A * @return string with the property.
0N/A * @since 1.5
0N/A */
0N/A public String getProperty(long window) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A return XlibWrapper.GetProperty(display,window,atom);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A
0N/A /*
0N/A * Auxiliary function that returns the value of 'property' of type
0N/A * 'property_type' on window 'window'. Format of the property must be 32.
0N/A */
0N/A public long get32Property(long window, long property_type) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, 1,
0N/A false, property_type);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return 0;
0N/A }
0N/A if (getter.getActualType() != property_type || getter.getActualFormat() != 32) {
0N/A return 0;
0N/A }
0N/A return Native.getCard32(getter.getData());
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns value of property of type CARDINAL/32 of this window
0N/A */
0N/A public long getCard32Property(XBaseWindow window) {
0N/A return get32Property(window.getWindow(), XA_CARDINAL);
0N/A }
0N/A
0N/A /**
0N/A * Sets property of type CARDINAL on the window
0N/A */
0N/A public void setCard32Property(long window, long value) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A Native.putCard32(XlibWrapper.larg1, value);
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
216N/A atom, XA_CARDINAL, 32, XConstants.PropModeReplace,
0N/A XlibWrapper.larg1, 1);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets property of type CARDINAL/32 on the window
0N/A */
0N/A public void setCard32Property(XBaseWindow window, long value) {
0N/A setCard32Property(window.getWindow(), value);
0N/A }
0N/A
0N/A /**
0N/A * Gets uninterpreted set of data from property and stores them in data_ptr.
0N/A * Property type is the same as current atom, property is current atom.
0N/A * Property format is 32. Property 'delete' is false.
0N/A * Returns boolean if requested type, format, length match returned values
0N/A * and returned data pointer is not null.
0N/A */
0N/A public boolean getAtomData(long window, long data_ptr, int length) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, (long)length,
0N/A false, this);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return false;
0N/A }
0N/A if (getter.getActualType() != atom
0N/A || getter.getActualFormat() != 32
0N/A || getter.getNumberOfItems() != length
0N/A )
0N/A {
0N/A return false;
0N/A }
0N/A XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
0N/A return true;
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gets uninterpreted set of data from property and stores them in data_ptr.
0N/A * Property type is <code>type</code>, property is current atom.
0N/A * Property format is 32. Property 'delete' is false.
0N/A * Returns boolean if requested type, format, length match returned values
0N/A * and returned data pointer is not null.
0N/A */
0N/A public boolean getAtomData(long window, long type, long data_ptr, int length) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, (long)length,
0N/A false, type);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return false;
0N/A }
0N/A if (getter.getActualType() != type
0N/A || getter.getActualFormat() != 32
0N/A || getter.getNumberOfItems() != length
0N/A )
0N/A {
0N/A return false;
0N/A }
0N/A XlibWrapper.memcpy(data_ptr, getter.getData(), length*getAtomSize());
0N/A return true;
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets uninterpreted set of data into property from data_ptr.
0N/A * Property type is the same as current atom, property is current atom.
0N/A * Property format is 32. Mode is PropModeReplace. length is a number
0N/A * of items pointer by data_ptr.
0N/A */
0N/A public void setAtomData(long window, long data_ptr, int length) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
216N/A atom, atom, 32, XConstants.PropModeReplace,
0N/A data_ptr, length);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets uninterpreted set of data into property from data_ptr.
0N/A * Property type is <code>type</code>, property is current atom.
0N/A * Property format is 32. Mode is PropModeReplace. length is a number
0N/A * of items pointer by data_ptr.
0N/A */
0N/A public void setAtomData(long window, long type, long data_ptr, int length) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
216N/A atom, type, 32, XConstants.PropModeReplace,
0N/A data_ptr, length);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets uninterpreted set of data into property from data_ptr.
0N/A * Property type is <code>type</code>, property is current atom.
0N/A * Property format is 8. Mode is PropModeReplace. length is a number
0N/A * of bytes pointer by data_ptr.
0N/A */
0N/A public void setAtomData8(long window, long type, long data_ptr, int length) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
216N/A atom, type, 8, XConstants.PropModeReplace,
0N/A data_ptr, length);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Deletes property specified by this item on the window.
0N/A */
0N/A public void DeleteProperty(long window) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window, atom);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Deletes property specified by this item on the window.
0N/A */
0N/A public void DeleteProperty(XBaseWindow window) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window.getWindow());
0N/A XToolkit.awtLock();
0N/A try {
0N/A XlibWrapper.XDeleteProperty(XToolkit.getDisplay(),
0N/A window.getWindow(), atom);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A
0N/A public void setAtomData(long window, long property_type, byte[] data) {
0N/A long bdata = Native.toData(data);
0N/A try {
0N/A setAtomData8(window, property_type, bdata, data.length);
0N/A } finally {
0N/A unsafe.freeMemory(bdata);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Auxiliary function that returns the value of 'property' of type
0N/A * 'property_type' on window 'window'. Format of the property must be 8.
0N/A */
0N/A public byte[] getByteArrayProperty(long window, long property_type) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, 0xFFFF,
0N/A false, property_type);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return null;
0N/A }
0N/A if (getter.getActualType() != property_type || getter.getActualFormat() != 8) {
0N/A return null;
0N/A }
0N/A byte[] res = XlibWrapper.getStringBytes(getter.getData());
0N/A return res;
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Interns the XAtom
0N/A */
0N/A public void intern(boolean onlyIfExists) {
0N/A XToolkit.awtLock();
0N/A try {
0N/A atom = XlibWrapper.InternAtom(display,name, onlyIfExists?1:0);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A register();
0N/A }
0N/A
0N/A public boolean isInterned() {
0N/A if (atom == 0) {
0N/A XToolkit.awtLock();
0N/A try {
0N/A atom = XlibWrapper.InternAtom(display, name, 1);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A if (atom == 0) {
0N/A return false;
0N/A } else {
0N/A register();
0N/A return true;
0N/A }
0N/A } else {
0N/A return true;
0N/A }
0N/A }
0N/A
0N/A public void setValues(long display, String name, long atom) {
0N/A this.display = display;
0N/A this.atom = atom;
0N/A this.name = name;
0N/A register();
0N/A }
0N/A
0N/A static int getAtomSize() {
0N/A return Native.getLongSize();
0N/A }
0N/A
0N/A /*
0N/A * Returns the value of property ATOM[]/32 as array of XAtom objects
0N/A * @return array of atoms, array of length 0 if the atom list is empty
0N/A * or has different format
0N/A */
0N/A XAtom[] getAtomListProperty(long window) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, 0xFFFF,
0N/A false, XA_ATOM);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return emptyList;
0N/A }
0N/A if (getter.getActualType() != XA_ATOM || getter.getActualFormat() != 32) {
0N/A return emptyList;
0N/A }
0N/A
0N/A int count = (int)getter.getNumberOfItems();
0N/A if (count == 0) {
0N/A return emptyList;
0N/A }
0N/A long list_atoms = getter.getData();
0N/A XAtom[] res = new XAtom[count];
0N/A for (int index = 0; index < count; index++) {
0N/A res[index] = XAtom.get(XAtom.getAtom(list_atoms+index*getAtomSize()));
0N/A }
0N/A return res;
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Returns the value of property of type ATOM[]/32 as XAtomList
0N/A * @return list of atoms, empty list if the atom list is empty
0N/A * or has different format
0N/A */
0N/A XAtomList getAtomListPropertyList(long window) {
0N/A return new XAtomList(getAtomListProperty(window));
0N/A }
0N/A XAtomList getAtomListPropertyList(XBaseWindow window) {
0N/A return getAtomListPropertyList(window.getWindow());
0N/A }
0N/A XAtom[] getAtomListProperty(XBaseWindow window) {
0N/A return getAtomListProperty(window.getWindow());
0N/A }
0N/A
0N/A /**
0N/A * Sets property value of type ATOM list to the list of atoms.
0N/A */
0N/A void setAtomListProperty(long window, XAtom[] atoms) {
0N/A long data = toData(atoms);
0N/A setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
0N/A unsafe.freeMemory(data);
0N/A }
0N/A
0N/A /**
0N/A * Sets property value of type ATOM list to the list of atoms specified by XAtomList
0N/A */
0N/A void setAtomListProperty(long window, XAtomList atoms) {
0N/A long data = atoms.getAtomsData();
0N/A setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
0N/A unsafe.freeMemory(data);
0N/A }
0N/A /**
0N/A * Sets property value of type ATOM list to the list of atoms.
0N/A */
0N/A public void setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
0N/A setAtomListProperty(window.getWindow(), atoms);
0N/A }
0N/A
0N/A /**
0N/A * Sets property value of type ATOM list to the list of atoms specified by XAtomList
0N/A */
0N/A public void setAtomListProperty(XBaseWindow window, XAtomList atoms) {
0N/A setAtomListProperty(window.getWindow(), atoms);
0N/A }
0N/A
0N/A long getAtom() {
0N/A return atom;
0N/A }
0N/A
0N/A void putAtom(long ptr) {
0N/A Native.putLong(ptr, atom);
0N/A }
0N/A
0N/A static long getAtom(long ptr) {
0N/A return Native.getLong(ptr);
0N/A }
0N/A /**
0N/A * Allocated memory to hold the list of native atom data and returns unsafe pointer to it
0N/A * Caller should free the memory by himself.
0N/A */
0N/A static long toData(XAtom[] atoms) {
0N/A long data = unsafe.allocateMemory(getAtomSize() * atoms.length);
0N/A for (int i = 0; i < atoms.length; i++ ) {
0N/A if (atoms[i] != null) {
0N/A atoms[i].putAtom(data + i * getAtomSize());
0N/A }
0N/A }
0N/A return data;
0N/A }
0N/A
0N/A void checkWindow(long window) {
0N/A if (window == 0) {
0N/A throw new IllegalArgumentException("Window must not be zero");
0N/A }
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if (!(o instanceof XAtom)) {
0N/A return false;
0N/A }
0N/A XAtom ot = (XAtom)o;
0N/A return (atom == ot.atom && display == ot.display);
0N/A }
0N/A public int hashCode() {
0N/A return (int)((atom ^ display)& 0xFFFFL);
0N/A }
0N/A
0N/A /**
0N/A * Sets property on the <code>window</code> to the value <code>window_value</window>
0N/A * Property is assumed to be of type WINDOW/32
0N/A */
0N/A public void setWindowProperty(long window, long window_value) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A XToolkit.awtLock();
0N/A try {
0N/A Native.putWindow(XlibWrapper.larg1, window_value);
0N/A XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
216N/A atom, XA_WINDOW, 32, XConstants.PropModeReplace,
0N/A XlibWrapper.larg1, 1);
0N/A } finally {
0N/A XToolkit.awtUnlock();
0N/A }
0N/A }
0N/A public void setWindowProperty(XBaseWindow window, XBaseWindow window_value) {
0N/A setWindowProperty(window.getWindow(), window_value.getWindow());
0N/A }
0N/A
0N/A /**
0N/A * Gets property on the <code>window</code>. Property is assumed to be
0N/A * of type WINDOW/32.
0N/A */
0N/A public long getWindowProperty(long window) {
0N/A if (atom == 0) {
0N/A throw new IllegalStateException("Atom should be initialized");
0N/A }
0N/A checkWindow(window);
0N/A WindowPropertyGetter getter =
0N/A new WindowPropertyGetter(window, this, 0, 1,
0N/A false, XA_WINDOW);
0N/A try {
0N/A int status = getter.execute();
216N/A if (status != XConstants.Success || getter.getData() == 0) {
0N/A return 0;
0N/A }
0N/A if (getter.getActualType() != XA_WINDOW || getter.getActualFormat() != 32) {
0N/A return 0;
0N/A }
0N/A return Native.getWindow(getter.getData());
0N/A } finally {
0N/A getter.dispose();
0N/A }
0N/A }
0N/A}