/* $Id: BookmarkList.java 125 2011-03-09 09:49:51Z ohura $ */
package smart_gs.swingui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JList;

import smart_gs.logical.GSResource;
import smart_gs.logical.ResourceBasket;
import smart_gs.logical.region.BookmarkRegion;

public class ResourceList extends JList {
	
	public ResourceList(List<GSResource> resources) {
		DefaultListModel model = new DefaultListModel();
		for (int i = 0; i < resources.size(); i++) {
			model.addElement(resources.get(i));
		}
		this.setModel(model);
	}


	public void setResources(List<GSResource> resources) {
		DefaultListModel model = new DefaultListModel();
		for (int i = 0; i < resources.size(); i++) {
			model.addElement(resources.get(i));
		}
		this.setModel(model);
	}
	public int getLength() {
		return ((DefaultListModel)this.getModel()).getSize();
	}


	public List<GSResource> getResources() {
		ArrayList<GSResource> resources = new ArrayList<GSResource>();
		DefaultListModel model = (DefaultListModel)this.getModel();
		int size = model.getSize();
		for (int i = 0; i < size; i++) {
			resources.add((GSResource)model.elementAt(i));
		}
		return resources;
	}


	public void removeResource(GSResource resource) {
		DefaultListModel model = (DefaultListModel)this.getModel();
		ArrayList<GSResource> resources = (ArrayList<GSResource>) this.getResources();
		resources.remove(resource);
		model.clear();
		for (int i = 0; i < resources.size(); i++) {
			model.addElement(resources.get(i));
		}
	}


}
