root / trunk / code / projects / colonet / client / RobotList.java @ 776
History | View | Annotate | Download (892 Bytes)
1 |
import java.util.Map; |
---|---|
2 |
import java.util.HashMap; |
3 |
import java.awt.Point; |
4 |
|
5 |
public class RobotList extends HashMap <Integer, RobotIcon> { |
6 |
|
7 |
/**
|
8 |
* Creates a new RobotList
|
9 |
*/
|
10 |
public RobotList () {
|
11 |
super();
|
12 |
} |
13 |
|
14 |
/**
|
15 |
* For a given Point, finds the robot that conatins this Point
|
16 |
* graphically. The coordinate system is based on the dimensions
|
17 |
* of the image returned by the webcam loader, not the coordinates
|
18 |
* of the panel containing the image in the applet. Returns null
|
19 |
* if no robot contains the Point, or if the Point is null. If
|
20 |
* multiple robots overlap the point, one will be chosen arbitrarily.
|
21 |
*/
|
22 |
public RobotIcon getBoundingIcon (Point p) { |
23 |
if (p == null) |
24 |
return null; |
25 |
for (Map.Entry <Integer,RobotIcon> entry : this.entrySet()) { |
26 |
RobotIcon r = entry.getValue(); |
27 |
if (r.contains(p.x, p.y)) {
|
28 |
return r;
|
29 |
} |
30 |
} |
31 |
return null; |
32 |
} |
33 |
|
34 |
} |