/**
Khalid Alharbi
*/
package org.sikuli.slides.sikuli;

import java.util.List;

import org.sikuli.api.DesktopScreenRegion;
import org.sikuli.api.ImageTarget;
import org.sikuli.api.ScreenRegion;
import org.sikuli.slides.screenshots.SlideTargetRegion;

/**
 * Search for multiple occurrences of a target on the screen.
 * 
 * @author Khalid Alharbi
 */
public class SearchMultipleTarget {

	
	/**
	 * Check if the screen has multiple occurrences of the Target image.
	 * @param imageTarget the target image to search for.
	 * @return returns true if the screen contains multiple occurrences of the target image (similar targets).
	 */
	public boolean hasMultipleOccurance(ImageTarget imageTarget){
		ScreenRegion fullScreenRegion=new DesktopScreenRegion();
		List<ScreenRegion> targetList=fullScreenRegion.findAll(imageTarget);
		if(targetList!=null && targetList.size()>1){
			return true;
		}
		else{
			return false;
		}
	}
	/**
	 * finds the new screen region that only contains the target image.
	 * @return the screen region that only contains the target image.
	 */
	public ScreenRegion findNewScreenRegion(SlideTargetRegion slideTargetRegion,ImageTarget imageTarget){
		RegionSelector regionSelector=new RegionSelector(slideTargetRegion);
		ScreenRegion newScreenRegion=regionSelector.findScreenRegion(imageTarget,slideTargetRegion);
		return newScreenRegion.find(imageTarget);
	}
}

@@ -867,16 +867,101 @@
 e()%3E1)%7B%0A
+%09%09%09System.out.println(%22Found %22+targetList.size()+%22 similar targets on the screen.%22);%0A
 %09%09%09retur
@@ -1419,16 +1419,46 @@
 egion);%0A
+%09%09if(newScreenRegion!=null)%7B%0A%09
 %09%09return
@@ -1493,13 +1493,45 @@
 arget);%0A
+%09%09%7D%0A%09%09else%7B%0A%09%09%09return null;%0A%09%09%7D%0A
 %09%7D%0A%7D%0A

print the number of similart targets on the screen