Source Code Cross Referenced for XAtom.java in  » 6.0-JDK-Platform » solaris » sun » awt » X11 » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Platform » solaris » sun.awt.X11 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
003:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004:         *
005:         * This code is free software; you can redistribute it and/or modify it
006:         * under the terms of the GNU General Public License version 2 only, as
007:         * published by the Free Software Foundation.  Sun designates this
008:         * particular file as subject to the "Classpath" exception as provided
009:         * by Sun in the LICENSE file that accompanied this code.
010:         *
011:         * This code is distributed in the hope that it will be useful, but WITHOUT
012:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013:         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014:         * version 2 for more details (a copy is included in the LICENSE file that
015:         * accompanied this code).
016:         *
017:         * You should have received a copy of the GNU General Public License version
018:         * 2 along with this work; if not, write to the Free Software Foundation,
019:         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020:         *
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022:         * CA 95054 USA or visit www.sun.com if you need additional information or
023:         * have any questions.
024:         */
025:
026:        package sun.awt.X11;
027:
028:        /**
029:         * XAtom is a class that allows you to create and modify X Window properties.
030:         * An X Atom is an identifier for a property that you can set on any X Window.
031:         * Standard X Atom are defined by X11 and these atoms are defined in this class
032:         * for convenience. Common X Atoms like <code>XA_WM_NAME</code> are used to communicate with the
033:         * Window manager to let it know the Window name. The use and protocol for these
034:         * atoms are defined in the Inter client communications converntions manual.
035:         * User specified XAtoms are defined by specifying a name that gets Interned
036:         * by the XServer and an <code>XAtom</code> object is returned. An <code>XAtom</code> can also be created
037:         * by using a pre-exisiting atom like <code>XA_WM_CLASS</code>. A <code>display</code> has to be specified
038:         * in order to create an <code>XAtom</code>. <p> <p>
039:         *
040:         * Once an <code>XAtom</code> instance is created, you can call get and set property methods to
041:         * set the values for a particular window. <p> <p>
042:         *
043:         *
044:         * Example usage : To set the window name for a top level: <p>
045:         * <code>
046:         * XAtom xa = new XAtom(display,XAtom.XA_WM_NAME); <p>
047:         * xa.setProperty(window,"Hello World");<p></code>
048:         *<p>
049:         *<p>
050:         * To get the cut buffer :<p>
051:         * <p><code>
052:         * XAtom xa = new XAtom(display,XAtom.XA_CUT_BUFFER0);<p>
053:         * String selection = xa.getProperty(root_window);<p></code>
054:         * @version     1.0, 9/6/02
055:         * @author  Bino George
056:         * @since       JDK1.5
057:         */
058:
059:        import sun.misc.Unsafe;
060:        import java.util.HashMap;
061:
062:        public class XAtom {
063:
064:            // Order of lock:  XAWTLock -> XAtom.class
065:
066:            /* Predefined Atoms - automatically extracted from XAtom.h */
067:            private static Unsafe unsafe = XlibWrapper.unsafe;
068:            private static XAtom[] emptyList = new XAtom[0];
069:
070:            public static final long XA_PRIMARY = 1;
071:            public static final long XA_SECONDARY = 2;
072:            public static final long XA_ARC = 3;
073:            public static final long XA_ATOM = 4;
074:            public static final long XA_BITMAP = 5;
075:            public static final long XA_CARDINAL = 6;
076:            public static final long XA_COLORMAP = 7;
077:            public static final long XA_CURSOR = 8;
078:            public static final long XA_CUT_BUFFER0 = 9;
079:            public static final long XA_CUT_BUFFER1 = 10;
080:            public static final long XA_CUT_BUFFER2 = 11;
081:            public static final long XA_CUT_BUFFER3 = 12;
082:            public static final long XA_CUT_BUFFER4 = 13;
083:            public static final long XA_CUT_BUFFER5 = 14;
084:            public static final long XA_CUT_BUFFER6 = 15;
085:            public static final long XA_CUT_BUFFER7 = 16;
086:            public static final long XA_DRAWABLE = 17;
087:            public static final long XA_FONT = 18;
088:            public static final long XA_INTEGER = 19;
089:            public static final long XA_PIXMAP = 20;
090:            public static final long XA_POINT = 21;
091:            public static final long XA_RECTANGLE = 22;
092:            public static final long XA_RESOURCE_MANAGER = 23;
093:            public static final long XA_RGB_COLOR_MAP = 24;
094:            public static final long XA_RGB_BEST_MAP = 25;
095:            public static final long XA_RGB_BLUE_MAP = 26;
096:            public static final long XA_RGB_DEFAULT_MAP = 27;
097:            public static final long XA_RGB_GRAY_MAP = 28;
098:            public static final long XA_RGB_GREEN_MAP = 29;
099:            public static final long XA_RGB_RED_MAP = 30;
100:            public static final long XA_STRING = 31;
101:            public static final long XA_VISUALID = 32;
102:            public static final long XA_WINDOW = 33;
103:            public static final long XA_WM_COMMAND = 34;
104:            public static final long XA_WM_HINTS = 35;
105:            public static final long XA_WM_CLIENT_MACHINE = 36;
106:            public static final long XA_WM_ICON_NAME = 37;
107:            public static final long XA_WM_ICON_SIZE = 38;
108:            public static final long XA_WM_NAME = 39;
109:            public static final long XA_WM_NORMAL_HINTS = 40;
110:            public static final long XA_WM_SIZE_HINTS = 41;
111:            public static final long XA_WM_ZOOM_HINTS = 42;
112:            public static final long XA_MIN_SPACE = 43;
113:            public static final long XA_NORM_SPACE = 44;
114:            public static final long XA_MAX_SPACE = 45;
115:            public static final long XA_END_SPACE = 46;
116:            public static final long XA_SUPERSCRIPT_X = 47;
117:            public static final long XA_SUPERSCRIPT_Y = 48;
118:            public static final long XA_SUBSCRIPT_X = 49;
119:            public static final long XA_SUBSCRIPT_Y = 50;
120:            public static final long XA_UNDERLINE_POSITION = 51;
121:            public static final long XA_UNDERLINE_THICKNESS = 52;
122:            public static final long XA_STRIKEOUT_ASCENT = 53;
123:            public static final long XA_STRIKEOUT_DESCENT = 54;
124:            public static final long XA_ITALIC_ANGLE = 55;
125:            public static final long XA_X_HEIGHT = 56;
126:            public static final long XA_QUAD_WIDTH = 57;
127:            public static final long XA_WEIGHT = 58;
128:            public static final long XA_POINT_SIZE = 59;
129:            public static final long XA_RESOLUTION = 60;
130:            public static final long XA_COPYRIGHT = 61;
131:            public static final long XA_NOTICE = 62;
132:            public static final long XA_FONT_NAME = 63;
133:            public static final long XA_FAMILY_NAME = 64;
134:            public static final long XA_FULL_NAME = 65;
135:            public static final long XA_CAP_HEIGHT = 66;
136:            public static final long XA_WM_CLASS = 67;
137:            public static final long XA_WM_TRANSIENT_FOR = 68;
138:            public static final long XA_LAST_PREDEFINED = 68;
139:            static HashMap<Long, XAtom> atomToAtom = new HashMap<Long, XAtom>();
140:            static HashMap<String, XAtom> nameToAtom = new HashMap<String, XAtom>();
141:
142:            static void register(XAtom at) {
143:                if (at == null) {
144:                    return;
145:                }
146:                synchronized (XAtom.class) {
147:                    if (at.atom != 0) {
148:                        atomToAtom.put(Long.valueOf(at.atom), at);
149:                    }
150:                    if (at.name != null) {
151:                        nameToAtom.put(at.name, at);
152:                    }
153:                }
154:            }
155:
156:            static XAtom lookup(long atom) {
157:                synchronized (XAtom.class) {
158:                    return atomToAtom.get(Long.valueOf(atom));
159:                }
160:            }
161:
162:            static XAtom lookup(String name) {
163:                synchronized (XAtom.class) {
164:                    return nameToAtom.get(name);
165:                }
166:            }
167:
168:            /*
169:             * [das]Suggestion:
170:             * 1.Make XAtom immutable.
171:             * 2.Replace public ctors with factory methods (e.g. get() below).
172:             */
173:            static XAtom get(long atom) {
174:                XAtom xatom = lookup(atom);
175:                if (xatom == null) {
176:                    xatom = new XAtom(XToolkit.getDisplay(), atom);
177:                }
178:                return xatom;
179:            }
180:
181:            public static XAtom get(String name) {
182:                XAtom xatom = lookup(name);
183:                if (xatom == null) {
184:                    xatom = new XAtom(name);
185:                }
186:                return xatom;
187:            }
188:
189:            public final String getName() {
190:                if (name == null) {
191:                    XToolkit.awtLock();
192:                    try {
193:                        this .name = XlibWrapper.XGetAtomName(display, atom);
194:                    } finally {
195:                        XToolkit.awtUnlock();
196:                    }
197:                    register();
198:                }
199:                return name;
200:            }
201:
202:            static String asString(long atom) {
203:                XAtom at = lookup(atom);
204:                if (at == null) {
205:                    return Long.toString(atom);
206:                } else {
207:                    return at.toString();
208:                }
209:            }
210:
211:            void register() {
212:                register(this );
213:            }
214:
215:            public String toString() {
216:                if (name != null) {
217:                    return name + ":" + atom;
218:                } else {
219:                    return Long.toString(atom);
220:                }
221:            }
222:
223:            /* interned value of Atom */
224:            long atom = 0;
225:
226:            /* name of atom */
227:            String name;
228:
229:            /* display for X connection */
230:            long display;
231:
232:            /**  This constructor will create and intern a new XAtom that is specified
233:             *  by the supplied name.
234:             *
235:             * @param display X display to use
236:             * @param name name of the XAtom to create.
237:             * @since 1.5
238:             */
239:
240:            private XAtom(long display, String name) {
241:                this (display, name, true);
242:            }
243:
244:            private XAtom(String name) {
245:                this (XToolkit.getDisplay(), name, true);
246:            }
247:
248:            public XAtom(String name, boolean autoIntern) {
249:                this (XToolkit.getDisplay(), name, autoIntern);
250:            }
251:
252:            /**  This constructor will create an instance of XAtom that is specified
253:             *  by the predefined XAtom specified by u <code> latom </code>
254:             *
255:             * @param display X display to use.
256:             * @param atom a predefined XAtom.
257:             * @since 1.5
258:             */
259:            public XAtom(long display, long atom) {
260:                this .atom = atom;
261:                this .display = display;
262:                register();
263:            }
264:
265:            /**  This constructor will create the instance,
266:             *  and if <code>autoIntern</code> is true intern a new XAtom that is specified
267:             *  by the supplied name.
268:             *
269:             * @param display X display to use
270:             * @param name name of the XAtom to create.
271:             * @since 1.5
272:             */
273:
274:            public XAtom(long display, String name, boolean autoIntern) {
275:                this .name = name;
276:                this .display = display;
277:                if (autoIntern) {
278:                    XToolkit.awtLock();
279:                    try {
280:                        atom = XlibWrapper.InternAtom(display, name, 0);
281:                    } finally {
282:                        XToolkit.awtUnlock();
283:                    }
284:                }
285:                register();
286:            }
287:
288:            /**
289:             * Creates uninitialized instance of
290:             */
291:            public XAtom() {
292:            }
293:
294:            /**  Sets the window property for the specified window
295:             * @param window window id to use
296:             * @param str value to set to.
297:             * @since 1.5
298:             */
299:            public void setProperty(long window, String str) {
300:                if (atom == 0) {
301:                    throw new IllegalStateException(
302:                            "Atom should be initialized");
303:                }
304:                checkWindow(window);
305:                XToolkit.awtLock();
306:                try {
307:                    XlibWrapper.SetProperty(display, window, atom, str);
308:                } finally {
309:                    XToolkit.awtUnlock();
310:                }
311:            }
312:
313:            /**
314:             * Sets UTF8_STRING type property. Explicitly converts str to UTF-8 byte sequence.
315:             */
316:            public void setPropertyUTF8(long window, String str) {
317:                XAtom XA_UTF8_STRING = XAtom.get("UTF8_STRING"); /* like STRING but encoding is UTF-8 */
318:                if (atom == 0) {
319:                    throw new IllegalStateException(
320:                            "Atom should be initialized");
321:                }
322:                checkWindow(window);
323:                byte[] bdata = null;
324:                try {
325:                    bdata = str.getBytes("UTF-8");
326:                } catch (java.io.UnsupportedEncodingException uee) {
327:                    uee.printStackTrace();
328:                }
329:                if (bdata != null) {
330:                    setAtomData(window, XA_UTF8_STRING.atom, bdata);
331:                }
332:            }
333:
334:            /**
335:             * Sets STRING/8 type property. Explicitly converts str to Latin-1 byte sequence.
336:             */
337:            public void setProperty8(long window, String str) {
338:                if (atom == 0) {
339:                    throw new IllegalStateException(
340:                            "Atom should be initialized");
341:                }
342:                checkWindow(window);
343:                byte[] bdata = null;
344:                try {
345:                    bdata = str.getBytes("ISO-8859-1");
346:                } catch (java.io.UnsupportedEncodingException uee) {
347:                    uee.printStackTrace();
348:                }
349:                if (bdata != null) {
350:                    setAtomData(window, XA_STRING, bdata);
351:                }
352:            }
353:
354:            /**  Gets the window property for the specified window
355:             * @param window window id to use
356:             * @param str value to set to.
357:             * @return string with the property.
358:             * @since 1.5
359:             */
360:            public String getProperty(long window) {
361:                if (atom == 0) {
362:                    throw new IllegalStateException(
363:                            "Atom should be initialized");
364:                }
365:                checkWindow(window);
366:                XToolkit.awtLock();
367:                try {
368:                    return XlibWrapper.GetProperty(display, window, atom);
369:                } finally {
370:                    XToolkit.awtUnlock();
371:                }
372:            }
373:
374:            /*
375:             * Auxiliary function that returns the value of 'property' of type
376:             * 'property_type' on window 'window'.  Format of the property must be 32.
377:             */
378:            public long get32Property(long window, long property_type) {
379:                if (atom == 0) {
380:                    throw new IllegalStateException(
381:                            "Atom should be initialized");
382:                }
383:                checkWindow(window);
384:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
385:                        this , 0, 1, false, property_type);
386:                try {
387:                    int status = getter.execute();
388:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
389:                        return 0;
390:                    }
391:                    if (getter.getActualType() != property_type
392:                            || getter.getActualFormat() != 32) {
393:                        return 0;
394:                    }
395:                    return Native.getCard32(getter.getData());
396:                } finally {
397:                    getter.dispose();
398:                }
399:            }
400:
401:            /**
402:             *  Returns value of property of type CARDINAL/32 of this window
403:             */
404:            public long getCard32Property(XBaseWindow window) {
405:                return get32Property(window.getWindow(), XA_CARDINAL);
406:            }
407:
408:            /**
409:             * Sets property of type CARDINAL on the window
410:             */
411:            public void setCard32Property(long window, long value) {
412:                if (atom == 0) {
413:                    throw new IllegalStateException(
414:                            "Atom should be initialized");
415:                }
416:                checkWindow(window);
417:                XToolkit.awtLock();
418:                try {
419:                    Native.putCard32(XlibWrapper.larg1, value);
420:                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
421:                            atom, XA_CARDINAL, 32, XlibWrapper.PropModeReplace,
422:                            XlibWrapper.larg1, 1);
423:                } finally {
424:                    XToolkit.awtUnlock();
425:                }
426:            }
427:
428:            /**
429:             * Sets property of type CARDINAL/32 on the window
430:             */
431:            public void setCard32Property(XBaseWindow window, long value) {
432:                setCard32Property(window.getWindow(), value);
433:            }
434:
435:            /**
436:             * Gets uninterpreted set of data from property and stores them in data_ptr.
437:             * Property type is the same as current atom, property is current atom.
438:             * Property format is 32. Property 'delete' is false.
439:             * Returns boolean if requested type, format, length match returned values
440:             * and returned data pointer is not null.
441:             */
442:            public boolean getAtomData(long window, long data_ptr, int length) {
443:                if (atom == 0) {
444:                    throw new IllegalStateException(
445:                            "Atom should be initialized");
446:                }
447:                checkWindow(window);
448:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
449:                        this , 0, (long) length, false, this );
450:                try {
451:                    int status = getter.execute();
452:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
453:                        return false;
454:                    }
455:                    if (getter.getActualType() != atom
456:                            || getter.getActualFormat() != 32
457:                            || getter.getNumberOfItems() != length) {
458:                        return false;
459:                    }
460:                    XlibWrapper.memcpy(data_ptr, getter.getData(), length
461:                            * getAtomSize());
462:                    return true;
463:                } finally {
464:                    getter.dispose();
465:                }
466:            }
467:
468:            /**
469:             * Gets uninterpreted set of data from property and stores them in data_ptr.
470:             * Property type is <code>type</code>, property is current atom.
471:             * Property format is 32. Property 'delete' is false.
472:             * Returns boolean if requested type, format, length match returned values
473:             * and returned data pointer is not null.
474:             */
475:            public boolean getAtomData(long window, long type, long data_ptr,
476:                    int length) {
477:                if (atom == 0) {
478:                    throw new IllegalStateException(
479:                            "Atom should be initialized");
480:                }
481:                checkWindow(window);
482:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
483:                        this , 0, (long) length, false, type);
484:                try {
485:                    int status = getter.execute();
486:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
487:                        return false;
488:                    }
489:                    if (getter.getActualType() != type
490:                            || getter.getActualFormat() != 32
491:                            || getter.getNumberOfItems() != length) {
492:                        return false;
493:                    }
494:                    XlibWrapper.memcpy(data_ptr, getter.getData(), length
495:                            * getAtomSize());
496:                    return true;
497:                } finally {
498:                    getter.dispose();
499:                }
500:            }
501:
502:            /**
503:             * Sets uninterpreted set of data into property from data_ptr.
504:             * Property type is the same as current atom, property is current atom.
505:             * Property format is 32. Mode is PropModeReplace. length is a number
506:             * of items pointer by data_ptr.
507:             */
508:            public void setAtomData(long window, long data_ptr, int length) {
509:                if (atom == 0) {
510:                    throw new IllegalStateException(
511:                            "Atom should be initialized");
512:                }
513:                checkWindow(window);
514:                XToolkit.awtLock();
515:                try {
516:                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
517:                            atom, atom, 32, XlibWrapper.PropModeReplace,
518:                            data_ptr, length);
519:                } finally {
520:                    XToolkit.awtUnlock();
521:                }
522:            }
523:
524:            /**
525:             * Sets uninterpreted set of data into property from data_ptr.
526:             * Property type is <code>type</code>, property is current atom.
527:             * Property format is 32. Mode is PropModeReplace. length is a number
528:             * of items pointer by data_ptr.
529:             */
530:            public void setAtomData(long window, long type, long data_ptr,
531:                    int length) {
532:                if (atom == 0) {
533:                    throw new IllegalStateException(
534:                            "Atom should be initialized");
535:                }
536:                checkWindow(window);
537:                XToolkit.awtLock();
538:                try {
539:                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
540:                            atom, type, 32, XlibWrapper.PropModeReplace,
541:                            data_ptr, length);
542:                } finally {
543:                    XToolkit.awtUnlock();
544:                }
545:            }
546:
547:            /**
548:             * Sets uninterpreted set of data into property from data_ptr.
549:             * Property type is <code>type</code>, property is current atom.
550:             * Property format is 8. Mode is PropModeReplace. length is a number
551:             * of bytes pointer by data_ptr.
552:             */
553:            public void setAtomData8(long window, long type, long data_ptr,
554:                    int length) {
555:                if (atom == 0) {
556:                    throw new IllegalStateException(
557:                            "Atom should be initialized");
558:                }
559:                checkWindow(window);
560:                XToolkit.awtLock();
561:                try {
562:                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
563:                            atom, type, 8, XlibWrapper.PropModeReplace,
564:                            data_ptr, length);
565:                } finally {
566:                    XToolkit.awtUnlock();
567:                }
568:            }
569:
570:            /**
571:             * Deletes property specified by this item on the window.
572:             */
573:            public void DeleteProperty(long window) {
574:                if (atom == 0) {
575:                    throw new IllegalStateException(
576:                            "Atom should be initialized");
577:                }
578:                checkWindow(window);
579:                XToolkit.awtLock();
580:                try {
581:                    XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window,
582:                            atom);
583:                } finally {
584:                    XToolkit.awtUnlock();
585:                }
586:            }
587:
588:            /**
589:             * Deletes property specified by this item on the window.
590:             */
591:            public void DeleteProperty(XBaseWindow window) {
592:                if (atom == 0) {
593:                    throw new IllegalStateException(
594:                            "Atom should be initialized");
595:                }
596:                checkWindow(window.getWindow());
597:                XToolkit.awtLock();
598:                try {
599:                    XlibWrapper.XDeleteProperty(XToolkit.getDisplay(), window
600:                            .getWindow(), atom);
601:                } finally {
602:                    XToolkit.awtUnlock();
603:                }
604:            }
605:
606:            public void setAtomData(long window, long property_type, byte[] data) {
607:                long bdata = Native.toData(data);
608:                try {
609:                    setAtomData8(window, property_type, bdata, data.length);
610:                } finally {
611:                    unsafe.freeMemory(bdata);
612:                }
613:            }
614:
615:            /*
616:             * Auxiliary function that returns the value of 'property' of type
617:             * 'property_type' on window 'window'.  Format of the property must be 8.
618:             */
619:            public byte[] getByteArrayProperty(long window, long property_type) {
620:                if (atom == 0) {
621:                    throw new IllegalStateException(
622:                            "Atom should be initialized");
623:                }
624:                checkWindow(window);
625:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
626:                        this , 0, 0xFFFF, false, property_type);
627:                try {
628:                    int status = getter.execute();
629:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
630:                        return null;
631:                    }
632:                    if (getter.getActualType() != property_type
633:                            || getter.getActualFormat() != 8) {
634:                        return null;
635:                    }
636:                    byte[] res = XlibWrapper.getStringBytes(getter.getData());
637:                    return res;
638:                } finally {
639:                    getter.dispose();
640:                }
641:            }
642:
643:            /**
644:             * Interns the XAtom
645:             */
646:            public void intern(boolean onlyIfExists) {
647:                XToolkit.awtLock();
648:                try {
649:                    atom = XlibWrapper.InternAtom(display, name,
650:                            onlyIfExists ? 1 : 0);
651:                } finally {
652:                    XToolkit.awtUnlock();
653:                }
654:                register();
655:            }
656:
657:            public boolean isInterned() {
658:                if (atom == 0) {
659:                    XToolkit.awtLock();
660:                    try {
661:                        atom = XlibWrapper.InternAtom(display, name, 1);
662:                    } finally {
663:                        XToolkit.awtUnlock();
664:                    }
665:                    if (atom == 0) {
666:                        return false;
667:                    } else {
668:                        register();
669:                        return true;
670:                    }
671:                } else {
672:                    return true;
673:                }
674:            }
675:
676:            /**
677:             * Initializes atom with name and display values
678:             */
679:            public void setValues(long display, String name, boolean autoIntern) {
680:                this .display = display;
681:                this .name = name;
682:                if (autoIntern) {
683:                    XToolkit.awtLock();
684:                    try {
685:                        atom = XlibWrapper.InternAtom(display, name, 0);
686:                    } finally {
687:                        XToolkit.awtUnlock();
688:                    }
689:                }
690:                register();
691:            }
692:
693:            public void setValues(long display, long atom) {
694:                this .display = display;
695:                this .atom = atom;
696:                register();
697:            }
698:
699:            public void setValues(long display, String name, long atom) {
700:                this .display = display;
701:                this .atom = atom;
702:                this .name = name;
703:                register();
704:            }
705:
706:            static int getAtomSize() {
707:                return Native.getLongSize();
708:            }
709:
710:            /*
711:             * Returns the value of property ATOM[]/32 as array of XAtom objects
712:             * @return array of atoms, array of length 0 if the atom list is empty
713:             *         or has different format
714:             */
715:            XAtom[] getAtomListProperty(long window) {
716:                if (atom == 0) {
717:                    throw new IllegalStateException(
718:                            "Atom should be initialized");
719:                }
720:                checkWindow(window);
721:
722:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
723:                        this , 0, 0xFFFF, false, XA_ATOM);
724:                try {
725:                    int status = getter.execute();
726:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
727:                        return emptyList;
728:                    }
729:                    if (getter.getActualType() != XA_ATOM
730:                            || getter.getActualFormat() != 32) {
731:                        return emptyList;
732:                    }
733:
734:                    int count = (int) getter.getNumberOfItems();
735:                    if (count == 0) {
736:                        return emptyList;
737:                    }
738:                    long list_atoms = getter.getData();
739:                    XAtom[] res = new XAtom[count];
740:                    for (int index = 0; index < count; index++) {
741:                        res[index] = XAtom.get(XAtom.getAtom(list_atoms + index
742:                                * getAtomSize()));
743:                    }
744:                    return res;
745:                } finally {
746:                    getter.dispose();
747:                }
748:            }
749:
750:            /*
751:             * Returns the value of property of type ATOM[]/32 as XAtomList
752:             * @return list of atoms, empty list if the atom list is empty
753:             *         or has different format
754:             */
755:            XAtomList getAtomListPropertyList(long window) {
756:                return new XAtomList(getAtomListProperty(window));
757:            }
758:
759:            XAtomList getAtomListPropertyList(XBaseWindow window) {
760:                return getAtomListPropertyList(window.getWindow());
761:            }
762:
763:            XAtom[] getAtomListProperty(XBaseWindow window) {
764:                return getAtomListProperty(window.getWindow());
765:            }
766:
767:            /**
768:             * Sets property value of type ATOM list to the list of atoms.
769:             */
770:            void setAtomListProperty(long window, XAtom[] atoms) {
771:                long data = toData(atoms);
772:                setAtomData(window, XAtom.XA_ATOM, data, atoms.length);
773:                unsafe.freeMemory(data);
774:            }
775:
776:            /**
777:             * Sets property value of type ATOM list to the list of atoms specified by XAtomList
778:             */
779:            void setAtomListProperty(long window, XAtomList atoms) {
780:                long data = atoms.getAtomsData();
781:                setAtomData(window, XAtom.XA_ATOM, data, atoms.size());
782:                unsafe.freeMemory(data);
783:            }
784:
785:            /**
786:             * Sets property value of type ATOM list to the list of atoms.
787:             */
788:            public void setAtomListProperty(XBaseWindow window, XAtom[] atoms) {
789:                setAtomListProperty(window.getWindow(), atoms);
790:            }
791:
792:            /**
793:             * Sets property value of type ATOM list to the list of atoms specified by XAtomList
794:             */
795:            public void setAtomListProperty(XBaseWindow window, XAtomList atoms) {
796:                setAtomListProperty(window.getWindow(), atoms);
797:            }
798:
799:            long getAtom() {
800:                return atom;
801:            }
802:
803:            void putAtom(long ptr) {
804:                Native.putLong(ptr, atom);
805:            }
806:
807:            static long getAtom(long ptr) {
808:                return Native.getLong(ptr);
809:            }
810:
811:            /**
812:             * Allocated memory to hold the list of native atom data and returns unsafe pointer to it
813:             * Caller should free the memory by himself.
814:             */
815:            static long toData(XAtom[] atoms) {
816:                long data = unsafe.allocateMemory(getAtomSize() * atoms.length);
817:                for (int i = 0; i < atoms.length; i++) {
818:                    if (atoms[i] != null) {
819:                        atoms[i].putAtom(data + i * getAtomSize());
820:                    }
821:                }
822:                return data;
823:            }
824:
825:            void checkWindow(long window) {
826:                if (window == 0) {
827:                    throw new IllegalArgumentException(
828:                            "Window must not be zero");
829:                }
830:            }
831:
832:            public boolean equals(Object o) {
833:                if (!(o instanceof  XAtom)) {
834:                    return false;
835:                }
836:                XAtom ot = (XAtom) o;
837:                return (atom == ot.atom && display == ot.display);
838:            }
839:
840:            public int hashCode() {
841:                return (int) ((atom ^ display) & 0xFFFFL);
842:            }
843:
844:            /**
845:             * Sets property on the <code>window</code> to the value <code>window_value</window>
846:             * Property is assumed to be of type WINDOW/32
847:             */
848:            public void setWindowProperty(long window, long window_value) {
849:                if (atom == 0) {
850:                    throw new IllegalStateException(
851:                            "Atom should be initialized");
852:                }
853:                checkWindow(window);
854:                XToolkit.awtLock();
855:                try {
856:                    Native.putWindow(XlibWrapper.larg1, window_value);
857:                    XlibWrapper.XChangeProperty(XToolkit.getDisplay(), window,
858:                            atom, XA_WINDOW, 32, XlibWrapper.PropModeReplace,
859:                            XlibWrapper.larg1, 1);
860:                } finally {
861:                    XToolkit.awtUnlock();
862:                }
863:            }
864:
865:            public void setWindowProperty(XBaseWindow window,
866:                    XBaseWindow window_value) {
867:                setWindowProperty(window.getWindow(), window_value.getWindow());
868:            }
869:
870:            /**
871:             * Gets property on the <code>window</code>. Property is assumed to be
872:             * of type WINDOW/32.
873:             */
874:            public long getWindowProperty(long window) {
875:                if (atom == 0) {
876:                    throw new IllegalStateException(
877:                            "Atom should be initialized");
878:                }
879:                checkWindow(window);
880:                WindowPropertyGetter getter = new WindowPropertyGetter(window,
881:                        this , 0, 1, false, XA_WINDOW);
882:                try {
883:                    int status = getter.execute();
884:                    if (status != XlibWrapper.Success || getter.getData() == 0) {
885:                        return 0;
886:                    }
887:                    if (getter.getActualType() != XA_WINDOW
888:                            || getter.getActualFormat() != 32) {
889:                        return 0;
890:                    }
891:                    return Native.getWindow(getter.getData());
892:                } finally {
893:                    getter.dispose();
894:                }
895:            }
896:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.