//----------------------------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.actions;

import java.awt.event.ActionEvent;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JToggleButton;

import org.huihoo.god4j.GOD4JFactory;
import org.huihoo.god4j.JGraphFrame;


/**
 * @author reic
 *
 * To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class Grid extends ActionBase
{	
	public Grid()
	{
		super();
		setEnabled(false);
	}
	
	public void actionPerformed(ActionEvent event)
	{
		Object source=event.getSource();
		if(source instanceof JCheckBoxMenuItem)
		{
			//FROM MenuBar
			JCheckBoxMenuItem item=(JCheckBoxMenuItem)source;
			GOD4JFactory.getGOD4J().switchGridVisible(item.isSelected());
		}
		
		if(source instanceof JToggleButton)
		{
			// FROM ToolBar
			JToggleButton button=(JToggleButton)source;
			GOD4JFactory.getGOD4J().switchGridVisible(button.isSelected());
		}
		
	}
	
	public void update()
	{
		setEnabled(false);
		
		JGraphFrame  fame=GOD4JFactory.getGOD4J().getControlPanel().getSelectedJGraph();
		
		if(fame ==null)
		{
			return;
		}
			
		setEnabled(true);
	}
}