1 2 package de.jwi.jgallery; 3 4 25 26 import imageinfo.ImageInfo; 27 28 import java.io.FileNotFoundException ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.Serializable ; 32 import java.text.DateFormat ; 33 import java.util.Date ; 34 import java.util.List ; 35 36 39 public class Image implements Serializable 40 { 41 42 private boolean isRepresentsSubdirectory = false; 43 44 private String name; 45 46 private Folder folder; 47 48 49 private String fileSize = ""; 50 51 private String thumbWidth; 52 53 private String thumbHeight; 54 55 private String fileDate = ""; 56 57 private long lastModified; 58 59 private String imageWidth; 61 private String imageHeight; 63 private String comment; 64 65 private EXIFInfo exif; 66 67 private ThumbNailInfo thumbNailInfo; 68 69 Image(String name, boolean isRepresentsSubdirectory, Folder folder, 70 IImageAccessor imageAccessor, ThumbNailInfo thumbNailInfo) 71 throws GalleryException 72 { 73 this.name = name; 74 this.folder = folder; 75 this.isRepresentsSubdirectory = isRepresentsSubdirectory; 76 this.thumbNailInfo = thumbNailInfo; 77 78 lastModified = imageAccessor.getLastModified(); 79 80 fileDate = DateFormat.getDateInstance().format(new Date (lastModified)); 81 82 InputStream imageInputStream = null; 83 InputStream thumbInputStream = null; 84 85 if (!isRepresentsSubdirectory) 86 { 87 try 88 { 89 91 imageInputStream = imageAccessor.getImageInputStream(); 92 ImageInfo ii = new ImageInfo(); 93 ii.setInput(imageInputStream); 94 if (!ii.check()) 95 { 96 throw new GalleryException( 97 "Not a supported image file format."); 98 } 99 100 imageWidth = Integer.toString(ii.getWidth()); 101 imageHeight = Integer.toString(ii.getHeight()); 102 103 fileSize = Long.toString(imageAccessor.getLength()); 104 105 107 thumbInputStream = imageAccessor.getThumbInputStream(); 108 109 ii = new ImageInfo(); 110 ii.setInput(thumbInputStream); 111 if (!ii.check()) 112 { 113 throw new GalleryException( 114 "Not a supported image file format."); 115 } 116 117 thumbWidth = Integer.toString(ii.getWidth()); 118 thumbHeight = Integer.toString(ii.getHeight()); 119 120 121 } 122 catch (FileNotFoundException e) 123 { 124 throw new GalleryException(e.getMessage()); 125 } 126 finally 127 { 128 if (imageInputStream != null) 129 { 130 try 131 { 132 imageInputStream.close(); 133 } 134 catch (IOException e) 135 { 136 } 138 } 139 if (thumbInputStream != null) 140 { 141 try 142 { 143 thumbInputStream.close(); 144 } 145 catch (IOException e) 146 { 147 } 149 } 150 } 151 152 153 try 154 { 155 imageInputStream = imageAccessor.getImageInputStream(); 156 } 157 catch (FileNotFoundException e) 158 { 159 throw new GalleryException(e.getMessage()); 160 } 161 162 try 163 { 164 exif = new EXIFInfo(imageInputStream); 165 } 166 catch (GalleryException e1) 167 { 168 exif = null; 169 } 170 } 171 172 } 173 174 public String toString() 175 { 176 return name; 177 } 178 179 public String getName() 180 { 181 return name; 182 } 183 184 private String labelfile; 185 186 public String getLabelfile() 187 throws FileNotFoundException , IOException , GalleryException 188 { 189 if (null == labelfile) 190 { 191 labelfile = folder.getFileContent(getLabel() + ".txt"); 192 } 193 194 return labelfile; 195 } 196 197 public String getLabel() 198 { 199 int p = name.indexOf('.'); 200 201 return (Folder.isJPEGExtension(name) & (p > -1)) 202 ? name.substring(0, p) 203 : name; 204 } 205 206 public String getFileName() 207 { 208 return name; 209 } 210 211 public String getCloseupPath() 212 { 213 String n; 214 if (isRepresentsSubdirectory) 215 { 216 n = name + "/index." + folder.getUrlExtention(); 217 } 218 else 219 { 220 n = name.substring(0, name.indexOf('.')) + "." 221 + folder.getUrlExtention(); 222 } 223 return folder.getHTMLBase() + n; 224 } 225 226 public String getIconPath() 227 { 228 return isRepresentsSubdirectory ? thumbNailInfo.getThumbPath() : ""; 229 } 230 231 public String getImagePath() 232 { 233 return folder.getImageBasePath() + "/" + name; 234 } 235 236 public String getThumbHeight() 237 { 238 return isRepresentsSubdirectory 239 ? thumbNailInfo.getThumbHeight() 240 : thumbHeight; 241 } 242 243 public String getThumbPath() 244 { 245 return isRepresentsSubdirectory ? thumbNailInfo.getThumbPath() : folder.getThumbsPath() + "/" + name; 246 247 } 249 250 public String getThumbBound() 251 { 252 int h = Integer.parseInt(isRepresentsSubdirectory ? thumbNailInfo 253 .getThumbHeight() : thumbHeight); 254 int w = Integer.parseInt(isRepresentsSubdirectory ? thumbNailInfo 255 .getThumbWidth() : thumbWidth); 256 257 return Integer.toString(Math.max(h, w)); 258 } 259 260 261 public List getNeighbourImages() throws GalleryException 262 { 263 return folder.getNeighbourImages(this); 264 } 265 266 public String getThumbWidth() 267 { 268 return isRepresentsSubdirectory 269 ? thumbNailInfo.getThumbWidth() 270 : thumbWidth; 271 } 272 273 278 public String getOriginalPath() 279 { 280 return ""; 281 } 282 283 public String getImageHeight() 284 { 285 return imageHeight; 286 } 287 288 public String getImageWidth() 289 { 290 return imageWidth; 291 } 292 293 public Folder getFolder() 294 { 295 return folder; 296 } 297 298 public void setFolder(Folder folder) 299 { 300 this.folder = folder; 301 } 302 303 304 public void setName(String name) 305 { 306 this.name = name; 307 } 308 309 public String getFileDate() 310 { 311 return fileDate; 312 } 313 314 public EXIFInfo getExif() 315 { 316 return exif; 317 } 318 319 public String getComment() 320 { 321 return comment; 322 } 323 324 public void setComment(String comment) 325 { 326 this.comment = comment; 327 } 328 329 public String getFileSize() 330 { 331 return fileSize; 332 } 333 334 public long getLastModified() 335 { 336 return lastModified; 337 } 338 339 public String getCounter() 340 { 341 String rc = folder.getImageCounter(name); 342 343 return rc; 344 } 345 346 public boolean getRepresentsSubdirectory() 347 { 348 return isRepresentsSubdirectory; 349 } 350 351 } | Popular Tags |