FileUtils.java :  » Groupware » lucane » org » lucane » applications » slideshow » Java Open Source

Java Open Source » Groupware » lucane 
lucane » org » lucane » applications » slideshow » FileUtils.java
/*
 * Lucane - a collaborative platform
 * Copyright (C) 2004  Vincent Fiack <vfiack@mail15.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.lucane.applications.slideshow;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.imageio.ImageIO;

import org.lucane.applications.slideshow.gui.PreloadDialog;
import org.lucane.client.widgets.DialogBox;

public class FileUtils
{
  public static Object[] preloadImages(SlideShow plugin, List files, PreloadDialog dialog)
  {
    Object[] objects = new Object[files.size()];
    for(int i=0;i<objects.length;i++)
    {
      File file = (File)files.get(i);
      dialog.setValue(i, file.getName());
      
      try {      
        objects[i] = ImageIO.read(file);
      } catch(Exception e) {
        String msg = plugin.tr("err.unableToLoadImage").replaceAll("%1", file.getName());
        DialogBox.error(msg + " " + e);
      }
    }
    
    return objects;
  }
  
  public static List sortFiles(File[] files)
  {
    ArrayList list = new ArrayList(files.length);
    for(int i=0;i<files.length;i++)
      list.add(files[i]);
    
    Collections.sort(list, new Comparator() {
      public int compare(Object o1, Object o2) {
        String s1 = ((File)o1).getName();
        String s2 = ((File)o2).getName();
        
        if(s1.length() < s2.length())
          return -1;
        else if(s1.length() > s2.length())
          return 1;
        else
          return s1.compareTo(s2);          
      }
    });
    
    return list;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.