View Javadoc

1   /*
2    * @(#)$Id: GestureKeyboard.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   * Mar 09, 2007     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.igesture.app.keyboard;
28  
29  import java.io.File;
30  import java.util.List;
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.configuration.Configuration;
38  import org.ximtec.igesture.core.Gesture;
39  import org.ximtec.igesture.core.GestureSet;
40  import org.ximtec.igesture.event.GestureActionManager;
41  import org.ximtec.igesture.io.GestureDevice;
42  import org.ximtec.igesture.io.GestureEventListener;
43  import org.ximtec.igesture.io.mouseclient.MouseReader;
44  import org.ximtec.igesture.util.XMLTool;
45  
46  
47  /**
48   * @version 1.0 Mar 2007
49   * @author Ueli Kurmann, igesture@uelikurmann.ch
50   * @author Beat Signer, signer@inf.ethz.ch
51   */
52  public class GestureKeyboard implements GestureEventListener {
53  
54     private static final Logger LOGGER = Logger.getLogger(GestureKeyboard.class
55           .getName());
56  
57     private static final String INITIALISING = "Initialising...";
58  
59     private static final String INITIALISED = "Initialised.";
60  
61     private static final String MAPPING_FILE = "gestureMapping.xml";
62  
63     private static final String RUBINE_CONFIGURATION = "rubineconfiguration.xml";
64  
65     private static final String GESTURE_SET = "gestureSet/msApplicationGestures.xml";
66  
67     private Recogniser recogniser;
68  
69     private GestureDevice<Note, Point> gestureDevice;
70  
71     private GestureActionManager eventManager;
72  
73  
74     public GestureKeyboard() throws AlgorithmException {
75        LOGGER.info(INITIALISING);
76        initEventManager();
77        initRecogniser();
78        initDevice();
79        LOGGER.info(INITIALISED);
80     }
81  
82  
83     private void initDevice() {
84        gestureDevice = new MouseReader();
85        gestureDevice.init();
86        gestureDevice.addGestureHandler(this);
87  
88     } // initDevice
89  
90  
91     private void initRecogniser() throws AlgorithmException {
92        Configuration configuration = XMLTool.importConfiguration(ClassLoader
93              .getSystemResourceAsStream(RUBINE_CONFIGURATION));
94        GestureSet gestureSet = XMLTool.importGestureSet(ClassLoader
95              .getSystemResourceAsStream(GESTURE_SET));
96        configuration.addGestureSet(gestureSet);
97        
98        recogniser = new Recogniser(configuration);
99        recogniser.addGestureHandler(eventManager);
100    } // initRecogniser
101    
102 
103    private void initEventManager() {
104       eventManager = new GestureActionManager();
105 
106       for (GestureKeyMapping mapping : XMLImport.importKeyMappings(new File(
107             GestureKeyboard.class.getClassLoader().getResource(MAPPING_FILE)
108                   .getFile()))) {
109          LOGGER.info(mapping.toString());
110          eventManager.registerEventHandler(mapping.getGestureName(),
111                new PressKeystroke(mapping.getKeys()));
112       }
113 
114    } // initEventManager
115 
116 
117    public static void main(String[] args) throws AlgorithmException {
118       new GestureKeyboard();
119    }
120 
121 
122    @Override
123    public void handleChunks(List< ? > chunks) {
124       LOGGER.info("Do nothing...");
125 
126    }
127 
128 
129    @Override
130    public void handleGesture(Gesture< ? > gesture) {
131 
132       LOGGER.info("Recoginse gesture...");
133       if (gesture.getGesture() instanceof Note) {
134          Note note = (Note)gesture.getGesture();
135 
136          if (note.getPoints().size() > 5) {
137             recogniser.recognise(note);
138          }
139       }
140 
141    }
142 
143 }