1
2
3
4
5 package nl.tudelft.goal.ut2004.visualizer.map;
6
7 import java.awt.event.MouseEvent;
8 import java.awt.event.MouseListener;
9 import java.util.Set;
10 import java.util.logging.Logger;
11
12 import javax.media.opengl.GLCapabilities;
13
14 import nl.tudelft.goal.ut2004.visualizer.services.ISelectionHandler;
15 import nl.tudelft.goal.ut2004.visualizer.timeline.map.IRenderableUTAgent;
16 import nl.tudelft.goal.ut2004.visualizer.timeline.map.IRenderableWorldObject;
17 import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealMap;
18 import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.UT2004Map;
19
20
21
22
23
24
25
26
27
28
29
30 abstract public class SelectableMapGLPanel extends MapGLPanel implements
31 MouseListener {
32
33 ISelectionHandler selectionHandler;
34
35 public SelectableMapGLPanel(GLCapabilities caps, UT2004Map map, Logger log) {
36 super(caps, map, log);
37 this.addMouseListener(this);
38 }
39
40 public SelectableMapGLPanel(IUnrealMap map, Logger log) {
41 super(map, log);
42 this.addMouseListener(this);
43 }
44
45 @Override
46 public void destroy() {
47 this.removeMouseListener(this);
48 super.destroy();
49 }
50
51 @Override
52 public void mouseClicked(MouseEvent e) {
53 }
54
55 @Override
56 public void mousePressed(MouseEvent e) {
57
58
59 if (e.getButton() != MouseEvent.BUTTON1) {
60 return;
61 }
62
63
64 ISelectionHandler selectionHandler = getSelectionHandler();
65 if (selectionHandler == null) {
66 return;
67 }
68
69
70 Set<IRenderableWorldObject> selected = this.getObjectsAt(e.getPoint());
71
72 selectionHandler.selected(selected, e.getPoint(), this);
73 }
74
75 protected ISelectionHandler getSelectionHandler() {
76 return selectionHandler;
77 }
78
79 public void setSelectionHandler(ISelectionHandler selectionHandler) {
80 this.selectionHandler = selectionHandler;
81 }
82
83 @Override
84 public void mouseReleased(MouseEvent e) {
85 }
86
87 @Override
88 public void mouseEntered(MouseEvent e) {
89 }
90
91 @Override
92 public void mouseExited(MouseEvent e) {
93 }
94 }