diff options
author | Tim Buschtöns | 2013-05-14 15:39:07 +0000 |
---|---|---|
committer | Tim Buschtöns | 2013-05-14 15:39:07 +0000 |
commit | 4f73a5776a020c88c1e3f78a8302e489cc6bc299 (patch) | |
tree | af3a44d32a4761b6a5f9d81593634a8987b9c083 | |
parent | dcdd417ee44cf73b4b2afd50adec43664475d3d3 (diff) | |
download | org.eclipse.rap.incubator.clientscripting-4f73a5776a020c88c1e3f78a8302e489cc6bc299.tar.gz org.eclipse.rap.incubator.clientscripting-4f73a5776a020c88c1e3f78a8302e489cc6bc299.tar.xz org.eclipse.rap.incubator.clientscripting-4f73a5776a020c88c1e3f78a8302e489cc6bc299.zip |
Add Numpad example to Demo
2 files changed, 67 insertions, 6 deletions
diff --git a/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/Demo.java b/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/Demo.java index 9fd9fd8..f5b0641 100644 --- a/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/Demo.java +++ b/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/Demo.java @@ -10,7 +10,10 @@ ******************************************************************************/ package org.eclipse.rap.clientscripting.demo; +import org.eclipse.rap.clientscripting.ClientListener; +import org.eclipse.rap.clientscripting.WidgetDataWhiteList; import org.eclipse.rap.rwt.application.AbstractEntryPoint; +import org.eclipse.rap.rwt.lifecycle.WidgetUtil; import org.eclipse.swt.SWT; import org.eclipse.swt.events.FocusAdapter; import org.eclipse.swt.events.FocusEvent; @@ -32,12 +35,19 @@ public class Demo extends AbstractEntryPoint { @Override protected void createContents( Composite parent ) { parent.setLayout( new GridLayout( 2, false ) ); - addUpperCaseExample( parent ); - addDigitsOnlyExample( parent ); - addDateFieldExample( parent ); - addCounterExample( parent ); - addCanvasExample( parent ); - addListExample( parent ); + Composite left = new Composite( parent, SWT.NONE ); + left.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + left.setLayout( new GridLayout( 2, false ) ); + addUpperCaseExample( left ); + addDigitsOnlyExample( left ); + addDateFieldExample( left ); + addCounterExample( left ); + addCanvasExample( left ); + addListExample( left ); + Composite right = new Composite( parent, SWT.NONE ); + right.setLayout( new GridLayout( 1, false ) ); + right.setLayoutData( new GridData( SWT.FILL, SWT.FILL, false, true ) ); + addNumpadExample( right ); } private void addUpperCaseExample( Composite parent ) { @@ -77,6 +87,42 @@ public class Demo extends AbstractEntryPoint { CustomBehaviors.addPaintingBehavior( canvas ); } + private void addNumpadExample( Composite parent ) { + addHeaderLabel( parent, "Numpad:" ); + Text text = new Text( parent, SWT.BORDER ); + text.setLayoutData( new GridData( SWT.FILL, SWT.TOP, true, false ) ); + text.setEditable( false ); + Composite pad = new Composite( parent, SWT.NONE ); + pad.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) ); + pad.setLayout( new GridLayout( 3, true ) ); + createNumKeys( pad, text ); + } + + private void createNumKeys( Composite parent, Text text ) { + WidgetDataWhiteList.addKey( "textWidget" ); + WidgetDataWhiteList.addKey( "numValue" ); + String scriptCode + = ResourceLoaderUtil.readTextContent( "org/eclipse/rap/clientscripting/demo/NumKey.js" ); + ClientListener listener = new ClientListener( scriptCode ); + int[] numbers = new int[]{ 7, 8, 9, 4, 5, 6, 1, 2, 3 }; + for( int i = 0; i < numbers.length; i++ ) { + createNumButton( parent, text, listener, numbers[ i ] ); + } + createNumButton( parent, text, listener, -1 ).setText( "C" ); + createNumButton( parent, text, listener, 0 ); + createNumButton( parent, text, listener, -2 ).setText( "." ); + } + + private Button createNumButton( Composite parent, Text text, ClientListener listener, int number ) { + Button button = new Button( parent, SWT.PUSH ); + button.setText( String.valueOf( number ) ); + button.setData( "textWidget", WidgetUtil.getId( text ) ); + button.setData( "numValue", Integer.valueOf( number ) ); + button.addListener( SWT.MouseDown, listener ); + button.setLayoutData( new GridData( 80, 70 ) ); + return button; + } + private void addListExample( Composite parent ) { addHeaderLabel( parent, "List:" ); List list = new List( parent, SWT.BORDER | SWT.MULTI ); diff --git a/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/NumKey.js b/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/NumKey.js new file mode 100644 index 0000000..00b6c03 --- /dev/null +++ b/bundles/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/demo/NumKey.js @@ -0,0 +1,15 @@ +var handleEvent = function( event ) { + var button = event.widget; + var text = rap.getObject( button.getData( "textWidget" ) ); + var value = button.getData( "numValue" ); + var str = text.getText(); + if( value === -1 ) { + text.setText( "" ); + } else if( value === -2 ) { + if( str.length > 0 && str.indexOf( "." ) === -1 ) { + text.setText( str + "." ); + } + } else if( value !== 0 || str.length > 0 ){ + text.setText( str + value ); + } +}; |