View Javadoc
1 /* 2 * Created on Sep 20, 2003 3 * Copyright (c) 2003 William Lee. All rights reserved. 4 */ 5 package portaview.model; 6 7 import java.io.File; 8 import java.io.FileInputStream; 9 10 import portaview.util.ImageUtils; 11 import portaview.util.StreamUtils; 12 13 /*** 14 * Represents a photo on disk. Note that this is not the model used in the 15 * PortaView manager. Provides an abstarction to access the pictures on disk. 16 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a> 17 * @version $Id: Photo.java,v 1.3 2003/12/10 06:18:57 wlee Exp $ 18 */ 19 public class Photo 20 { 21 private String caption; 22 private File file; 23 24 public Photo() 25 { 26 this(null, null); 27 } 28 29 /*** 30 * Constructs a photo with caption. 31 * @param f file that represents the photo 32 * @param caption caption for the photo 33 */ 34 public Photo(File f, String caption) 35 { 36 this.file = f; 37 this.caption = caption; 38 } 39 40 /*** 41 * Constructs a photo. 42 * @param f file that represents the photo 43 */ 44 public Photo(File f) 45 { 46 this.file = f; 47 this.caption = f.getName(); 48 } 49 50 /*** 51 * @return the caption of this photo. 52 */ 53 public String getCaption() 54 { 55 return caption; 56 } 57 58 /*** 59 * Sets the caption. 60 * @param caption caption to set. 61 */ 62 public void setCaption(String caption) 63 { 64 this.caption = caption; 65 } 66 67 /*** 68 * @return the file associated with this Photo. 69 */ 70 public File getFile() 71 { 72 return file; 73 } 74 75 /*** 76 * Sets the file associated with this Photo. 77 * @param file file to set. 78 */ 79 public void setFile(File file) 80 { 81 this.file = file; 82 } 83 84 /*** 85 * @return the jpeg encoding of this photo. 86 */ 87 public byte[] getJpeg() 88 { 89 if (this.file == null) return null; 90 try 91 { 92 return StreamUtils.getBytesFromStream(new FileInputStream(file)); 93 } 94 catch (Exception e) 95 { 96 e.printStackTrace(); 97 return null; 98 } 99 } 100 101 /*** 102 * @return the jpeg encoding of this icon. 103 */ 104 public byte[] getJpegIcon(int width, int height) 105 { 106 if (this.file == null) return null; 107 try 108 { 109 return ImageUtils.getScaledImage(file, width, height); 110 } 111 catch (Exception e) 112 { 113 e.printStackTrace(); 114 return null; 115 } 116 } 117 118 }

This page was automatically generated by Maven