View Javadoc
1 /* 2 * Created on Oct 12, 2003 3 * Copyright (c) 2003. All rights reserved. 4 */ 5 package portaview.model; 6 7 import java.io.File; 8 import java.util.Hashtable; 9 import java.util.Iterator; 10 import java.util.List; 11 import java.util.Vector; 12 13 /*** 14 * Represents the album in PortaView. An album is a folder that contain 15 * images on disk. This object is not used in the MVC model but rather 16 * serves as a class to retrieve photos on disk. 17 * 18 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a> 19 * @version $Id: Album.java,v 1.5 2003/12/10 06:18:57 wlee Exp $ 20 */ 21 public class Album extends NameModel implements XmlRpcType 22 { 23 public static final String XT_NAME = "name"; 24 public static final String XT_ICON = "icon"; 25 public static final String XT_PHOTOS = "photos"; 26 public static final int ICON_W = 48; 27 public static final int ICON_H = 48; 28 29 File directory = null; 30 byte[] icon = null; 31 32 /*** 33 * Creates an album from a directory. 34 * @param dir directory for the album. 35 */ 36 public Album(File dir) 37 { 38 super(dir.getName()); 39 this.directory = dir; 40 Photo p = getPhoto(0); 41 if (p != null) 42 { 43 icon = p.getJpegIcon(ICON_W, ICON_H); 44 } 45 } 46 47 /*** 48 * @return the directory for this album. 49 */ 50 public File getDirectory() 51 { 52 return directory; 53 } 54 55 /*** 56 * Sets the directory. 57 * @param directory album directory 58 */ 59 public void setDirectory(File directory) 60 { 61 this.directory = directory; 62 } 63 64 /*** 65 * Lists out the photos inside this album. 66 * @return the list of File that represents the photos in this album. 67 */ 68 public List listPhotos() 69 { 70 if (directory == null) return new Vector(); 71 File[] listing = directory.listFiles(); 72 return getJpegs(listing); 73 } 74 75 /*** 76 * Returns the photo with the show name and the sequence id. 77 * @param seq the sequence of photo based on the directory's sorting order. 78 * @return the photo. 79 */ 80 public Photo getPhoto(int seq) 81 { 82 if (directory == null) 83 return null; 84 List jpegs = listPhotos(); 85 File f = null; 86 try 87 { 88 return new Photo((File) jpegs.get(seq)); 89 } 90 catch (Exception e) 91 { 92 } 93 return null; 94 95 } 96 97 /*** 98 * Returns a photo given the name. 99 * @param name name of photo. 100 * @return the Photo. 101 */ 102 public Photo getPhoto(String name) 103 { 104 if (directory == null) 105 return null; 106 File jpeg = new File(directory, name + ".jpg"); 107 File f = null; 108 try 109 { 110 return new Photo(jpeg); 111 } 112 catch (Exception e) 113 { 114 } 115 return null; 116 } 117 118 /*** 119 * Returns the list of jpeg bytes according to the file list. 120 * 121 * @param listing an array of files. 122 * @return List of file with an jpg or JPG extension. 123 */ 124 private List getJpegs(File[] listing) 125 { 126 List l = new Vector(); 127 for (int i = 0; i < listing.length; i++) 128 { 129 if (listing[i].getName().endsWith(".jpg") 130 || listing[i].getName().endsWith(".JPG")) 131 { 132 l.add(listing[i]); 133 } 134 135 } 136 return l; 137 } 138 139 /*** 140 * Returns a Hashtable of name = the name of album and 141 * icon = byte[] of the album image. 142 * @see portaview.model.XmlRpcType#toXmlRpcType() 143 */ 144 public Object toXmlRpcType() 145 { 146 Hashtable rtn = new Hashtable(); 147 rtn.put(XT_NAME, getName()); 148 rtn.put(XT_ICON, this.icon); 149 List flist = listPhotos(); 150 Vector photos = new Vector(); 151 for (Iterator i = flist.iterator(); i.hasNext();) 152 { 153 File f = (File)i.next(); 154 photos.add(f.getName()); 155 } 156 rtn.put(XT_PHOTOS, photos); 157 return rtn; 158 } 159 }

This page was automatically generated by Maven