1 14 package org.wings; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.wings.resource.ClasspathResource; 19 import org.wings.util.ImageInfo; 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.IOException ; 23 24 32 33 42 public class SResourceIcon extends ClasspathResource implements SIcon { 43 44 private final transient static Log log = LogFactory.getLog(SResourceIcon.class); 45 46 49 private int width = -1; 50 51 54 private int height = -1; 55 56 59 private String title = null; 60 61 62 public SResourceIcon(String resourceFileName) { 63 this(SResourceIcon.class.getClassLoader(), resourceFileName); 64 } 65 66 public SResourceIcon(ClassLoader classLoader, String resourceFileName) { 67 super(classLoader, resourceFileName); 68 69 try { 70 bufferResource(); 71 } catch (Throwable e) { 72 log.fatal("Can not buffer resource " + resourceFileName); 73 } 74 75 if (buffer != null && buffer.isValid()) { 76 ImageInfo tImageInfo = new ImageInfo(); 77 ByteArrayInputStream tImageInput = new ByteArrayInputStream (buffer.getBytes()); 78 tImageInfo.setInput(tImageInput); 79 80 if (tImageInfo.check()) { 81 extension = tImageInfo.getFormatName(); 82 mimeType = tImageInfo.getMimeType(); 83 width = tImageInfo.getWidth(); 84 height = tImageInfo.getHeight(); 85 } 86 87 try { 88 tImageInput.close(); 89 } catch (IOException ex) { 90 } 92 } 93 } 94 95 public int getIconWidth() { 96 return width; 97 } 98 99 public int getIconHeight() { 100 return height; 101 } 102 103 public void setIconWidth(int width) { 104 this.width = width; 105 } 106 107 public void setIconHeight(int height) { 108 this.height = height; 109 } 110 111 public String getIconTitle() { 112 return (title!=null) ? title : ""; 113 } 114 115 public void setIconTitle(String title) { 116 this.title = title; 117 } 118 } 119 120 121 | Popular Tags |