Revision 664
Added some boundary code
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 | 60 |
JButton btnCommand_MoveTo; |
59 | 61 |
JButton btnCommand_MoveAll; |
60 | 62 |
JButton btnCommand_StopTask; |
... | ... | |
204 | 206 |
batteryIcon = new BatteryIcon(0); |
205 | 207 |
lblBattery = new JLabel(batteryIcon); |
206 | 208 |
lblSelected = new JLabel("None"); |
207 |
// Command subset
|
|
209 |
// Management subset
|
|
208 | 210 |
setWaypoint = false; |
209 | 211 |
setWaypointID = -1; |
210 | 212 |
btnAssignID = new JButton("Assign ID"); |
213 |
boundary = new RobotBoundary(); |
|
214 |
btnSetBounds = new JButton("Set Boundary"); |
|
215 |
// Control subset |
|
211 | 216 |
btnCommand_MoveTo = new JButton("Move to ..."); |
212 | 217 |
btnCommand_MoveAll = new JButton("Move all ..."); |
213 | 218 |
btnCommand_StopTask = new JButton("Stop Current Task"); |
... | ... | |
221 | 226 |
panelRobotCommands.add(new JLabel("Selected Icon: ")); |
222 | 227 |
panelRobotCommands.add(lblSelected); |
223 | 228 |
panelRobotCommands.add(btnAssignID); |
224 |
panelRobotCommands.add(new JLabel(""));
|
|
229 |
panelRobotCommands.add(btnSetBounds);
|
|
225 | 230 |
panelRobotCommands.add(btnCommand_MoveTo); |
226 | 231 |
panelRobotCommands.add(btnCommand_MoveAll); |
227 | 232 |
//panelRobotCommands.add(btnCommand_StopTask); |
... | ... | |
281 | 286 |
|
282 | 287 |
// Disable components before connecting |
283 | 288 |
btnConnect.setText("Connect"); |
284 |
lblConnectionStatus.setText("Status: Disconnected");
|
|
285 |
btnF.setEnabled(false);
|
|
286 |
btnB.setEnabled(false);
|
|
287 |
btnL.setEnabled(false);
|
|
288 |
btnR.setEnabled(false);
|
|
289 |
btnActivate.setEnabled(false);
|
|
290 |
cmbRobotNum.setEnabled(false);
|
|
291 |
btnAssignID.setEnabled(false);
|
|
292 |
btnCommand_MoveTo.setEnabled(false);
|
|
293 |
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 |
btnCommand_MoveTo.setEnabled(false); |
|
298 |
btnCommand_MoveAll.setEnabled(false); |
|
294 | 299 |
|
295 | 300 |
/* Add all listeners here */ |
296 | 301 |
// Task Management |
... | ... | |
321 | 326 |
btnConnect.addActionListener(this); |
322 | 327 |
btnGetXBeeIDs.addActionListener(this); |
323 | 328 |
btnAssignID.addActionListener(this); |
329 |
btnSetBounds.addActionListener(this); |
|
324 | 330 |
panelWebcam.addMouseListener(this); |
325 | 331 |
} |
326 | 332 |
|
... | ... | |
578 | 584 |
public void mouseEntered(MouseEvent e) { |
579 | 585 |
} |
580 | 586 |
public void mouseReleased(MouseEvent e) { |
587 |
(new MouseHandler(e)).start(); |
|
588 |
repaint(); |
|
581 | 589 |
} |
582 | 590 |
public void mouseClicked(MouseEvent e) { |
583 | 591 |
} |
584 | 592 |
public void mouseDragged(MouseEvent e) { |
593 |
(new MouseHandler(e)).start(); |
|
594 |
repaint(); |
|
585 | 595 |
} |
586 | 596 |
public void mouseMoved(MouseEvent e) { |
587 | 597 |
} |
... | ... | |
620 | 630 |
Point pt = panelWebcam.convertClick(e); |
621 | 631 |
|
622 | 632 |
// If we are selecting a waypoint (destination) for a specific bot |
623 |
if (setWaypoint && setWaypointID >= 0) { |
|
633 |
if (setWaypoint && setWaypointID >= 0 && e.getID() == MouseEvent.MOUSE_PRESSED) {
|
|
624 | 634 |
setWaypoint = false; |
625 | 635 |
panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
626 | 636 |
if (selectedBot < 0) { |
... | ... | |
635 | 645 |
csi.sendAbsoluteMove(r.id, r.destx, r.desty); |
636 | 646 |
} |
637 | 647 |
} |
638 |
|
|
639 | 648 |
return; |
640 | 649 |
} |
641 | 650 |
|
642 | 651 |
// Right-click also means we are moving a robot |
643 |
if (e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) { |
|
652 |
if ((e.getButton() == MouseEvent.BUTTON2 || e.getButton() == MouseEvent.BUTTON3) |
|
653 |
&& e.getID() == MouseEvent.MOUSE_PRESSED) { |
|
644 | 654 |
if (selectedBot < 0) { |
645 | 655 |
return; |
646 | 656 |
} |
... | ... | |
653 | 663 |
csi.sendAbsoluteMove(r.id, r.destx, r.desty); |
654 | 664 |
} |
655 | 665 |
} |
656 |
|
|
657 | 666 |
return; |
658 | 667 |
} |
659 | 668 |
|
660 | 669 |
// If we are setting all waypoints |
661 |
if (setWaypoint) { |
|
670 |
if (setWaypoint && e.getID() == MouseEvent.MOUSE_PRESSED) {
|
|
662 | 671 |
setWaypoint = false; |
663 | 672 |
panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
664 | 673 |
for (Map.Entry<Integer,RobotIcon> entry : robotIcons.entrySet()) { |
... | ... | |
668 | 677 |
} |
669 | 678 |
return; |
670 | 679 |
} |
680 |
|
|
681 |
// If we are drawing a boundary rectangle |
|
682 |
if (boundary.set) { |
|
683 |
// Begin |
|
684 |
if (e.getID() == MouseEvent.MOUSE_PRESSED) { |
|
685 |
boundary.p1 = new Point(pt.x, pt.y); |
|
686 |
boundary.p2 = new Point(pt.x, pt.y); |
|
687 |
} |
|
688 |
// Resize |
|
689 |
else if (e.getID() == MouseEvent.MOUSE_DRAGGED){ |
|
690 |
boundary.p2 = new Point(pt.x, pt.y); |
|
691 |
} |
|
692 |
// End |
|
693 |
else if (e.getID() == MouseEvent.MOUSE_RELEASED){ |
|
694 |
boundary.p2 = new Point(pt.x, pt.y); |
|
695 |
panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
696 |
boundary.set = false; |
|
697 |
boundary.active = true; |
|
698 |
boundary.sendToServer(); |
|
699 |
} |
|
700 |
return; |
|
701 |
} |
|
671 | 702 |
|
672 | 703 |
// Otherwise, we are selecting a bot, or doing nothing |
673 | 704 |
for (Map.Entry<Integer,RobotIcon> entry : robotIcons.entrySet()) { |
... | ... | |
776 | 807 |
} else if (source == btnActivate) { |
777 | 808 |
vectorController.setZero(); |
778 | 809 |
vectorController.sendToServer(); |
779 |
} else if (source == btnCommand_MoveTo) { // Robot Commands (non-movement) |
|
810 |
} else if (source == btnSetBounds) { |
|
811 |
boundary.set = true; |
|
812 |
panelWebcam.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); |
|
813 |
} else if (source == btnCommand_MoveTo) { |
|
780 | 814 |
if (selectedBot < 0) { |
781 | 815 |
return; |
782 | 816 |
} |
... | ... | |
922 | 956 |
y = (maxHeight - newHeight) / 2 + BORDER; |
923 | 957 |
} |
924 | 958 |
|
925 |
// Draw everything onto the buffer
|
|
959 |
// Draw image onto the buffer
|
|
926 | 960 |
buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); |
927 | 961 |
Graphics2D bufferedGraphics = (Graphics2D)buffer.getGraphics(); |
928 | 962 |
bufferedGraphics.setColor(Color.GRAY); |
... | ... | |
930 | 964 |
Image imgScaled = img.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST); |
931 | 965 |
bufferedGraphics.drawImage(imgScaled, x, y, this); |
932 | 966 |
|
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 |
} |
|
933 | 972 |
|
934 | 973 |
// Draw Identifiers and battery levels |
935 | 974 |
if (robotIcons != null) { |
... | ... | |
1070 | 1109 |
} |
1071 | 1110 |
} |
1072 | 1111 |
} |
1112 |
|
|
1113 |
class RobotBoundary { |
|
1114 |
public boolean active, set; |
|
1115 |
public Point p1, p2; |
|
1116 |
|
|
1117 |
public RobotBoundary () { |
|
1118 |
active = false; |
|
1119 |
set = false; |
|
1120 |
p1 = new Point(-1,-1); |
|
1121 |
p2 = new Point(-1,-1); |
|
1122 |
} |
|
1123 |
|
|
1124 |
public void sendToServer () { |
|
1125 |
//TODO |
|
1126 |
} |
|
1127 |
|
|
1128 |
} |
|
1073 | 1129 |
|
1074 | 1130 |
} |
Also available in: Unified diff