Index: other-projects/GlamED/trunk/src/org/honours/agents/GenerateThumbnails.java
===================================================================
--- other-projects/GlamED/trunk/src/org/honours/agents/GenerateThumbnails.java	(revision 26637)
+++ other-projects/GlamED/trunk/src/org/honours/agents/GenerateThumbnails.java	(revision 26637)
@@ -0,0 +1,140 @@
+package org.honours.agents;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.coobird.thumbnailator.Thumbnails;
+import net.coobird.thumbnailator.name.Rename;
+
+import org.expeditee.gui.Frame;
+import org.honours.CollectionSpace.CollectionSpace;
+import org.honours.collection.Collection;
+import org.honours.collection.CollectionItem;
+
+public class GenerateThumbnails {
+	private Collection _collection;
+	private String _newDirectory;
+	
+	private List<File> _imageFiles = new ArrayList<File>();
+	private List<File> _originalFiles = new ArrayList<File>();
+	
+	public Frame process(Frame frame) {
+		try{
+		//obtain collection the frame belongs to.
+		_collection = Collection.findCollection(frame);
+		
+		if(_collection == null)
+			return null;
+		
+		_newDirectory = "expeditee" + File.separator + "thumbnails-" + _collection.getName();
+		
+		new File(_newDirectory).mkdir();
+		
+		FileWriter fw = new FileWriter(_newDirectory + File.separator + "thumbnails.inf");
+		BufferedWriter bw = new BufferedWriter(fw);
+		
+		for(int i = 0; i < _collection.getItems().size(); i++){
+			CollectionItem ci = _collection.getItems().get(i);
+			String thumbnailFileName = getThumbnailFileName(ci.getAssociatedFile());
+			System.err.println("NEED TO FIND OUT thumbnail file name: " + thumbnailFileName + " *********");
+			moveImageToThumbnailDirectory(ci,thumbnailFileName,i+1,bw);
+		}
+
+		resize();
+		cleanThumbnailsFolder();
+		
+		bw.close();
+	}catch(Exception ex){
+		ex.printStackTrace();
+	}
+		
+		return null;
+	}
+	
+	
+	private void resize(){
+		try{
+			Thumbnails.of(new File(_newDirectory).listFiles())
+			/*.size(CollectionSpace._imageSize,CollectionSpace._imageSize)*/
+			.outputFormat("jpg")
+			.forceSize(CollectionSpace._imageSize,CollectionSpace._imageSize)
+			.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
+		}catch(Exception e){
+			e.printStackTrace();
+		}
+	}
+	
+	/**
+	 * Once thumbnails are generated, remove original larger images.
+	 */
+	private void cleanThumbnailsFolder(){
+		
+		for(int i = 0; i < _originalFiles.size(); i++){
+			
+		}
+	}
+	
+	private String getThumbnailFileName(String associatedFile){
+		
+		if(associatedFile.endsWith(".JPG") || associatedFile.endsWith(".jpg") ||
+				associatedFile.endsWith(".JPEG") || associatedFile.endsWith(".jpeg") ||
+				associatedFile.endsWith(".PNG") || associatedFile.endsWith(".png")){
+			return associatedFile;
+		}else{
+			return "images" + File.separator + "no-image-available.png";
+		}
+	}
+	
+	private void moveImageToThumbnailDirectory(CollectionItem ci, String thumbnail, int iter,BufferedWriter bw)
+	{
+		
+		File orig = new File(thumbnail);
+		//TODO: Add orig to a list of original files for removing later.
+		_originalFiles.add(orig);
+		
+		File replace = new File(_newDirectory + File.separator + _collection.getName() +
+				iter + ".png");
+		replace = new File(_newDirectory + File.separator + _collection.getName() + iter/* + ".png"*/);
+		if(!replace.exists()){
+			try{
+				replace.createNewFile();
+			}catch(IOException e){
+				e.printStackTrace();
+			}
+		}
+		
+		InputStream in = null;
+		OutputStream out = null;
+		
+		try{
+			in = new FileInputStream(orig);
+			out = new FileOutputStream(replace);
+			
+			//transfer bytes from in to out.
+			byte[] buf =  new byte[1024];
+			int len;
+			while((len = in.read(buf)) > 0){
+				out.write(buf,0,len);
+			}
+			in.close();
+			out.close();
+			
+			System.err.println("***** replace... " + replace.getPath());
+			
+			//bw.write(replace.getPath() + ","  + ci.getFrame().getName() + "\n");
+			bw.write(_newDirectory + File.separator + "thumbnail." + _collection.getName() + iter + ".JPG" + "," + ci.getFrame().getName() + "\n");
+			_imageFiles.add(replace);
+			
+		}catch(Exception e){
+			e.printStackTrace();
+		}
+	}
+}
