View Javadoc

1   /*
2    * @(#)$Id: HelloWorld.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      :   
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Nov 15, 2006     ukurmann    Initial Release
15   * Mar 24, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.app.helloworld;
28  
29  import java.util.List;
30  import java.util.logging.Level;
31  import java.util.logging.Logger;
32  
33  import org.sigtec.ink.Note;
34  import org.sigtec.ink.Point;
35  import org.ximtec.igesture.Recogniser;
36  import org.ximtec.igesture.algorithm.AlgorithmException;
37  import org.ximtec.igesture.algorithm.siger.SigerAlgorithm;
38  import org.ximtec.igesture.configuration.Configuration;
39  import org.ximtec.igesture.core.Gesture;
40  import org.ximtec.igesture.core.GestureClass;
41  import org.ximtec.igesture.core.GestureSet;
42  import org.ximtec.igesture.core.ResultSet;
43  import org.ximtec.igesture.core.TextDescriptor;
44  import org.ximtec.igesture.io.GestureDevice;
45  import org.ximtec.igesture.io.GestureEventListener;
46  import org.ximtec.igesture.io.mouseclient.MouseReader;
47  
48  
49  /**
50   * @version 1.0 Nov 2006
51   * @author Ueli Kurmann, igesture@uelikurmann.ch
52   * @author Beat Signer, signer@inf.ethz.ch
53   */
54  public class HelloWorld implements GestureEventListener {
55  
56     private static final Logger LOGGER = Logger.getLogger(HelloWorld.class
57           .getName());
58  
59     private static final String INITIALISED = "Initialised.";
60  
61     private static final String NOT_RECOGNISED = "Not recognised.";
62  
63     private Recogniser recogniser;
64  
65     private GestureDevice<Note, Point> client;
66  
67  
68     public HelloWorld() throws AlgorithmException {
69        init();
70        LOGGER.log(Level.INFO, INITIALISED);
71     }
72  
73  
74     private void init() throws AlgorithmException {
75        GestureClass leftRightLine = new GestureClass("LeftRight");
76        leftRightLine.addDescriptor(new TextDescriptor("E"));
77  
78        GestureClass downRight = new GestureClass("DownRight");
79        downRight.addDescriptor(new TextDescriptor("S,E"));
80  
81        GestureClass upLeft = new GestureClass("UpLeft");
82        upLeft.addDescriptor(new TextDescriptor("N,W"));
83  
84        GestureSet gestureSet = new GestureSet("GestureSet");
85        gestureSet.addGestureClass(leftRightLine);
86        gestureSet.addGestureClass(upLeft);
87        gestureSet.addGestureClass(downRight);
88  
89        Configuration configuration = new Configuration();
90        configuration.addGestureSet(gestureSet);
91        configuration.addAlgorithm(SigerAlgorithm.class.getName());
92  
93        recogniser = new Recogniser(configuration);
94        client = new MouseReader();
95        client.init();
96        client.addGestureHandler(this);
97     }
98  
99  
100    @Override
101    public void handleChunks(List< ? > chunks) {
102       LOGGER.log(Level.INFO, "Not implemented");
103 
104    }
105 
106 
107    @Override
108    public void handleGesture(Gesture< ? > gesture) {
109 
110       if (gesture.getGesture() instanceof Note) {
111          Note note = (Note)gesture.getGesture();
112          ResultSet result = recogniser.recognise(note);
113 
114          if (result.isEmpty()) {
115             LOGGER.log(Level.INFO, NOT_RECOGNISED);
116          }
117          else {
118             LOGGER.log(Level.INFO, result.getResult().getGestureClassName());
119          }
120       }
121    }
122 
123 
124    public static void main(String[] args) throws Exception {
125       new HelloWorld();
126       Thread.sleep(Integer.MAX_VALUE);
127    }
128 
129 }