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 cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealMap;
16  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.UT2004Map;
17  
18  /**
19   * This is MapGLPanel that is adding selection behavior, when bot is clicked in
20   * the map, list of selected bots in this map IPogamutEnvironments global lookup
21   * will change.
22   * 
23   * @author Honza
24   * 
25   * @since 13-Jan-2011 : Replaced selection handler by an interface to make it
26   *        work for now.
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  		// we only want to select/deselect on left click, not middle click used
56  		// during drag or something like that
57  		if (e.getButton() != MouseEvent.BUTTON1) {
58  			return;
59  		}
60  
61  		// get global selection object for this map
62  		ISelectionHandler selectionHandler = getSelectionHandler();
63  		if (selectionHandler == null) {
64  			return;
65  		}
66  
67  		// Get list of selected bots
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  }