litesoft
@ 948
litesoft / trunk / GWT_Sandbox / FormEngine / src / com / temp / client / foundation / widget / NamedImageButton.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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
package com.temp.client.foundation.widget; import com.google.gwt.event.dom.client.*; import com.google.gwt.user.client.ui.*; public class NamedImageButton extends CompositeButton<NamedImageButton> { public static final String UP = "Up"; public static final String HOVER = "Hover"; public static final String PRESSED = "Pressed"; public NamedImageButton() { } public NamedImageButton( String name ) { this(); setName( name ); } public NamedImageButton( String name, ClickHandler handler ) { this( name ); add( handler ); } @Override public void setName( String name ) { super.setName( name ); setImage( UP, proxyTo.getUpFace() ); setImage( HOVER, proxyTo.getUpHoveringFace() ); setImage( PRESSED, proxyTo.getDownFace(), proxyTo.getDownHoveringFace(), proxyTo.getUpDisabledFace(), proxyTo.getDownDisabledFace() ); } public NamedImageButton add( ClickHandler handler ) { if ( handler != null ) { proxyTo.addClickHandler( handler ); } return this; } public NamedImageButton style( String className ) { addStyleName( className ); return this; } private void setImage( String imageFaceName, PushButton.Face... faces ) { String url = getImageUrl( getName(), imageFaceName ); for ( PushButton.Face face : faces ) { face.setImage( new Image( url ) ); } } private static String getImageUrl( String name, String imageFaceName ) { return "images/buttons/" + name + "/" + imageFaceName + ".png"; } public static String createSafeHtmlElement( String name, String safeHtmlAltToolTip ) { return createSafeHtmlElementWithIdAndStyle( null, name, UP, safeHtmlAltToolTip, null ); } public static String createSafeHtmlElementWithId( String id, String name, String safeHtmlAltToolTip ) { return createSafeHtmlElementWithIdAndStyle( id, name, UP, safeHtmlAltToolTip, null ); } public static String createSafeHtmlElement( String name, String safeHtmlAltToolTip, String styleName ) { return createSafeHtmlElementWithIdAndStyle( null, name, UP, safeHtmlAltToolTip, styleName ); } public static String createSafeHtmlElementWithId( String id, String name, String safeHtmlAltToolTip, String styleName ) { return createSafeHtmlElementWithIdAndStyle( id, name, UP, safeHtmlAltToolTip, styleName ); } private static String createSafeHtmlElementWithIdAndStyle( String id, String name, String imageFaceName, String safeHtmlAltToolTip, String styleName ) { return createSafeHtmlElementWithImageUrl( id, safeHtmlAltToolTip, styleName, getImageUrl( name, imageFaceName ) ); } } |