View Javadoc

1   /*
2    * @(#)$Id: GestureSample.java 796 2010-05-04 14:54:35Z bpuype $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	Represents a gesture sample as for example used by
7    *                  the Rubine algorithm. Single gestures are represented
8    *                  as notes. 
9    *
10   * -----------------------------------------------------------------------
11   *
12   * Revision Information:
13   *
14   * Date             Who         Reason
15   *
16   * Dec 26, 2006     ukurmann    Initial Release
17   * Mar 22, 2007     bsigner     Cleanup
18   *
19   * -----------------------------------------------------------------------
20   *
21   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
22   *
23   * This software is the proprietary information of ETH Zurich.
24   * Use is subject to license terms.
25   * 
26   */
27  
28  
29  package org.ximtec.igesture.core;
30  
31  import java.util.logging.Level;
32  import java.util.logging.Logger;
33  
34  import org.sigtec.ink.Note;
35  import org.sigtec.util.Constant;
36  import org.ximtec.igesture.io.GestureDevice;
37  
38  
39  /**
40   * Represents a gesture sample as for example used by the Rubine algorithm.
41   * Single gestures are represented as notes.
42   * 
43   * @version 1.0, Dec 2006
44   * @author Ueli Kurmann, igesture@uelikurmann.ch
45   * @author Beat Signer, signer@inf.ethz.ch
46   */
47  public class GestureSample extends DefaultDataObject implements Cloneable,
48        Gesture<Note> {
49  
50     private static final Logger LOGGER = Logger.getLogger(GestureSample.class
51           .getName());
52  
53     public static final String PROPERTY_NAME = "name";
54  
55     public static final String PROPERTY_GESTURE = "gesture";
56  
57     private Note gesture;
58  
59     private String name;
60  
61     private GestureDevice<?,?> source;
62  
63     /**
64      * Constructs a new gesture sample.
65      * 
66      * @param name the name of the gesture sample.
67      * @param note the note the sample note.
68      */
69     public GestureSample(String name, Note gesture) {
70        super();
71        setName(name);
72        setGesture(gesture);
73     }
74     
75     public GestureSample(GestureDevice<?,?> device, String name, Note gesture)
76     {
77  	   this(name,gesture);
78  	   setSource(device);
79     }
80     
81  
82     /**
83      * Sets the sample name.
84      * 
85      * @param name the name to be set.
86      */
87     public void setName(String name) {
88        String oldValue = this.name;
89        this.name = name;
90        propertyChangeSupport.firePropertyChange(PROPERTY_NAME, oldValue, name);
91     } // setName
92  
93  
94     /**
95      * Returns the name of the gesture sample.
96      * 
97      * @return the gesture sample's name.
98      */
99     public String getName() {
100       return name;
101    } // getName
102 
103 
104    /**
105     * Sets the sample gesture.
106     * 
107     * @param gesture the gesture to be set.
108     */
109    public void setGesture(Note gesture) {
110       Note oldValue = this.gesture;
111       this.gesture = gesture;
112       propertyChangeSupport.firePropertyChange(PROPERTY_GESTURE, oldValue,
113             gesture);
114    } // setGesture
115 
116 
117    /**
118     * Returns the gesture sample.
119     * 
120     * @return the gesture sample.
121     */
122    public Note getGesture() {
123       return gesture;
124    } // getGesture
125 
126 
127    /**
128     * {@inheritDoc}
129     */
130    @Override
131    public void accept(Visitor visitor) {
132       visitor.visit(this);
133    }
134 
135 
136    @Override
137    public Object clone() {
138       GestureSample clone = null;
139 
140       try {
141          clone = (GestureSample)super.clone();
142          clone.name = name;
143          clone.gesture = (Note)gesture.clone();
144       }
145       catch (final CloneNotSupportedException e) {
146          LOGGER.log(Level.SEVERE, Constant.EMPTY_STRING, e);
147       }
148 
149       return clone;
150    } // clone
151 
152 
153    @Override
154    public String toString() {
155       return name;
156    } // toString
157 
158 
159 	/* (non-Javadoc)
160 	 * @see org.ximtec.igesture.core.Gesture#getSource()
161 	 */
162 	@Override
163 	public GestureDevice<?, ?> getSource() {
164 		return source;
165 	}
166 
167 	/* (non-Javadoc)
168 	 * @see org.ximtec.igesture.core.Gesture#setSource(org.ximtec.igesture.io.GestureDevice)
169 	 */
170 	@Override
171 	public void setSource(GestureDevice<?, ?> device) {
172 		this.source = device;
173 	}
174 	
175 }