Revision 667
Updated boundary code, need to implement scaling
trunk/code/projects/colonet/client/Colonet.java | ||
---|---|---|
55 | 55 |
JButton btnAssignID; |
56 | 56 |
boolean setWaypoint; |
57 | 57 |
int setWaypointID; |
58 |
JButton btnSetBounds; |
|
59 |
RobotBoundary boundary; |
|
58 |
JButton btnSetBounds;
|
|
59 |
RobotBoundary boundary;
|
|
60 | 60 |
JButton btnCommand_MoveTo; |
61 | 61 |
JButton btnCommand_MoveAll; |
62 | 62 |
JButton btnCommand_StopTask; |
... | ... | |
286 | 286 |
|
287 | 287 |
// Disable components before connecting |
288 | 288 |
btnConnect.setText("Connect"); |
289 |
lblConnectionStatus.setText("Status: Disconnected"); |
|
290 |
btnF.setEnabled(false); |
|
291 |
btnB.setEnabled(false); |
|
292 |
btnL.setEnabled(false); |
|
293 |
btnR.setEnabled(false); |
|
294 |
btnActivate.setEnabled(false); |
|
295 |
cmbRobotNum.setEnabled(false); |
|
296 |
btnAssignID.setEnabled(false); |
|
297 |
btnCommand_MoveTo.setEnabled(false); |
|
298 |
btnCommand_MoveAll.setEnabled(false); |
|
289 |
lblConnectionStatus.setText("Status: Disconnected"); |
|
290 |
btnF.setEnabled(false); |
|
291 |
btnB.setEnabled(false); |
|
292 |
btnL.setEnabled(false); |
|
293 |
btnR.setEnabled(false); |
|
294 |
btnActivate.setEnabled(false); |
|
295 |
cmbRobotNum.setEnabled(false); |
|
296 |
btnAssignID.setEnabled(false); |
|
297 |
btnSetBounds.setEnabled(false); |
|
298 |
btnCommand_MoveTo.setEnabled(false); |
|
299 |
btnCommand_MoveAll.setEnabled(false); |
|
299 | 300 |
|
300 | 301 |
/* Add all listeners here */ |
301 | 302 |
// Task Management |
... | ... | |
326 | 327 |
btnConnect.addActionListener(this); |
327 | 328 |
btnGetXBeeIDs.addActionListener(this); |
328 | 329 |
btnAssignID.addActionListener(this); |
329 |
btnSetBounds.addActionListener(this); |
|
330 |
btnSetBounds.addActionListener(this);
|
|
330 | 331 |
panelWebcam.addMouseListener(this); |
331 | 332 |
} |
332 | 333 |
|
... | ... | |
429 | 430 |
btnActivate.setEnabled(true); |
430 | 431 |
cmbRobotNum.setEnabled(true); |
431 | 432 |
btnAssignID.setEnabled(true); |
433 |
btnSetBounds.setEnabled(true); |
|
432 | 434 |
btnCommand_MoveTo.setEnabled(true); |
433 | 435 |
btnCommand_MoveAll.setEnabled(true); |
434 | 436 |
} |
... | ... | |
453 | 455 |
btnActivate.setEnabled(false); |
454 | 456 |
cmbRobotNum.setEnabled(false); |
455 | 457 |
btnAssignID.setEnabled(false); |
458 |
btnSetBounds.setEnabled(false); |
|
456 | 459 |
btnCommand_MoveTo.setEnabled(false); |
457 | 460 |
btnCommand_MoveAll.setEnabled(false); |
458 | 461 |
} |
... | ... | |
688 | 691 |
// Resize |
689 | 692 |
else if (e.getID() == MouseEvent.MOUSE_DRAGGED){ |
690 | 693 |
boundary.p2 = new Point(pt.x, pt.y); |
694 |
repaint(); |
|
691 | 695 |
} |
692 | 696 |
// End |
693 | 697 |
else if (e.getID() == MouseEvent.MOUSE_RELEASED){ |
... | ... | |
964 | 968 |
Image imgScaled = img.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST); |
965 | 969 |
bufferedGraphics.drawImage(imgScaled, x, y, this); |
966 | 970 |
|
967 |
// Draw boundary |
|
968 |
if (boundary.set || boundary.active) { |
|
969 |
bufferedGraphics.setColor(Color.BLUE); |
|
970 |
bufferedGraphics.drawRect(boundary.p1.x, boundary.p1.y, boundary.p2.x, boundary.p2.y); |
|
971 |
} |
|
971 |
// Draw boundary |
|
972 |
if (boundary.set || boundary.active) { |
|
973 |
bufferedGraphics.setColor(Color.BLUE); |
|
974 |
Point p1scaled = convertImagePoint(boundary.p1); |
|
975 |
Point p2scaled = convertImagePoint(boundary.p2); |
|
976 |
bufferedGraphics.drawRect(p1scaled.x, p1scaled.y, p2scaled.x, p2scaled.y); |
|
977 |
} |
|
972 | 978 |
|
973 | 979 |
// Draw Identifiers and battery levels |
974 | 980 |
if (robotIcons != null) { |
... | ... | |
1052 | 1058 |
px = (int) (px / scale); |
1053 | 1059 |
return new Point(px, py); |
1054 | 1060 |
} |
1061 |
|
|
1062 |
/** |
|
1063 |
* Convert a point on the webcam image to the corresponding point within the JPanel |
|
1064 |
*/ |
|
1065 |
public Point convertImagePoint (Point p) { |
|
1066 |
if (img == null) { |
|
1067 |
return new Point(p.x, p.y); |
|
1068 |
} |
|
1069 |
|
|
1070 |
//TODO: Implement this method |
|
1071 |
return new Point(p.x, p.y); |
|
1072 |
} |
|
1055 | 1073 |
} |
1056 | 1074 |
|
1057 | 1075 |
/* |
... | ... | |
1111 | 1129 |
} |
1112 | 1130 |
|
1113 | 1131 |
class RobotBoundary { |
1114 |
public boolean active, set; |
|
1115 |
public Point p1, p2; |
|
1132 |
public volatile boolean active, set;
|
|
1133 |
public volatile Point p1, p2;
|
|
1116 | 1134 |
|
1117 | 1135 |
public RobotBoundary () { |
1118 | 1136 |
active = false; |
Also available in: Unified diff