package gov.nih.nci.nbia.util;

import gov.nih.nci.ncia.search.ImageSearchResultEx;
import gov.nih.nci.ncia.search.ImageSearchResult;
import java.util.List;

public class SlideShowUtil {
	public static String getImageSeriesJavascriptEx(
			List<ImageSearchResultEx> thumbnailList) {
		StringBuffer js = new StringBuffer("[");
		for (int i = 0; i < thumbnailList.size(); i++) {
			ImageSearchResultEx image = thumbnailList.get(i);
			int frameSize = 0;
			if (image.getNameValuesPairs()!= null){
				String frameNumI = image.getNameValuesPairs().getValues()[0];
				frameSize = (frameNumI==null) ? 0 : Integer.parseInt(frameNumI);		
			}

			if (frameSize <= 1) {
				String tnURL = "'"+image.getThumbnailURL()+"'";
				js.append(tnURL);
			}
			else { //frameSize > 1
				for (int j = 0; j < frameSize; ++j) {

					js.append("'" + 
							  image.getThumbnailURL() + 
							  "-" + 
							  j +
							  "'");
					if (j != frameSize - 1) {
						js.append(',');
					}
				}			
			}
			if (i != thumbnailList.size() - 1) {
				js.append(',');
			}
		}
		js.append(']');
		//System.out.println("java script:" + js.toString());
		return js.toString();
	}
	
	public static String getImageSeriesJavascriptEx(
			List<ImageSearchResultEx> thumbnailList, int i) {
		ImageSearchResultEx image = thumbnailList.get(i - 1);
		int frameSize = 0;
		StringBuffer js = new StringBuffer("[");
		
		if (image.getNameValuesPairs() != null) {
			String frameNumI = image.getNameValuesPairs().getValues()[0];
			frameSize = (frameNumI == null) ? 0 : Integer.parseInt(frameNumI);
System.out.println("!!!!!SOP="+image.getSopInstanceUid() +" Frame #="+frameSize);			
		}

		if (frameSize <= 1) {
			String tnURL = "'" + image.getThumbnailURL() + "'";
			js.append(tnURL);
		} else { // frameSize > 1
			for (int j = 0; j < frameSize; ++j) {

				js.append("'" + image.getThumbnailURL() + "-" + j + "'");
				if (j != frameSize - 1) {
					js.append(',');
				}
			}
		}

		js.append(']');
		// System.out.println("java script:" + js.toString());
		return js.toString();
	}
	
	public static String getImageSeriesJavascript(List<ImageSearchResult> thumbnailList) {
		StringBuffer js = new StringBuffer("[");
		for(int i=0;i<thumbnailList.size();i++) {
			ImageSearchResult image = thumbnailList.get(i);
			js.append("'"+image.getThumbnailURL()+"'");
			if(i!=thumbnailList.size()-1) {
				js.append(',');
			}
		}
		js.append(']');
		return js.toString();
	}
}

@@ -1350,20 +1350,16 @@
 st.get(i
- - 1
 );%0D%0A%09%09in
@@ -1610,94 +1610,8 @@
 );%0D%0A
-System.out.println(%22!!!!!SOP=%22+image.getSopInstanceUid() +%22 Frame #=%22+frameSize);%09%09%09%0D%0A
 %09%09%7D%0D

Add feature to support US multi-frame.