
package com.smartgwt.sample.client;


import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.util.KeyCallback;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.events.MouseOutEvent;
import com.smartgwt.client.widgets.events.MouseOutHandler;
import com.smartgwt.client.widgets.events.MouseOverEvent;
import com.smartgwt.client.widgets.events.MouseOverHandler;
import com.smartgwt.client.widgets.layout.VStack;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuItem;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripMenuButton;


/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class CustomDS implements EntryPoint
{

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad()
	{

		KeyIdentifier debugKey = new KeyIdentifier();
		debugKey.setCtrlKey( true );
		debugKey.setKeyName( "D" );

		Page.registerKey( debugKey, new KeyCallback()
		{
			public void execute(String keyName)
			{
				SC.showConsole();
			}
		} );

		VStack vStack = new VStack();
		vStack.setLeft( 175 );
		vStack.setTop( 75 );
		vStack.setWidth( "70%" );
		vStack.setMembersMargin( 20 );

		Label label = new Label();
		label.setContents( "<ul>" + "<li>On first mouse over of Menu Button, menu animates at 0, 0 (top left) instead of "
				+"under the Menu Button.</li><li>If the menu is activated by mouse clicking, the menu appears correctly under the menu"
				+ " Button.  Subsequent mouse overs then cause the animated menu to appear under the Menu button.</li>"
				+"<li>Note that mouse out events do not fire as expected.</li>"
				+ "</ul>" );
		vStack.addMember( label );

		ToolStrip toolstrip = new ToolStrip();;
		final Menu menu = new Menu();
		menu.setShowShadow( true );
		menu.setShadowDepth( 3 );

		MenuItem menu1 = new MenuItem( "menu 1");
		MenuItem menu2 = new MenuItem( "menu2" );

		menu.setItems( menu1, menu2 );
		
		ToolStripMenuButton menuButton = new ToolStripMenuButton( "Menu Button", menu );
		menuButton.setWidth( 200 );
		menuButton.setMenuAnimationEffect( "slide" );

		menuButton.addMouseOverHandler( new MouseOverHandler()
		{
			@Override
			public void onMouseOver(MouseOverEvent event)
			{
				System.out.println("Mouse over settings button");
				menu.animateShow( AnimationEffect.SLIDE );								
			}
		});
		menuButton.addMouseOutHandler( new MouseOutHandler()
		{
			
			@Override
			public void onMouseOut(MouseOutEvent event)
			{
				System.out.println("No longer hovering over settings button.");
				menu.animateHide( AnimationEffect.SLIDE );				
			}
		});
		
		toolstrip.addMenuButton( menuButton );
		
		
		vStack.setMembers( label, toolstrip );

		vStack.draw();

	}

}
