01: package ch.aecii.j3d.utils;
02:
03: import java.util.*;
04:
05: import javax.media.j3d.*;
06:
07: /**
08: * An ObservableTransformGroup allows to register Listener which get notified when the TransformGroup
09: * changed.
10: *
11: * @author sg
12: * @version 1.0
13: */
14: public class ObservableTransformGroup extends TransformGroup {
15: private List<TransformGroupListener> listeners = new LinkedList<TransformGroupListener>();
16: private Transform3D t0 = new Transform3D();
17:
18: public void setTransform(Transform3D t1)
19: throws BadTransformException, CapabilityNotSetException {
20: getTransform(t0);
21: if (t0.equals(t1))
22: return;
23:
24: super .setTransform(t1);
25: Iterator it = listeners.iterator();
26: while (it.hasNext()) {
27: TransformGroupListener tgl = (TransformGroupListener) it
28: .next();
29: tgl.transformChanged(this );
30: }
31: }
32:
33: /**
34: * Register a TransformGroupListener to this TransformGroup
35: * @param tgl TransformGroupListener to register
36: */
37: public void addListener(TransformGroupListener tgl) {
38: listeners.add(tgl);
39: }
40:
41: /**
42: * Remove a TransformGroupListener from this TransformGroup
43: * @param tgl TransformGroupListener to remove
44: * @return true if TransformGroupListener has been removed, false otherwise
45: */
46: public boolean remove(TransformGroupListener tgl) {
47: return listeners.remove(tgl);
48: }
49: }
|