root / trunk / code / projects / colonet / client / RobotList.java @ 757
History | View | Annotate | Download (1.22 KB)
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 on 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 |
/**
|
35 |
* Removes the destination coordinate for a specified robot. As
|
36 |
* a result, no destination vector is painted for the robot on
|
37 |
* the webcam image. This method does not cause any command
|
38 |
* to be sent to the robot.
|
39 |
*/
|
40 |
public void cancelMoveTo (int id) { |
41 |
RobotIcon r = get(id); |
42 |
if (r != null) |
43 |
r.destx = r.desty = -1;
|
44 |
} |
45 |
|
46 |
} |