View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
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   * This is MapGLPanel that is adding selection behavior, when bot is clicked in
22   * the map, list of selected bots in this map IPogamutEnvironments global lookup
23   * will change.
24   * 
25   * @author Honza
26   * 
27   * @since 13-Jan-2011 : Replaced selection handler by an interface to make it
28   *        work for now.
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  		// we only want to select/deselect on left click, not middle click used
58  		// during drag or something like that
59  		if (e.getButton() != MouseEvent.BUTTON1) {
60  			return;
61  		}
62  
63  		// get global selection object for this map
64  		ISelectionHandler selectionHandler = getSelectionHandler();
65  		if (selectionHandler == null) {
66  			return;
67  		}
68  
69  		// Get list of selected bots
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  }