/* $Id: CheckAction.java 268 2011-07-19 10:00:29Z shayashi $ */
package smart_gs.image_search.normal.swingui;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import smart_gs.image_search.logical.SearchResult;

public class CheckAction implements ItemListener{
	
	private SearchResult result;
	private SearchResultViewer parent;
	AbstractSearchResultPanel mediator;
	
	public CheckAction(SearchResultViewer parent,SearchResult result){
		this.result = result;
		this.parent = parent;
	}

	public void itemStateChanged(ItemEvent e) {
	    /*
	     * 20071111 田村
	     *  "Remove" にチェックが入ったときには反応しないように
	     */
	    if (!parent.getRemovedResults().contains(result)) {
		if(e.getStateChange() == ItemEvent.SELECTED){
			parent.getSelectedResults().add(result);
			parent.getBucket().add(result.toQuery());
			//変更　田村
			parent.updateBucket(false);
		}else{
			if(parent.getSelectedResults().contains(result)){
		//		parent.getBucket().remove(parent.getSelectedResults().indexOf(result));
//				parent.getSelectedResults().remove(result);
				/*
				 * 変更
				 */
				parent.getBucket().remove(parent.getPreviousBucketSize() + parent.getSelectedResults().indexOf(result));
				parent.getSelectedResults().remove(result);
				parent.updateBucket(true);
				
			}
		}
	    }
	}
}