Project

General

Profile

Revision 429

Added support for controlling multiple robots, but there is an image loading problem

View differences:

trunk/code/projects/colonet/ColonetGUI/Colonet.java
68 68
	BufferedImage imageVectorControl;
69 69
	JButton btnAssignID;
70 70
	boolean setWaypoint;
71
	int setWaypointID;
71 72
	JButton btnCommand_MoveTo;
73
	JButton btnCommand_MoveAll;
72 74
	JButton btnCommand_StopTask;
73 75
	JButton btnCommand_ResumeTask;
74 76
	JButton btnCommand_ChargeNow;
......
155 157
		panelWebcam = new WebcamPanel();
156 158
		tabPaneMain = new JTabbedPane();
157 159
		tabPaneMain.add(panelWebcam, "Webcam");
158
		tabPaneMain.add(panelGraph, "Graph");
160
		//tabPaneMain.add(panelGraph, "Graph");
159 161
		
160 162
		// Calculate center of canvas
161 163
		cx = image.getWidth() / 2;
......
224 226
		lblSelected = new JLabel("None");
225 227
		// Command subset
226 228
		setWaypoint = false;
229
		setWaypointID = -1;
227 230
		btnAssignID = new JButton("Assign ID");
228 231
		btnCommand_MoveTo = new JButton("Move to ...");
232
		btnCommand_MoveAll = new JButton("Move all ...");
229 233
		btnCommand_StopTask = new JButton("Stop Current Task");
230 234
		btnCommand_ResumeTask = new JButton("Resume Current Task");
231 235
		btnCommand_ChargeNow = new JButton("Recharge Now");
......
237 241
		panelRobotCommands.add(new JLabel("Selected Icon: "));
238 242
		panelRobotCommands.add(lblSelected);
239 243
		panelRobotCommands.add(btnAssignID);
244
		panelRobotCommands.add(new JLabel(""));
240 245
		panelRobotCommands.add(btnCommand_MoveTo);
246
		panelRobotCommands.add(btnCommand_MoveAll);
241 247
		//panelRobotCommands.add(btnCommand_StopTask);
242 248
		//panelRobotCommands.add(btnCommand_ResumeTask);
243 249
		//panelRobotCommands.add(btnCommand_ChargeNow);
......
327 333
		btnActivate.addKeyListener(this);
328 334
		cmbRobotNum.addKeyListener(this);
329 335
		btnCommand_MoveTo.addActionListener(this);
336
		btnCommand_MoveAll.addActionListener(this);
330 337
		btnCommand_StopTask.addActionListener(this);
331 338
		btnCommand_ResumeTask.addActionListener(this);
332 339
		btnCommand_ChargeNow.addActionListener(this);
......
357 364
	public void paint (Graphics g) {
358 365
	    super.paint(g);
359 366
	}
367
	
368
	public void update (Graphics g) {
369
	    paint(g);
370
	}
360 371
		
361 372
	/** 
362 373
	* Gets the JTextArea used for storing the activity log. This method returns a reference to the 
......
528 539
	public void mousePressed(MouseEvent e) {
529 540
	
530 541
	    // If we are selecting a waypoint (destination) for a specific bot
531
	    if (setWaypoint) {
542
	    if (setWaypoint && setWaypointID  >= 0) {
543
	        setWaypoint = false;
544
	        panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
532 545
	        if (selectedBot < 0 || robotIcons.get(selectedBot).id < 0) 
533 546
	            return;
534
	        int px = e.getX();
535
	        int py = e.getY();
536 547
	        
537 548
	        RobotIcon r = robotIcons.get(selectedBot);
538 549
	        r.destx = e.getX();
539 550
	        r.desty = e.getY();
540
	        
551
	        return;
552
	    }
553
	    
554
	    // If we are setting all waypoints
555
	    if (setWaypoint) {
541 556
	        setWaypoint = false;
542 557
	        panelWebcam.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
558
	        for (int i = 0; i < robotIcons.size(); i++) {
559
	            RobotIcon r = robotIcons.get(i);
560
	            if (r.id < 0)
561
	                continue;
562
	            r.destx = e.getX();
563
	            r.desty = e.getY();
564
	        }
543 565
	        return;
544 566
	    }
545 567
	    
......
646 668
		}
647 669
		// Robot Commands (non-movement)
648 670
		else if (source == btnCommand_MoveTo) {
671
		    if (selectedBot < 0)
672
		        return;
649 673
		    panelWebcam.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
650 674
		    setWaypoint = true;
675
		    setWaypointID = selectedBot;
651 676
		    		
677
		} else if (source == btnCommand_MoveAll) {
678
		    panelWebcam.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
679
		    setWaypoint = true;
680
		    setWaypointID = -1;
681
		    		
652 682
		} else if (source == btnCommand_StopTask) {
653 683
		
654 684
		} else if (source == btnCommand_ResumeTask) {
......
914 944
				img.flush();
915 945
				img = null;
916 946
				img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
947
				txtMatrix.append("c");
917 948
			}
949
			System.gc();
918 950
			img = newimg;
919
			repaint();
920 951
		}
921 952
		
922 953
		public synchronized void setPoints (Point [] newpoints) {
......
1031 1062
					Thread.sleep(WEBCAMLOADER_DELAY);
1032 1063
					if (image != null) 
1033 1064
						image.flush();
1065
					System.gc();
1034 1066
					image = ImageIO.read(imagePath);
1035 1067
					// The MediaTracker waitForID pauses the thread until the image is loaded.
1036 1068
					// We don't want to display a half-downloaded image.
......
1039 1071
					mt.removeImage(image);
1040 1072
					// Save
1041 1073
					panelWebcam.setImage(image);
1042
					//parseLocations(locationsPath.toURL());
1043
					panelWebcam.setPoints(null);  //temporary simulation code
1074
					parseLocations(locationsPath.toURL());
1075
					//panelWebcam.setPoints(null);  //temporary simulation code
1044 1076
				} catch (InterruptedException e) {
1045 1077
					return;
1046 1078
				} catch (java.security.AccessControlException e) {
......
1096 1128
	*/
1097 1129
	class RobotIcon {
1098 1130
		public final int RADIUS = 30;
1099
		public final int CLOSE = 30;
1131
		public final int CLOSE = 70;
1100 1132
		
1101 1133
		public int x, y;
1102 1134
		public int destx, desty;

Also available in: Unified diff