001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.lib.collab.util;
043:
044: import java.awt.*;
045: import java.util.*;
046: import javax.swing.*;
047: import java.net.*;
048:
049: /**
050: *
051: * Image Dictionary class for hanling image reloading
052: * Any images loaded into the NetLert client using the imageDictionary class will
053: * be reloaded each time they are rendered (actually in intervals of half a minute)
054: *
055: */
056: public class ImageDictionary extends Dictionary {
057: private Hashtable dic = new Hashtable(8);
058: private Hashtable imageList = new Hashtable(8);
059:
060: public ImageDictionary() {
061: }
062:
063: /**
064: *
065: * @param
066: */
067: final public Enumeration elements() {
068: return dic.elements();
069: }
070:
071: /**
072: *
073: * @param
074: */
075: final private Image getImage(URL u) {
076: return Toolkit.getDefaultToolkit().createImage(u);
077: }
078:
079: /**
080: * Returns the actual value stored in hashtable (this may not be an image)
081: * @param Object key
082: */
083: final public Object getObject(Object key) {
084: return dic.get(key);
085: }
086:
087: /**
088: * Returns an image from the dictionary
089: * TODO for now - netlert specific -- assumes key is a URL
090: * TODo Image is stored twice in memory - stored here and in actual netlert msg
091: * @param Object key
092: */
093: final public Object get(Object key) {
094: String tmp = key.toString();
095: Enumeration ee = dic.keys();
096: while (ee.hasMoreElements()) {
097: Object k = ee.nextElement();
098: //System.out.println("COMPARE " + key.toString() + " WITH " + tmp);
099: if (((URL) k).toString().equalsIgnoreCase(tmp)) {
100: //System.out.println("GOT MATCH " + tmp);
101: byte[] b = (byte[]) dic.get(k);
102: ImageIcon ico = new ImageIcon(b);
103: return ico.getImage();
104: }
105: }
106: return null;
107:
108: }
109:
110: /*final public Object get(Object key){
111: if(key instanceof URL){
112: Image i = getImage((URL)key);
113: String tmp = (String)imageList.get(((URL)key).toString());
114: if(tmp != null){
115: long last_flush = Long.parseLong(tmp);
116: last_flush = System.currentTimeMillis() - last_flush;
117: //System.out.println("LAST_FLUSH " + last_flush);
118: if(last_flush > 30000){
119: i.flush();
120: imageList.put(((URL)key).toString(), Long.toString(System.currentTimeMillis()));
121: }
122: } else {
123: imageList.put(((URL)key).toString(), Long.toString(System.currentTimeMillis()));
124: }
125:
126: if(i != null){
127: ImageIcon icon = new ImageIcon(i);
128: return icon.getImage();
129: } else {
130: return null;
131: }
132: } else {
133: Image i = (Image)dic.get(key);
134: if(i != null){
135: ImageIcon icon = new ImageIcon(i);
136: return icon.getImage();
137: } else {
138: return null;
139: }
140: }
141: }*/
142:
143: final public boolean isEmpty() {
144: if (dic.size() == 0)
145: return true;
146: return false;
147: }
148:
149: final public Enumeration keys() {
150: return dic.keys();
151: }
152:
153: final public Object put(Object key, Object value) {
154: Object prev = null;
155: if (dic.containsKey(key)) {
156: prev = dic.get(key);
157: }
158: dic.put(key, value);
159: return prev;
160: }
161:
162: final public Object remove(Object key) {
163: Object prev = null;
164: if (dic.containsKey(key)) {
165: prev = dic.get(key);
166: dic.remove(key);
167: }
168:
169: if (imageList.contains(key)) {
170: imageList.remove(key);
171: }
172:
173: return prev;
174: }
175:
176: final public int size() {
177: return dic.size();
178: }
179: }
|