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 cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealMap;
16 import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.UT2004Map;
17
18
19
20
21
22
23
24
25
26
27
28 abstract public class SelectableMapGLPanel extends MapGLPanel implements
29 MouseListener {
30
31 ISelectionHandler selectionHandler;
32
33 public SelectableMapGLPanel(GLCapabilities caps, UT2004Map map) {
34 super(caps, map);
35 this.addMouseListener(this);
36 }
37
38 public SelectableMapGLPanel(IUnrealMap map, Logger log) {
39 super(map, log);
40 this.addMouseListener(this);
41 }
42
43 @Override
44 public void destroy() {
45 this.removeMouseListener(this);
46 super.destroy();
47 }
48
49 @Override
50 public void mouseClicked(MouseEvent e) {
51 }
52
53 @Override
54 public void mousePressed(MouseEvent e) {
55
56
57 if (e.getButton() != MouseEvent.BUTTON1) {
58 return;
59 }
60
61
62 ISelectionHandler selectionHandler = getSelectionHandler();
63 if (selectionHandler == null) {
64 return;
65 }
66
67
68 Set<Object> selected = this.getObjectsAt(e.getPoint());
69
70 selectionHandler.selected(selected, e.getPoint(), this);
71 }
72
73 protected ISelectionHandler getSelectionHandler() {
74 return selectionHandler;
75 }
76
77 public void setSelectionHandler(ISelectionHandler selectionHandler) {
78 this.selectionHandler = selectionHandler;
79 }
80
81 @Override
82 public void mouseReleased(MouseEvent e) {
83 }
84
85 @Override
86 public void mouseEntered(MouseEvent e) {
87 }
88
89 @Override
90 public void mouseExited(MouseEvent e) {
91 }
92 }