001: /*
002: * Copyright 2005 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: import java.util.*;
029:
030: /**
031: * Implements abstract X window property caching mechanism. The
032: * caching is performed using storeCache method, the cached data can
033: * be retrieved using getCacheEntry method.
034: *
035: * NOTE: current caching is disabled because of the big variate of
036: * uncovered access to properties/changes of properties. Once the
037: * access to properites is rewritten using general mechanisms, caching
038: * will be enabled.
039: */
040: public class XPropertyCache {
041:
042: static class PropertyCacheEntry {
043: private final int format;
044: private final int numberOfItems;
045: private final long bytesAfter;
046: private final long data;
047: private final int dataLength;
048:
049: public PropertyCacheEntry(int format, int numberOfItems,
050: long bytesAfter, long data, int dataLength) {
051: this .format = format;
052: this .numberOfItems = numberOfItems;
053: this .bytesAfter = bytesAfter;
054: this .data = XlibWrapper.unsafe.allocateMemory(dataLength);
055: this .dataLength = dataLength;
056: XlibWrapper.memcpy(this .data, data, dataLength);
057: }
058:
059: public int getFormat() {
060: return format;
061: }
062:
063: public int getNumberOfItems() {
064: return numberOfItems;
065: }
066:
067: public long getBytesAfter() {
068: return bytesAfter;
069: }
070:
071: public long getData() {
072: return data;
073: }
074:
075: public int getDataLength() {
076: return dataLength;
077: }
078: }
079:
080: private static Map<Long, Map<XAtom, PropertyCacheEntry>> windowToMap = new HashMap<Long, Map<XAtom, PropertyCacheEntry>>();
081:
082: public static boolean isCached(long window, XAtom property) {
083: Map<XAtom, PropertyCacheEntry> entryMap = windowToMap
084: .get(window);
085: if (entryMap != null) {
086: return entryMap.containsKey(property);
087: } else {
088: return false;
089: }
090: }
091:
092: public static PropertyCacheEntry getCacheEntry(long window,
093: XAtom property) {
094: Map<XAtom, PropertyCacheEntry> entryMap = windowToMap
095: .get(window);
096: if (entryMap != null) {
097: return entryMap.get(property);
098: } else {
099: return null;
100: }
101: }
102:
103: public static void storeCache(PropertyCacheEntry entry,
104: long window, XAtom property) {
105: Map<XAtom, PropertyCacheEntry> entryMap = windowToMap
106: .get(window);
107: if (entryMap == null) {
108: entryMap = new HashMap<XAtom, PropertyCacheEntry>();
109: windowToMap.put(window, entryMap);
110: }
111: entryMap.put(property, entry);
112: }
113:
114: public static void clearCache(long window) {
115: windowToMap.remove(window);
116: }
117:
118: public static void clearCache(long window, XAtom property) {
119: Map<XAtom, PropertyCacheEntry> entryMap = windowToMap
120: .get(window);
121: if (entryMap != null) {
122: entryMap.remove(property);
123: }
124: }
125:
126: public static boolean isCachingSupported() {
127: // Currently - unsupported
128: return false;
129: }
130: }
|