1 19 package org.lucane.applications.slideshow; 20 21 import java.io.File ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Comparator ; 25 import java.util.List ; 26 27 import javax.imageio.ImageIO ; 28 29 import org.lucane.applications.slideshow.gui.PreloadDialog; 30 import org.lucane.client.widgets.DialogBox; 31 32 public class FileUtils 33 { 34 public static Object [] preloadImages(SlideShow plugin, List files, PreloadDialog dialog) 35 { 36 Object [] objects = new Object [files.size()]; 37 for(int i=0;i<objects.length;i++) 38 { 39 File file = (File )files.get(i); 40 dialog.setValue(i, file.getName()); 41 42 try { 43 objects[i] = ImageIO.read(file); 44 } catch(Exception e) { 45 String msg = plugin.tr("err.unableToLoadImage").replaceAll("%1", file.getName()); 46 DialogBox.error(msg + " " + e); 47 } 48 } 49 50 return objects; 51 } 52 53 public static List sortFiles(File [] files) 54 { 55 ArrayList list = new ArrayList (files.length); 56 for(int i=0;i<files.length;i++) 57 list.add(files[i]); 58 59 Collections.sort(list, new Comparator () { 60 public int compare(Object o1, Object o2) { 61 String s1 = ((File )o1).getName(); 62 String s2 = ((File )o2).getName(); 63 64 if(s1.length() < s2.length()) 65 return -1; 66 else if(s1.length() > s2.length()) 67 return 1; 68 else 69 return s1.compareTo(s2); 70 } 71 }); 72 73 return list; 74 } 75 } | Popular Tags |