package org.ximtec.igesture.app.helloworld; import org.ximtec.igesture.Recogniser; import org.ximtec.igesture.algorithm.AlgorithmException; import org.ximtec.igesture.algorithm.siger.SigerRecogniser; import org.ximtec.igesture.configuration.Configuration; import org.ximtec.igesture.core.GestureClass; import org.ximtec.igesture.core.GestureSet; import org.ximtec.igesture.core.ResultSet; import org.ximtec.igesture.core.TextDescriptor; import org.ximtec.igesture.io.ButtonDeviceEventListener; import org.ximtec.igesture.io.InputDeviceClient; import org.ximtec.igesture.tool.GestureConfiguration; import org.ximtec.ipaper.io.InputDeviceEvent; public class HelloWorld implements ButtonDeviceEventListener { private Recogniser recogniser; private InputDeviceClient client; public HelloWorld() throws AlgorithmException { GestureConfiguration appConfig = new GestureConfiguration("config.xml"); GestureClass leftRightLine = new GestureClass("LeftRight"); leftRightLine.addDescriptor(new TextDescriptor("E")); GestureClass downRight = new GestureClass("DownRight"); downRight.addDescriptor(new TextDescriptor("S,E")); GestureClass upLeft = new GestureClass("UpLeft"); upLeft.addDescriptor(new TextDescriptor("N,W")); GestureSet gestureSet = new GestureSet("GestureSet"); gestureSet.addGestureClass(leftRightLine); gestureSet.addGestureClass(upLeft); gestureSet.addGestureClass(downRight); Configuration configuration = new Configuration(); configuration.addGestureSet(gestureSet); configuration.addAlgorithm(SigerRecogniser.class.getName()); recogniser = new Recogniser(configuration); client = new InputDeviceClient(appConfig); client.addButtonDeviceEventListener(this); System.out.println("initialised..."); } public static void main(String[] args) throws AlgorithmException { new HelloWorld(); } public void handleButtonPressedEvent(InputDeviceEvent event) { ResultSet result = recogniser.recognise(client.createNote(0, event .getTimestamp(), 70)); client.clearBuffer(); if (result.isEmpty()) { System.out.println("not recognised"); } else { System.out.println(result.getResult().getName()); } } }
package org.ximtec.igesture.app.helloworld; import java.util.List; import java.io.File; import java.util.ArrayList; import org.ximtec.igesture.Recogniser; import org.ximtec.igesture.algorithm.AlgorithmException; import org.ximtec.igesture.configuration.Configuration; import org.ximtec.igesture.core.ResultSet; import org.ximtec.igesture.io.ButtonDeviceEventListener; import org.ximtec.igesture.io.InputDeviceClient; import org.ximtec.igesture.io.MouseReader; import org.ximtec.igesture.tool.GestureConfiguration; import org.ximtec.igesture.util.XMLTools; import org.ximtec.ipaper.io.InputDevice; import org.ximtec.ipaper.io.InputDeviceEvent; public class HelloWorldXML implements ButtonDeviceEventListener { private Recogniser recogniser; private InputDeviceClient client; public HelloWorldXML() throws AlgorithmException { GestureConfiguration appConfig = new GestureConfiguration("config.xml"); Configuration configuration = XMLTools.importConfiguration(new File( this.getClass().getClassLoader().getResource( "configuration.xml").getFile())); recogniser = new Recogniser(configuration); List<InputDevice> pens = new ArrayList<InputDevice>(); pens.add(new MouseReader()); client = new InputDeviceClient(appConfig); client.addButtonDeviceEventListener(this); System.out.println("initialised..."); } public static void main(String[] args) throws AlgorithmException { new HelloWorldXML(); } public void handleButtonPressedEvent(InputDeviceEvent event) { ResultSet result = recogniser.recognise(client.createNote(0, event .getTimestamp(), 70)); client.clearBuffer(); if (result.isEmpty()) { System.out.println("not recognised"); } else { System.out.println(result.getResult().getName()); } } }
<?xml version="1.0" encoding="UTF-8"?> <configuration> <algorithm name="org.ximtec.igesture.algorithm.siger.SigerRecogniser" /> <set name="gestureSet1" id="1"> <class name="LeftRight" id="2"><textDescriptor><text>E</text></textDescriptor></class> <class name="DownRight" id="3"><textDescriptor><text>S,E</text></textDescriptor></class> <class name="UpLeft" id="4"><textDescriptor><text>N,W</text></textDescriptor></class> </set> </configuration>