KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > viewsupport > ImageDisposer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.viewsupport;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.swt.events.DisposeEvent;
16 import org.eclipse.swt.events.DisposeListener;
17 import org.eclipse.swt.graphics.Image;
18
19
20 /**
21  * Helper class to manage images that should be disposed when a control is disposed
22  * contol.addWidgetListener(new ImageDisposer(myImage));
23  */

24 public class ImageDisposer implements DisposeListener {
25     
26     private Image[] fImages;
27         
28     public ImageDisposer(Image image) {
29         this(new Image[] { image });
30     }
31     
32     public ImageDisposer(Image[] images) {
33         Assert.isNotNull(images);
34         fImages= images;
35     }
36     
37     /*
38      * @see WidgetListener#widgetDisposed
39      */

40     public void widgetDisposed(DisposeEvent e) {
41         if (fImages != null) {
42             for (int i= 0; i < fImages.length; i++) {
43                 fImages[i].dispose();
44             }
45         }
46     }
47 }
48
Popular Tags