//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010 huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/god4j
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : god4j@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.god4j.tree;
import java.awt.Component;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import org.huihoo.god4j.GOD4JConstants;
import org.huihoo.god4j.util.ImageLoader;
import org.huihoo.god4j.util.StringManager;
public class NodeExplorerRenderer extends DefaultTreeCellRenderer
{
	private static StringManager sm = StringManager.getManager(ExplorerConstants.PACKAGE);
	
	private Icon packageIcon;
	private Icon applicationsIcon;
	private Icon applicationIcon;
	private Icon parametersIcon;
	private Icon parameterIcon;
	private Icon processesIcon;
	private Icon processIcon;
	private Icon activitiesIcon;
	private Icon activityIcon;
	private Icon transitionsIcon;
	private Icon transitionIcon;
	
	public NodeExplorerRenderer()
	{
		packageIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.packageImage"));
		
		applicationsIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.applicationsImage"));
		applicationIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.applicationImage"));
		
		parametersIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.parametersImage"));
		parameterIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.parameterImage"));
		
		processesIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.processesImage"));
		processIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.processImage"));
		
		activitiesIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.activitiesImage"));
		activityIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.activityImage"));
		
		transitionsIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.transitionsImage"));
		transitionIcon = ImageLoader.getImageIcon(sm.getString("nodeTree.transitionImage"));
	}
	
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus)
	{
		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		
		if(!(value instanceof ExplorerNode))
		{
			return this;
		}
		
		ExplorerNode treeNode = (ExplorerNode) value;
				
		if (ExplorerUtilities.isPackageNode(treeNode))
		{
			this.setIcon(packageIcon);
		}

		if (ExplorerUtilities.isApplicationsNode(treeNode))
		{
			this.setIcon(applicationsIcon);
		}
				
		if (ExplorerUtilities.isApplicationNode(treeNode))
		{
			this.setIcon(applicationIcon);
		}

		if (ExplorerUtilities.isParametersNode(treeNode))
		{
			this.setIcon(parametersIcon);
		}
				
		if (ExplorerUtilities.isParameterNode(treeNode))
		{
			this.setIcon(parameterIcon);
		}
				
		if (ExplorerUtilities.isProcessesNode(treeNode))
		{
			this.setIcon(processesIcon);
		}
				
		if (ExplorerUtilities.isProcessNode(treeNode))
		{
			this.setIcon(processIcon);
		}
		
		if (ExplorerUtilities.isActivitiesNode(treeNode))
		{
			this.setIcon(activitiesIcon);
		}
		if (ExplorerUtilities.isActivityNode(treeNode))
		{
			this.setIcon(activityIcon);
		}
		
		if (ExplorerUtilities.isTransitionsNode(treeNode))
		{
			this.setIcon(transitionsIcon);
		}
		if (ExplorerUtilities.isTransitionNode(treeNode))
		{
			this.setIcon(transitionIcon);
		}
		
		this.setFont(GOD4JConstants.WINDOWS_UI_FONT);
		
		return this;
	}
}
