View Javadoc

1   /*
2    * @(#)$Id: SampleDescriptor.java 730 2009-08-05 21:17:30Z kurmannu $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	Describes a gesture by a set of gesture samples.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Dec 26, 2006     ukurmann    Initial Release
15   * Mar 22, 2007     bsigner     Cleanup
16   * Jan 19, 2009		vogelsar	Made more generic to be able to store GestureSample3D
17   *
18   * -----------------------------------------------------------------------
19   *
20   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
21   *
22   * This software is the proprietary information of ETH Zurich.
23   * Use is subject to license terms.
24   * 
25   */
26  
27  
28  package org.ximtec.igesture.core;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  
34  /**
35   * Describes a gesture by a set of gesture samples.
36   * 
37   * @version 1.0, Dec 2006
38   * @author Ueli Kurmann, igesture@uelikurmann.ch
39   * @author Beat Signer, signer@inf.ethz.ch
40   */
41  public abstract class DefaultSampleDescriptor<T> extends DefaultDescriptor {
42  
43     public static final String PROPERTY_SAMPLES = "samples";
44  
45     private List<Gesture<T>> samples;
46  
47  
48     /**
49      * Constructs a new sample descriptor.
50      * 
51      */
52     public DefaultSampleDescriptor() {
53        super();
54        samples = new ArrayList<Gesture<T>>();
55     }
56  
57  
58     /**
59      * Returns the samples.
60      * 
61      * @return the samples.
62      */
63     public List<Gesture<T>> getSamples() {
64        return samples;
65     } // getSamples
66  
67  
68     /**
69      * Returns the gesture sample for a given index position.
70      * @param index the position of the sample to be returned.
71      * @return the sample at the specified index position.
72      */
73     public Gesture<T> getSample(int index) {
74        if (samples.size() >= index - 1) {
75           return samples.get(index);
76        }
77        
78        return null;
79     } // getSample
80  
81  
82     /**
83      * Adds a sample to the descriptor.
84      * 
85      * @param sample the sample to be added.
86      */
87     public void addSample(Gesture<T> sample) {
88        samples.add(sample);
89        propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_SAMPLES, samples
90              .indexOf(sample), null, sample);
91     } // addSample
92  
93  
94     /**
95      * Removes a sample from the gesture set.
96      * 
97      * @param sample the sample to be removed.
98      */
99     public void removeSample(Gesture<T> sample) {
100       int index = samples.indexOf(sample);
101       samples.remove(sample);
102       propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_SAMPLES, index,
103             sample, null);
104    } // removeSample
105 
106 
107    /**
108     * {@inheritDoc}
109     */
110    @Override
111    public void accept(Visitor visitor) {
112       visitor.visit(this);
113       for (Gesture<T> sample : samples) {
114         sample.accept(visitor);
115       }
116    } // accept
117 
118 
119    
120 
121 
122    @Override
123    public String toString() {
124       return getName();
125    } // toString
126 
127 }