1 package de.jwi.jgallery; 2 3 24 25 26 import java.util.Comparator ; 27 28 29 33 public class ImageComparator implements Comparator 34 { 35 public static final int SORTNONE = 0; 36 public static final int SORTBYNAME = 1; 37 public static final int SORTBYFILEDATE = 2; 38 public static final int SORTBYEXIFDATE = 3; 39 40 private int mode; 41 42 ImageComparator(int mode) throws GalleryException 43 { 44 this.mode = mode; 45 46 if ((mode != SORTBYFILEDATE) && (mode != SORTBYNAME) && (mode != SORTBYEXIFDATE)) 47 { 48 throw new GalleryException("illegal sorting mode"); 49 } 50 } 51 52 public int compare(Object o1, 53 Object o2) 54 { 55 int rc = 0; 56 57 Image i1 = (Image)o1; 58 Image i2 = (Image)o2; 59 if (SORTBYFILEDATE == mode) 60 { 61 rc = (int) (i1.getLastModified() - i2.getLastModified()) ; 62 } 63 else if (SORTBYEXIFDATE == mode) 64 { 65 EXIFInfo e1 = i1.getExif(); 66 EXIFInfo e2 = i2.getExif(); 67 if ((null==e1) || (null==e2)) 68 { 69 rc = 0; 70 } 71 else 72 { 73 String s1 = e1.getOriginalDate(); 74 String s2 = e2.getOriginalDate(); 75 76 if ((null==s1) || (null==s2)) 77 { 78 rc = 0; 79 } 80 else 81 { 82 rc = s1.compareTo(s2); 83 } 84 } 85 } 86 else if (SORTBYNAME == mode) 87 { 88 rc= i1.getName().compareToIgnoreCase(i2.getName()); 89 } 90 return rc; 91 } 92 } 93 | Popular Tags |