Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / client / RobotIcon.java @ 1438

History | View | Annotate | Download (4.92 KB)

1 644 gtress
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 776 gtress
        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 644 gtress
15
        public RobotIcon (int id, int x, int y) {
16 776 gtress
                setID(id);
17
                setColor(Color.RED);
18
                setLocation(x, y);
19
                clearDestination();
20
                setBattery(-1);
21 644 gtress
        }
22 776 gtress
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 644 gtress
76
        /**
77 776 gtress
        *         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 644 gtress
        */
81 776 gtress
        public void setLocation (int x, int y) {
82 938 rcahoon
                location = new Point(x, y);
83 644 gtress
        }
84 776 gtress
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 938 rcahoon
    location = p;
92 776 gtress
        }
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 938 rcahoon
          return (destination != null && destination.x >= 0 && destination.y >= 0);
112 776 gtress
        }
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 938 rcahoon
                destination = new Point(x, y);
122 776 gtress
        }
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 938 rcahoon
                destination = p;
132 776 gtress
        }
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 644 gtress
142
        /**
143
        *         Determines whether a given point is within the rectangle that circumscribes the
144 776 gtress
        *         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 644 gtress
        */
148
        public boolean contains (int px, int py) {
149 776 gtress
                return this.getBoundingRectangle().contains(px, py);
150 644 gtress
        }
151 776 gtress
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 644 gtress
163 776 gtress
  /**
164
  *  Provides a text representation of this RobotIcon object
165
  */
166 644 gtress
        public String toString () {
167 776 gtress
                String s = "RobotIcon at (" + location.x + "," + location.y + "), id " + id;
168 644 gtress
                return s;
169
        }
170
}