1 11 package org.eclipse.jface.resource; 12 13 import java.io.BufferedInputStream ; 14 import java.io.IOException ; 15 import java.io.InputStream ; 16 import java.net.URL ; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.SWTException; 20 import org.eclipse.swt.graphics.ImageData; 21 22 27 class URLImageDescriptor extends ImageDescriptor { 28 private URL url; 29 30 34 URLImageDescriptor(URL url) { 35 this.url = url; 36 } 37 38 41 public boolean equals(Object o) { 42 if (!(o instanceof URLImageDescriptor)) { 43 return false; 44 } 45 return ((URLImageDescriptor) o).url.equals(this.url); 46 } 47 48 52 public ImageData getImageData() { 53 ImageData result = null; 54 InputStream in = getStream(); 55 if (in != null) { 56 try { 57 result = new ImageData(in); 58 } catch (SWTException e) { 59 if (e.code != SWT.ERROR_INVALID_IMAGE) { 60 throw e; 61 } 63 } finally { 64 try { 65 in.close(); 66 } catch (IOException e) { 67 } 70 } 71 } 72 return result; 73 } 74 75 80 protected InputStream getStream() { 81 try { 82 return new BufferedInputStream (url.openStream()); 83 } catch (IOException e) { 84 return null; 85 } 86 } 87 88 91 public int hashCode() { 92 return url.hashCode(); 93 } 94 95 98 102 public String toString() { 103 return "URLImageDescriptor(" + url + ")"; } 105 } 106 | Popular Tags |