1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.util.picking.behavior;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import java.awt.event.*;
27 import java.util.*;
28
29 import javax.media.j3d.*;
30 import javax.swing.event.*;
31 import javax.vecmath.*;
32
33 import com.sun.j3d.utils.picking.*;
34
35
36
37
38 /***
39 * PickMouseBehavior uses new package com.sun.j3d.utils.pickiing.
40 *
41 * @version $Revision: 1.3 $
42 * @author Masahiro Takatsuka (masa@jbeans.net)
43 * @see com.sun.j3d.utils.picking.behaviors.PickMouseBehavior
44 */
45
46 public class PickMouseBehavior extends com.sun.j3d.utils.picking.behaviors.PickMouseBehavior {
47 private transient EventListenerList listenerList;
48
49 /***
50 * constructs a new PickMouseBehavior.
51 *
52 * @param root Root of your scene graph.
53 * @param canvas Java 3D drawing canvas.
54 * @param bounds Bounds of your scene.
55 * @param pickMode specifys USE_BOUNDS or USE_GEOMETRY.
56 * Note: If pickMode is set to USE_GEOMETRY, all geometry object in
57 * the scene graph that allows pickable must have its ALLOW_INTERSECT bit set.
58 */
59 public PickMouseBehavior(Canvas3D canvas3d, BranchGroup root, Bounds bounds, int pickMode) {
60 super(canvas3d, root, bounds);
61 this.listenerList = new EventListenerList();
62 setSchedulingBounds(bounds);
63 setMode(pickMode);
64 }
65
66 public void updateScene(int i, int j) {
67 int clickCount = mevent.getClickCount();
68 pickCanvas.setShapeLocation(i, j);
69 PickResult result = pickCanvas.pickClosest();
70 PickMouseEvent event = new PickMouseEvent(result, mevent);
71
72 if (clickCount == 1) {
73 fireSelectedEvent(event);
74 } else {
75 firePickedEvent(event);
76 }
77 }
78
79 /***
80 * Adds a PickMouseListener to the slider.
81 *
82 * @param l the PickMouseListener to add
83 */
84 public void addPickMouseListener(PickMouseListener l) {
85 this.listenerList.add(PickMouseListener.class, l);
86 }
87
88 /***
89 * Removes a PickMouseListener from the slider.
90 *
91 * @param l the PickMouseListener to remove
92
93 */
94 public void removePickMouseListener(PickMouseListener l) {
95 this.listenerList.remove(PickMouseListener.class, l);
96 }
97
98 /***
99 * Send the Pick node to listeners.
100 */
101 protected void firePickedEvent(PickMouseEvent event) {
102 Object[] listeners = this.listenerList.getListenerList();
103 for (int i = listeners.length - 2; i >= 0; i -= 2) {
104 if (listeners[i] == PickMouseListener.class) {
105 ((PickMouseListener)listeners[i+1]).picked(event);
106 }
107 }
108 }
109
110 /***
111 * Send the Selection node to listeners.
112 */
113 protected void fireSelectedEvent(PickMouseEvent event) {
114 Object[] listeners = this.listenerList.getListenerList();
115 for (int i = listeners.length - 2; i >= 0; i -= 2) {
116 if (listeners[i] == PickMouseListener.class) {
117 ((PickMouseListener)listeners[i+1]).selected(event);
118 }
119 }
120 }
121 }
122