litesoft
@ 948
litesoft / trunk / GWT_Sandbox / MultiModule / foundation / src / org / litesoft / sandbox / multimodule / foundation / client / widgets / DieRotator.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
package org.litesoft.sandbox.multimodule.foundation.client.widgets; import org.litesoft.sandbox.anywhere.die.*; import org.litesoft.sandbox.multimodule.foundation.client.*; import org.litesoft.sandbox.multimodule.foundation.client.support.*; import com.google.gwt.dom.client.*; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.ui.*; public class DieRotator extends Grid { private Die mDie; private Image mDieImage; public DieRotator( FaceSwitcher pFaceSwitcher ) { super( 3, 3 ); addStyleName( "DieRotator" ); setCellPadding( 5 ); setWidget( 0, 1, createButton( pFaceSwitcher, "Down", View.North ) ); setWidget( 1, 0, createButton( pFaceSwitcher, "Right", View.West ) ); setWidget( 1, 1, mDieImage = new Image( "common/TransparentSpacer.gif" ) ); setWidget( 1, 2, createButton( pFaceSwitcher, "Left", View.East ) ); setWidget( 2, 1, createButton( pFaceSwitcher, "Up", View.South ) ); } public void setDie( Die pDie ) { mDie = pDie; updateDieImage(); } private void updateDieImage() { mDieImage.setUrl( "common/dice/die_" + mDie.getResult() + ".gif" ); } private Widget createButton( final FaceSwitcher pFaceSwitcher, String pArrowDirection, final View pViewToMakeResult ) { PushButton zButton = new PushButton( new Image( "common/Arrow" + pArrowDirection + ".gif" ), new ClickHandler() { @Override public void onClick( ClickEvent event ) { mDie.makeViewResult( pViewToMakeResult ); updateDieImage(); pFaceSwitcher.switchTo( Places.fromOrdinal( mDie.getResult() ) ); } } ); zButton.getElement().getStyle().setCursor( Style.Cursor.POINTER ); return zButton; } } |