root / trunk / code / projects / colonet / client / RobotIcon.java @ 776
History | View | Annotate | Download (4.92 KB)
1 |
|
---|---|
2 |
import java.awt.*; |
3 |
|
4 |
/**
|
5 |
* RobotIcon class
|
6 |
* Provides a means for graphically representing and keeping track of webcam bots.
|
7 |
*/
|
8 |
public class RobotIcon { |
9 |
private int id; // the XBee ID of the robot |
10 |
private Color color; // the color used for painting the robot on screen. |
11 |
private Point location; // the position of the robot in the coordinate system of the webcam image |
12 |
private Point destination; // the destination of the robot, if homing or charging |
13 |
private int battery; // the battery level, if available |
14 |
|
15 |
public RobotIcon (int id, int x, int y) { |
16 |
setID(id); |
17 |
setColor(Color.RED);
|
18 |
setLocation(x, y); |
19 |
clearDestination(); |
20 |
setBattery(-1);
|
21 |
} |
22 |
|
23 |
/**
|
24 |
* Returns the ID of this RobotIcon.
|
25 |
*/
|
26 |
public int getID () { |
27 |
return id;
|
28 |
} |
29 |
|
30 |
/**
|
31 |
* Sets the ID of this RobotIcon.
|
32 |
*/
|
33 |
public void setID (int newid) { |
34 |
this.id = newid;
|
35 |
} |
36 |
|
37 |
/**
|
38 |
* Returns the Color used for representing this RobotIcon on screen.
|
39 |
*/
|
40 |
public Color getColor () { |
41 |
return color;
|
42 |
} |
43 |
|
44 |
/**
|
45 |
* Sets the Color used for representing this RobotIcon on screen.
|
46 |
*/
|
47 |
public void setColor (Color newcolor) { |
48 |
this.color = newcolor;
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* Returns the battery level of this RobotIcon.
|
53 |
* TODO: what numbering system is this?
|
54 |
*/
|
55 |
public int getBattery () { |
56 |
return battery;
|
57 |
} |
58 |
|
59 |
/**
|
60 |
* Sets the battery level of this RobotIcon.
|
61 |
* TODO: what numbering system is this?
|
62 |
*/
|
63 |
public void setBattery (int newbattery) { |
64 |
this.battery = newbattery;
|
65 |
} |
66 |
|
67 |
/**
|
68 |
* Returns the location of this RobotIcon as a Point. The location is specified
|
69 |
* in the coordinate system of the original webcam image, NOT the coordinate
|
70 |
* system of the scaled image as seen on screen.
|
71 |
*/
|
72 |
public Point getLocation () { |
73 |
return location;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* Sets the location of this RobotIcon. The location should be specified in the
|
78 |
* coordinate system of the original webcam image, NOT the coordinate system of
|
79 |
* the scaled image as seen on screen.
|
80 |
*/
|
81 |
public void setLocation (int x, int y) { |
82 |
location.setLocation(x, y); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Sets the location of this RobotIcon. The location should be specified in the
|
87 |
* coordinate system of the original webcam image, NOT the coordinate system of
|
88 |
* the scaled image as seen on screen.
|
89 |
*/
|
90 |
public void setLocation (Point p) { |
91 |
location.setLocation(p); |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Returns the destination of this RobotIcon as a Point. The location is specified
|
96 |
* in the coordinate system of the original webcam image, NOT the coordinate
|
97 |
* system of the scaled image as seen on screen. If the RobotIcon has no current
|
98 |
* destination, then this method returns null.
|
99 |
*/
|
100 |
public Point getDestination () { |
101 |
if (!hasDestination())
|
102 |
return null; |
103 |
return destination;
|
104 |
} |
105 |
|
106 |
/**
|
107 |
* Determines whether this RobotIcon currently has a destination, e.g., for homing
|
108 |
* to a specific point in the environment or finding a charging bay.
|
109 |
*/
|
110 |
public boolean hasDestination () { |
111 |
return (destination.x >= 0 && destination.y >= 0); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Sets the destination of this RobotIcon for the purposes of homing to a specific
|
116 |
* point in the environment of finding a charging bay. The destination point should
|
117 |
* be specified in the coordinate system of the original webcam image, NOT the
|
118 |
* coordinate system of the scaled image as seen on screen.
|
119 |
*/
|
120 |
public void setDestination (int x, int y) { |
121 |
destination.setLocation(x, y); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Sets the destination of this RobotIcon for the purposes of homing to a specific
|
126 |
* point in the environment of finding a charging bay. The destination point should
|
127 |
* be specified in the coordinate system of the original webcam image, NOT the
|
128 |
* coordinate system of the scaled image as seen on screen.
|
129 |
*/
|
130 |
public void setDestination (Point p) { |
131 |
destination.setLocation(p); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Clears the destination Point for this RobotIcon, indicating that the robot is
|
136 |
* no longer homing.
|
137 |
*/
|
138 |
public void clearDestination () { |
139 |
setDestination(-1, -1); |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Determines whether a given point is within the rectangle that circumscribes the
|
144 |
* robot's circlular icon. Used for click detection on robots in webcam view. The
|
145 |
* parameter point should be specified in the coordinate system of the original
|
146 |
* webcam image, NOT the coordinate system of the scaled image as seen on screen.
|
147 |
*/
|
148 |
public boolean contains (int px, int py) { |
149 |
return this.getBoundingRectangle().contains(px, py); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Returns the Rectangle object that circumscribes the RobotIcon identifier circle
|
154 |
* that is painted on screen. The Rectangle is in the coordinate system of the
|
155 |
* original webcam image NOT the coordinate system of the scaled image as seen
|
156 |
* on screen.
|
157 |
*/
|
158 |
public Rectangle getBoundingRectangle () { |
159 |
int radius = ColonetConstants.ROBOT_RADIUS;
|
160 |
return new Rectangle(location.x-radius, location.y-radius, 2*radius, 2*radius); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Provides a text representation of this RobotIcon object
|
165 |
*/
|
166 |
public String toString () { |
167 |
String s = "RobotIcon at (" + location.x + "," + location.y + "), id " + id; |
168 |
return s;
|
169 |
} |
170 |
} |