1 14 package org.wings; 15 16 import org.wings.resource.FileResource; 17 import org.wings.util.ImageInfo; 18 19 import java.io.File ; 20 import java.io.FileInputStream ; 21 import java.io.FileNotFoundException ; 22 import java.io.IOException ; 23 24 31 public class SFileIcon extends FileResource implements SIcon { 32 33 36 private int width = -1; 37 38 41 private int height = -1; 42 43 46 private String title = null; 47 48 49 54 public SFileIcon(String fileName) throws FileNotFoundException { 55 this(new File (fileName)); 56 } 57 58 69 public SFileIcon(File file, String extension, String mimetype) throws FileNotFoundException { 70 super(file, extension, mimetype); 71 72 ImageInfo tImageInfo = new ImageInfo(); 73 FileInputStream tImageInput = new FileInputStream (file); 74 tImageInfo.setInput(tImageInput); 75 76 if (tImageInfo.check()) { 77 if (this.mimeType == null || this.mimeType.length() == 0) { 79 this.mimeType = tImageInfo.getMimeType(); 80 } else if (this.extension == null || this.extension.length() == 0) { 81 this.extension = tImageInfo.getFormatName(); 82 } 83 84 width = tImageInfo.getWidth(); 85 height = tImageInfo.getHeight(); 86 } 87 88 try { 89 tImageInput.close(); 90 } catch (IOException ex) { 91 } 93 } 94 95 public SFileIcon(File file) throws FileNotFoundException { 96 this(file, null, null); 97 } 98 99 public int getIconWidth() { 100 return width; 101 } 102 103 public int getIconHeight() { 104 return height; 105 } 106 107 public void setIconWidth(int width) { 108 this.width = width; 109 } 110 111 public void setIconHeight(int height) { 112 this.height = height; 113 } 114 115 public String getIconTitle() { 116 return (title!=null) ? title : ""; 117 } 118 119 public void setIconTitle(String title) { 120 this.title = title; 121 } 122 } 123 124 125 | Popular Tags |