01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.util;
11:
12: import java.util.Hashtable;
13: import java.util.Iterator;
14: import java.util.Map;
15:
16: import org.eclipse.swt.graphics.Color;
17: import org.eclipse.swt.graphics.Font;
18: import org.eclipse.swt.graphics.Image;
19:
20: /**
21: * SWTResourceUtil is a class that holds onto Colors, Fonts and Images and
22: * disposes them on shutdown.
23: */
24: public class SWTResourceUtil {
25:
26: /**
27: * The cache of images that have been dispensed by this provider. Maps
28: * ImageDescriptor->Image. Caches are all static to avoid creating extra
29: * system resources for very common images, font and colors.
30: */
31: private static Map imageTable = new Hashtable(40);
32:
33: /**
34: * The cache of colors that have been dispensed by this provider. Maps
35: * RGB->Color.
36: */
37: private static Map colorTable = new Hashtable(7);
38:
39: /**
40: * The cache of fonts that have been dispensed by this provider. Maps
41: * FontData->Font.
42: */
43: private static Map fontTable = new Hashtable(7);
44:
45: /**
46: * Disposes of all allocated images, colors and fonts when shutting down the
47: * plug-in.
48: */
49: public static final void shutdown() {
50: if (imageTable != null) {
51: for (Iterator i = imageTable.values().iterator(); i
52: .hasNext();) {
53: ((Image) i.next()).dispose();
54: }
55: imageTable = null;
56: }
57: if (colorTable != null) {
58: for (Iterator i = colorTable.values().iterator(); i
59: .hasNext();) {
60: ((Color) i.next()).dispose();
61: }
62: colorTable = null;
63: }
64: if (fontTable != null) {
65: for (Iterator i = fontTable.values().iterator(); i
66: .hasNext();) {
67: ((Font) i.next()).dispose();
68: }
69: fontTable = null;
70: }
71: }
72:
73: /**
74: * Get the Map of RGBs to Colors.
75: * @return Returns the colorTable.
76: */
77: public static Map getColorTable() {
78: return colorTable;
79: }
80:
81: /**
82: * Return the map of FontDatas to Fonts.
83: * @return Returns the fontTable.
84: */
85: public static Map getFontTable() {
86: return fontTable;
87: }
88:
89: /**
90: * Return the map of ImageDescriptors to Images.
91: * @return Returns the imageTable.
92: */
93: public static Map getImageTable() {
94: return imageTable;
95: }
96: }
|