litesoft
@ 948
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
package org.litesoft.GWT.client.widgets.range; import org.litesoft.GWT.client.*; import org.litesoft.core.*; /** * Factory for Slider "Widgets". * <p> * If the platform (browser) supports HTML5's range input, then a Widget that utilizes that is returned. * If the platform is not "mobile" then (e.g. Firefox) then a mouse/JavaScript based Slider Widget is created. * Otherwise, null is returned to indicated that the "mobile" browser is too old, and probably the processor is too weak to support a JavaScript Slider. * </p> * Note: If null is returned, then the UI should be adjusted to be reasonable w/o a Slider! */ public abstract class SliderFactory { private static SliderFactory mFactory; public static synchronized SliderFactory getFactory() { return (mFactory != null) ? mFactory : (mFactory = createFactory()); } /** * Return a Slider "Widget" if the current platform supports a Slider; with Min==0, Step==1, & Max==100 (useful for simple percentages). * * @return A Slider "Widget" or null if Sliders are not supported. */ public final Slider createSlider() { return createSlider( 100 ); } /** * Return a Slider "Widget" if the current platform supports a Slider; with Min==0, & Step==1. * * @param pMax Maximum value of the range. * * @return A Slider "Widget" or null if Sliders are not supported. */ public final Slider createSlider( int pMax ) { return createSlider( 0, 1, pMax ); } /** * Return a Slider "Widget" if the current platform supports a Slider. * * @param pMin Minimum value of the range. * @param pStep This is Step scale factor of the slider. * @param pMax Maximum value of the range. * * @return A Slider "Widget" or null if Sliders are not supported. */ abstract public Slider createSlider( int pMin, int pStep, int pMax ); private static SliderFactory createFactory() { if ( inputRangeSupported() ) { return new SliderFactory() { @Override public Slider createSlider( int pMin, int pStep, int pMax ) { return new SliderHTML5InputRange( pMin, pStep, pMax ); } }; } if ( DeviceType.Desktop == UserAgent.getInstance().getDeviceType() ) { return new SliderFactory() { @Override public Slider createSlider( int pMin, int pStep, int pMax ) { return new SliderEmulated( pMin, pStep, pMax ); } }; } return new SliderFactory() { @Override public Slider createSlider( int pMin, int pStep, int pMax ) { return null; } }; } /** * Check if browser supports the <input type='range'/> * <p/> * Pulled directly from "Dive into HTML5". */ private static native boolean inputRangeSupported() /*-{ var e = document.createElement( "input" ); e.setAttribute( "type", "range" ); return e.type !== "text"; }-*/; } |