Project

General

Profile

Revision 545

Added by Greg Tress over 16 years ago

Fixed robot selection

View differences:

Colonet.java
424 424
	}
425 425

  
426 426
	public void connect () {
427
		lblConnectionStatus.setText("Status: Connecting...");
428
		webcamLoader = new WebcamLoader(this);
429
		dataUpdater = new DataUpdater();
427
		if (csi != null)
428
			return;
430 429
		csi = new ColonetServerInterface(this);
431 430
		csi.connect(txtHost.getText(), txtPort.getText());
432 431
		if (!csi.isReady()) {
433
			lblConnectionStatus.setText("Status: Offline");
434
		} else {
435
			btnConnect.setText("Disconnect");
436
			lblConnectionStatus.setText("Status: Connected");
437
			dataUpdater.start();
438
			webcamLoader.start();
432
			csi = null;
433
			return;
439 434
		}
435
		webcamLoader = new WebcamLoader(this);
436
		dataUpdater = new DataUpdater();
437
		dataUpdater.start();
438
		webcamLoader.start();
439
		btnConnect.setText("Disconnect");
440
		lblConnectionStatus.setText("Status: Connected");
440 441
	}
441 442

  
442 443
	public void disconnect () {
......
609 610
					return;
610 611
				}
611 612

  
612
				RobotIcon r = robotIcons.get(selectedBot);
613
				r.destx = pt.x;
614
				r.desty = pt.y;
615

  
616
				if (csi != null) {
617
					csi.sendAbsoluteMove(r.id, r.destx, r.desty);
613
				for (int i = 0; i < robotIcons.size(); i++) {
614
					RobotIcon r = robotIcons.get(i);
615
					if (r.id == selectedBot) {
616
						r.destx = pt.x;
617
						r.desty = pt.y;
618
						if (csi != null) {
619
							csi.sendAbsoluteMove(r.id, r.destx, r.desty);
620
						}
621
					}
618 622
				}
619 623

  
620 624
				return;
......
626 630
					return;
627 631
				}
628 632

  
629
				RobotIcon r = robotIcons.get(selectedBot);
630
				r.destx = pt.x;
631
				r.desty = pt.y;
632

  
633
				if (csi != null) {
634
					csi.sendAbsoluteMove(r.id, r.destx, r.desty);
633
				for (int i = 0; i < robotIcons.size(); i++) {
634
					RobotIcon r = robotIcons.get(i);
635
					if (r.id == selectedBot) {
636
						r.destx = pt.x;
637
						r.desty = pt.y;
638
						if (csi != null) {
639
							csi.sendAbsoluteMove(r.id, r.destx, r.desty);
640
						}
641
					}
635 642
				}
636 643

  
637 644
				return;
......
654 661
			for (int i = 0; i < robotIcons.size(); i++) {
655 662
				RobotIcon r = robotIcons.get(i);
656 663
				if (r.contains(pt.x, pt.y)) {
657
					selectedBot = i;
658
					lblSelected.setText(" " + r.id);
664
					selectedBot = r.id;
665
					lblSelected.setText("" + r.id);
659 666
					// Try to select the clicked bot, if its XBee ID is detected.
660 667
					for (int j = 1; j < cmbRobotNum.getItemCount(); j++) {
661
						if (Integer.parseInt(cmbRobotNum.getItemAt(j).toString()) == robotIcons.get(selectedBot).id) {
668
						if (Integer.parseInt(cmbRobotNum.getItemAt(j).toString()) == selectedBot) {
662 669
							cmbRobotNum.setSelectedIndex(j);
663 670
						}
664 671
					}
......
722 729
				csi.sendXBeeIDRequest();
723 730
			} else if (source == btnAssignID) {
724 731
				String message;
725
				if (selectedBot < 0) {
726
					return;
727
				}
728
				int curID = robotIcons.get(selectedBot).id;
729

  
732
				int curID = selectedBot;
730 733
				if (curID < 0) {
731 734
					message = "That robot is unidentified. Please specify its ID.";
732 735
				} else {
......
745 748
				}
746 749
				// Assign new ID and update display
747 750
				csi.sendIDAssignment(curID, newID);
748
				robotIcons.get(selectedBot).id = newID;
749
				robotIcons.get(selectedBot).color = Color.GREEN;
750
				lblSelected.setText(" " + newID);
751
				for (int i = 0; i < robotIcons.size(); i++) {
752
					RobotIcon r = robotIcons.get(i);
753
					if (r.id == curID) {
754
						r.id = newID;
755
						r.color = Color.GREEN;
756
						break;
757
					}
758
				}
759
				lblSelected.setText("" + newID);
751 760
			} else if (source == btnF) { // Robot Movement Controls
752 761
				vectorController.setMaxForward();
753 762
				vectorController.sendToServer();
......
946 955
			}
947 956

  
948 957
			// Identify currently-selected robot
949
			if (selectedBot >= 0 && selectedBot < robotIcons.size()) {
950
				bufferedGraphics.setColor(Color.BLACK);
951
				RobotIcon r = robotIcons.get(selectedBot);
952
				int px = (int) (x + r.x * scale);
953
				int py = (int) (y + r.y * scale);
954
				bufferedGraphics.drawOval(px-RADIUS-6, py-RADIUS-6, 2*r.RADIUS+12, 2*r.RADIUS+12);
958
			for (int i = 0; i < robotIcons.size(); i++) {
959
				RobotIcon r = robotIcons.get(i);
960
				if (r.id == selectedBot) {
961
					int px = (int) (x + r.x * scale);
962
					int py = (int) (y + r.y * scale);
963
					bufferedGraphics.setColor(Color.BLACK);
964
					bufferedGraphics.drawOval(px-RADIUS-6, py-RADIUS-6, 2*r.RADIUS+12, 2*r.RADIUS+12);
965
				}
955 966
			}
956 967

  
957 968
			//Display buffered content

Also available in: Unified diff