View Javadoc

1   /*
2    * @(#)$Id: WorkspaceTool.java 456 2008-11-11 09:54:06Z D\signerb $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *                  
6    *
7    * Purpose		: 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date				Who			Reason
14   *
15   * 27.10.2008			ukurmann	Initial Release
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.core;
28  
29  import java.util.ArrayList;
30  import java.util.List;
31  
32  
33  /**
34   * Comment
35   * @version 1.0 27.10.2008
36   * @author Ueli Kurmann
37   */
38  public class TestClass extends DefaultDataObject {
39  
40     public static final String PROPERTY_GESTURES = "gestures";
41     public static final String PROPERTY_NAME = "name";
42     private ArrayList<Gesture<?>> gestures;
43     private String name;
44  
45  
46     public TestClass(String name) {
47        this.name = name;
48        this.gestures = new ArrayList<Gesture<?>>();
49     }
50  
51  
52     /**
53      * Returns the name of the gesture
54      * @return
55      */
56     public String getName() {
57        return this.name;
58     }
59     
60     public void setName(String name){
61       String oldName = this.name; 
62       this.name = name;
63        
64        for(Gesture<?> gesture:gestures){
65           gesture.setName(name);
66        }
67        
68        propertyChangeSupport.firePropertyChange(PROPERTY_NAME, oldName, this.name);
69     }
70  
71  
72     /**
73      * Returns a shallow copy of the gesture instances.
74      * @return a shallow copy of the gesture instances.
75      */
76     @SuppressWarnings("unchecked")
77     public List<Gesture<?>> getGestures() {
78        return (List<Gesture<?>>)gestures.clone();
79     }
80  
81  
82     /**
83      * Add a gesture to the test class
84      * @param gesture
85      */
86     public void add(Gesture<?> gesture) {
87        gesture.setName(this.getName());
88        gestures.add(gesture);
89        propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_GESTURES, 0,
90              null, gesture);
91     }
92  
93  
94     /**
95      * Remove a gesture from the test class
96      * @param gesture
97      */
98     public void remove(Gesture<?> gesture) {
99        gestures.remove(gesture);
100       propertyChangeSupport.fireIndexedPropertyChange(PROPERTY_GESTURES, 0,
101             gesture, null);
102    }
103 
104 
105    /**
106     * Returns the number of gestures in the test set.
107     * @return the number of gestures in the test set.
108     */
109    public int size() {
110       return gestures.size();
111    }
112 
113 
114    @Override
115    public int hashCode() {
116       return name != null ? name.hashCode():0;
117    }
118    
119    @Override
120    public boolean equals(Object object) {
121       if(object == this){
122          return true;
123       }
124       
125       if(!(object instanceof TestClass)){
126          return false;
127       }
128       TestClass o = (TestClass)object;
129       if(this.getName() != null && this.getName().equals(o.getName())){
130          return true;
131       }
132       
133       return false;
134    }
135    
136    @Override
137    public void accept(Visitor visitor) {
138       visitor.visit(this);
139 
140       for (Gesture<?> gesture : gestures) {
141          gesture.accept(visitor);
142       }
143 
144    } // accept
145 }