jancoow 11 жил өмнө
parent
commit
6e2da6812f

+ 28 - 6
gui/customComponents/ComWriter.java

@@ -4,12 +4,15 @@ import gnu.io.CommPortIdentifier;
 import gnu.io.NoSuchPortException;
 import gnu.io.PortInUseException;
 import gnu.io.SerialPort;
+import gnu.io.SerialPortEvent;
+import gnu.io.SerialPortEventListener;
 import gnu.io.UnsupportedCommOperationException;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.TooManyListenersException;
 
 // Com1Writer.java 1.1 12/02/22  voor BlueJ omgeving
 // @author Jan Woolderink
@@ -22,8 +25,8 @@ public class ComWriter
     private CommPortIdentifier portId;
     private static SerialPort serialPort;
     private OutputStream outputStream;
-    private InputStream inputStream;
-
+    private InputStream in;
+    
     public ComWriter() 
     {
         initCom();
@@ -38,15 +41,16 @@ public class ComWriter
      
         try 
         {
-            serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
+            serialPort = (SerialPort) portId.open("Boebot", 2000);
         } catch (PortInUseException e) { e.printStackTrace(); }
      
         try 
         {
             outputStream = serialPort.getOutputStream();
-            inputStream = serialPort.getInputStream();
+            in = serialPort.getInputStream();
         } catch (IOException e) { e.printStackTrace(); }
-
+        
+                
         try 
         {
             serialPort.setSerialPortParams(9600,
@@ -55,6 +59,17 @@ public class ComWriter
                                            SerialPort.PARITY_NONE);
         } catch (UnsupportedCommOperationException e) {}
      
+        try {
+			serialPort.addEventListener(new SerialPortEventListener() {
+				@Override
+				public void serialEvent(SerialPortEvent arg0) {
+					System.out.println("tset");
+					
+				}
+			});
+		} catch (TooManyListenersException e) {
+			e.printStackTrace();
+		}
         System.out.println("COM6: ");
         System.out.println(serialPort.getBaudRate());
         System.out.println(serialPort.getDataBits());
@@ -71,8 +86,14 @@ public class ComWriter
         } catch (UnsupportedCommOperationException e) 
             {System.out.println("Onbekende baudrate");}
     } 
+    public InputStream getInput(){
+    	return in;
+    }
+
+    
     public void writeString(String tekst) 
     {
+
         try 
         {
             outputStream.write(tekst.getBytes());
@@ -84,8 +105,9 @@ public class ComWriter
 		for(Character step:route){
 			routestring = routestring + step;
 		}
+		System.out.println(routestring);
 		routestring = routestring + "?";
-		writeString(route.toString());
+		writeString(routestring);
 	}
 	public void sendSpeed(int snelheid){
 		String st = ""+snelheid;

+ 1 - 0
gui/customComponents/Filehandling.java

@@ -64,6 +64,7 @@ public class Filehandling {
 	    
 	    file.add("broboticsrouteplanner");
 	    file.add(maxx+","+maxy);
+	    System.out.println(maxx);
 	    file.add(routestring + ";");
 	    try {
 			Files.write(path, file, ENCODING);

+ 36 - 9
gui/customComponents/Kruispunt.java

@@ -21,14 +21,14 @@ public class Kruispunt extends JLabel
     BufferedImage kruispunt;
     public Kruispunt() 
     {
-    	kruispunt = null;
+     kruispunt = null;
     }
     public void setBoebot(int rotation)
     {
         if(rotation == 90)
         {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/boebot.png"));
+            kruispunt = ImageIO.read(new File("pictures/boebot.png"));
         }catch (IOException e){
             
         }
@@ -36,7 +36,7 @@ public class Kruispunt extends JLabel
         if(rotation == 0)
         {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/boven boebot.png"));
+            kruispunt = ImageIO.read(new File("pictures/boven boebot.png"));
         }catch (IOException e){
             
         }
@@ -44,7 +44,7 @@ public class Kruispunt extends JLabel
         if(rotation == 180)
         {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/onder boebot.png"));
+            kruispunt = ImageIO.read(new File("pictures/onder boebot.png"));
         }catch (IOException e){
             
         }
@@ -52,26 +52,53 @@ public class Kruispunt extends JLabel
         if(rotation == 270)
         {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/links boebot.png"));
+            kruispunt = ImageIO.read(new File("pictures/links boebot.png"));
         }catch (IOException e){
             
         }
     }
         this.repaint();
     }
-    public void setGat()
+    public void setGat(int rotation)
     {
+          if(rotation == 90)
+        {
+        try{
+            kruispunt = ImageIO.read(new File("pictures/gatrechts.png"));
+        }catch (IOException e){
+            
+        }
+    }
+        if(rotation == 0)
+        {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/gat.png"));
+            kruispunt = ImageIO.read(new File("pictures/gatboven.png"));
         }catch (IOException e){
             
         }
+    }
+        if(rotation == 180)
+        {
+        try{
+            kruispunt = ImageIO.read(new File("pictures/gatonder.png"));
+        }catch (IOException e){
+            
+        }
+    }
+        if(rotation == 270)
+        {
+        try{
+            kruispunt = ImageIO.read(new File("pictures/gatlinks.png"));
+        }catch (IOException e){
+            
+        }
+    }
         this.repaint();
     }
     public void setFinish()
     {
         try{
-            kruispunt = ImageIO.read(new File("src/pictures/finish.png"));
+            kruispunt = ImageIO.read(new File("pictures/finish.png"));
         }catch (IOException e){
             
         }
@@ -88,4 +115,4 @@ public class Kruispunt extends JLabel
       
       g2.drawImage(kruispunt, 0, 0, getWidth(), getHeight(), null);
     }
-}
+}

+ 89 - 0
gui/customComponents/MapLabel.java

@@ -0,0 +1,89 @@
+package customComponents;
+
+import java.awt.Color;
+import java.awt.Cursor;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+
+@SuppressWarnings("serial")
+public class MapLabel extends JLabel{
+	
+	int x1, y1;
+	public int xcoord, ycoord;
+	private boolean isSelected;
+	
+	public MapLabel(int x1, int y1, int xcoord, int ycoord){
+		this.x1 = x1;
+		this.y1 = y1;
+		this.xcoord = xcoord;
+		this.ycoord = ycoord;
+		isSelected(false);
+		setBounds(x1 - 3,y1 - 3, 6, 6);
+		setOpaque(true);
+	}
+	
+	public void isSelected(boolean selected){
+		if(selected){
+			setBackground(new Color(255,0,0));
+			setBorder(BorderFactory.createLineBorder(new Color(255,0,0), 1, true));
+			setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
+		}else{
+			setBackground(new Color(100, 100, 100));
+			setBorder(BorderFactory.createLineBorder(new Color(80,80,80), 1, true));
+			setCursor(new Cursor(Cursor.HAND_CURSOR));
+		}
+		this.isSelected = selected;
+	}
+	/*public void paintComponent(Graphics g){
+		super.paintComponent(g);
+	    Graphics2D graphics = (Graphics2D) g;
+	    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+	    Shape circle = new Ellipse2D.Double(1, 1, 5, 5);
+	    graphics.setPaint(Color.BLACK);
+	    graphics.fill(circle);
+	    graphics.draw(circle);
+	    
+	}*/
+	public void setSize(int x, int y , int width, int height){
+		setBounds(x - 3,y - 3, 6, 6);
+		setX1(x);
+		setY1(y);
+	}
+	public boolean isSelected() {
+		return isSelected;
+	}
+
+	public int getX1() {
+		return x1;
+	}
+
+	public void setX1(int x1) {
+		this.x1 = x1;
+	}
+
+	public int getY1() {
+		return y1;
+	}
+
+	public void setY1(int y1) {
+		this.y1 = y1;
+	}
+
+	public int getXcoord() {
+		return xcoord;
+	}
+
+	public void setXcoord(int xcoord) {
+		this.xcoord = xcoord;
+	}
+
+	public int getYcoord() {
+		return ycoord;
+	}
+
+	public void setYcoord(int ycoord) {
+		this.ycoord = ycoord;
+	}
+	
+}

+ 21 - 2
gui/main/Main.java

@@ -1,6 +1,8 @@
 package panels;
 
 import java.awt.GridLayout;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import javax.swing.JButton;
 import javax.swing.JLabel;
@@ -10,17 +12,34 @@ public class Iconbar extends JPanel {
 	public JButton irremote;
 	public JLabel currentroute;
 	public JLabel currentGridSize;
+	private JLabel messages;
+	Timer timer;
 	
 	public Iconbar(){
 		currentGridSize = new JLabel();
 		currentroute = new JLabel();
 		irremote = new JButton("Afstandsbediening");
+		messages = new JLabel();
+		timer = new Timer();
 		
-		this.setLayout(new GridLayout(0,5,10,10));
+		this.setLayout(new GridLayout(0,4,10,10));
 	
 		this.add(irremote);
 		this.add(currentroute);
 		this.add(currentGridSize);
+		this.add(messages);
+	}
+	public void setMessage(String message, int time){
+		messages.setText(message);
+		if (time != 0){
+			timer.schedule(new TimerTask() {
+				
+				@Override
+				public void run() {
+					messages.setText("");
+					
+				}
+			}, time);
+		}
 	}
-	
 }

+ 70 - 29
gui/panels/MainMenu.java

@@ -4,6 +4,7 @@ import java.awt.BorderLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.IOException;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 
@@ -28,68 +29,83 @@ public class MainMenu extends JPanel{
 	ComWriter bluetooth;
 	Remote remote;
 	Filehandling file;
-	
 	String currentRouteFile;
-	int maxx, maxy;
-	ArrayList<ArrayList<Integer>> currentRouteCoordinates;
-	ArrayList<Character> currentRouteSteps;
-	
+	boolean startup;
+	 
 	public MainMenu(){
     	menubar = new Menubar();
     	routeSplitpane = new RouteSplitpane();
     	iconbar = new Iconbar();
     	file = new Filehandling();
-    	//bluetooth = new ComWriter();
+    	bluetooth = new ComWriter();
     	remote = new Remote(new AfstandbedieningPanel(bluetooth));
-    	remote.dispose();
-    	
     	
     	setLayout(new BorderLayout(0,0));
     	add(menubar, BorderLayout.NORTH);
     	add(routeSplitpane);
-    	add(iconbar, BorderLayout.SOUTH);
-    	add(iconbar, BorderLayout.SOUTH);
-    	
-    	currentRouteCoordinates = new ArrayList<ArrayList<Integer>>();
-    	currentRouteSteps = new ArrayList<Character>();    	
-    	
-    	
+    	add(iconbar, BorderLayout.SOUTH);	
     	menubarMouseListeners();	
     	
     	currentRouteFile = "";
+    	startup = true;
     	iconbar.currentroute.setText("Geen bestand");  
     	menubar.menu_file.opslaan.setEnabled(false);
-    	menubar.menu_file.opslaanals.setEnabled(false);
+    	menubar.menu_file.opslaanals.setEnabled(false);  
+    	
+    	Thread bt = new Thread(){
+    		public void run(){
+    			char c;
+    			while(true){
+    				try {
+						c = (char) bluetooth.getInput().read();
+						if(c == 'b'){
+							iconbar.setMessage("Botsing gedetecteerd!", 2000);
+						}else if(c == 'g'){
+							iconbar.setMessage("Gat gedetecteerd!", 2000);
+						}else if(c == 'k');
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+    			}
+    		}
+    		
+    	};
+    	bt.start();
+	}
     	
-    	}
  
-
-    
     public String getCurrentRouteFile() {
 		return currentRouteFile;
 	}
     
     //methode om een route in te laden of om een nieuwe route aan te maken.
 	public void setCurrentRouteFile(String route, ArrayList<ArrayList<Integer>> tempcorarray ){
-		int c = JOptionPane.showConfirmDialog(null, "Weet u zeker dat u de huidige route wilt afsluiten?", "Alert: " + "Weet u het zeker?", JOptionPane.YES_NO_OPTION);  
+		int c;
+		if(startup){
+			c = 0;
+			startup = false;
+		}else{
+			c = JOptionPane.showConfirmDialog(null, "Weet u zeker dat u de huidige route wilt afsluiten?", "Alert: " + "Weet u het zeker?", JOptionPane.YES_NO_OPTION);  
+		}
     	if (c == JOptionPane.YES_OPTION) {
 	        	if(tempcorarray != null){	
-	        		maxx = tempcorarray.get(0).get(0);
-	        		maxy = tempcorarray.get(0).get(1);
-		        	routeSplitpane.rightpanel.setGridsize(maxx, maxy);
+	        		// route openen via bestand
+	        		int maxx = tempcorarray.get(0).get(0);
+	        		int maxy = tempcorarray.get(0).get(1);
+
 		    		iconbar.currentGridSize.setText( maxx + " x " + maxy);
-		        	tempcorarray.remove(0);
-		        	currentRouteCoordinates = tempcorarray;
+		        	tempcorarray.remove(0);	
+		        	routeSplitpane.setFieldSize(maxx, maxy, tempcorarray);
 		        	currentRouteFile = route;
 		    		iconbar.currentroute.setText(currentRouteFile);
 		        	menubar.menu_file.opslaan.setEnabled(true);
 		        	menubar.menu_file.opslaanals.setEnabled(true);
 	  	  	  }else{
+	  	  		  // Geen route ingeladen, nieuwe route openen
 	  	  		int[] tempsize = sizePopup();
 	  	  		if(tempsize != null){
-			  	 	routeSplitpane.rightpanel.setGridsize(tempsize[0], tempsize[1]);
+			  	 	routeSplitpane.setFieldSize(tempsize[0], tempsize[1], new ArrayList<ArrayList<Integer>>());
 		    		iconbar.currentGridSize.setText(tempsize[0] + " x " + tempsize[1]);
-		        	currentRouteCoordinates.clear();
 		        	currentRouteFile = "new";
 		    		iconbar.currentroute.setText("Nieuw bestand");
 		        	menubar.menu_file.opslaan.setEnabled(false);
@@ -144,7 +160,7 @@ public class MainMenu extends JPanel{
 		menubar.menu_file.opslaan.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent arg0) {
-				file.writeRouteFile(maxx, maxy, currentRouteCoordinates, currentRouteFile);				
+				file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, currentRouteFile);				
 			}
 		});
 		menubar.menu_file.opslaanals.addActionListener(new ActionListener() {
@@ -154,7 +170,8 @@ public class MainMenu extends JPanel{
 			      c.setFileFilter(new FileNameExtensionFilter("Route bestanden", "rt"));
 			      int rVal = c.showOpenDialog(MainMenu.this);
 			      if (rVal == JFileChooser.APPROVE_OPTION) {
-			    	  file.writeRouteFile(maxx, maxy, currentRouteCoordinates, c.getSelectedFile().getAbsolutePath());
+			    	  file.writeRouteFile(routeSplitpane.getColumns(), routeSplitpane.getRows(), routeSplitpane.leftpanel.coordinaten, c.getSelectedFile().getAbsolutePath());
+			    	  setCurrentRouteFile(c.getSelectedFile().getAbsolutePath(), file.readRouteFile(c.getSelectedFile().getAbsolutePath()));
 			      }		
 			}
 		});
@@ -171,6 +188,30 @@ public class MainMenu extends JPanel{
 				createRemote();
 			}
 		});
+		routeSplitpane.pauze.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				bluetooth.writeString("p");
+			}
+		});
+		routeSplitpane.hervatten.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				bluetooth.writeString("h");
+			}
+		});
+		routeSplitpane.upload.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				bluetooth.sendRoute(routeSplitpane.leftpanel.steps);
+			}
+		});
+		routeSplitpane.automatisch.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				routeSplitpane.automatischBerekenen(iconbar);
+			}
+		});
     }
 
     public void createRemote(){

+ 68 - 14
gui/panels/RouteSplitpane.java

@@ -1,34 +1,88 @@
 package panels;
 
-import java.awt.Color;
+import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
 
+import javax.swing.JButton;
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
 
-public class RouteSplitpane extends JSplitPane {
-	JPanel leftpanel;
-	RouteSplitpaneCurrentLocation rightpanel;
-	
-	public RouteSplitpane(){
+import customComponents.MapLabel;
+
+public class RouteSplitpane extends JPanel {
+	RouteSplitpaneDisplay rightpanel;
+	RouteSplitpanePlanner leftpanel;
+	private int rows, columns;
+	JButton pauze, hervatten, clear, upload, automatisch;
+	JPanel menubar;
+	   
+	public RouteSplitpane(){	
 		//Linker paneel van de splitPane
-		leftpanel = new JPanel();
-		leftpanel.setBackground(Color.red);
+		leftpanel = new RouteSplitpanePlanner();
 		leftpanel.setMinimumSize(new Dimension(200, 100));
 		
 		//rechter paneel van de splitPane
-		rightpanel = new RouteSplitpaneCurrentLocation();
+		rightpanel = new RouteSplitpaneDisplay();
 		rightpanel.setMinimumSize(new Dimension(200, 100));
+		
 		//aantal opties voor de splitpane
-		this.setResizeWeight(0.5);
-		this.setContinuousLayout(true);
-		Component divider = this.getComponent(2);
+		JSplitPane split = new JSplitPane();
+		split.setResizeWeight(0.5);
+		split.setContinuousLayout(true);
+		Component divider = split.getComponent(2);
 		divider.setCursor(new Cursor(Cursor.HAND_CURSOR));
 
 		//panels toevoegen aan de splitpane
-		this.setLeftComponent(leftpanel);
-		this.setRightComponent(rightpanel);
+		split.setLeftComponent(leftpanel);
+		split.setRightComponent(rightpanel);
+		
+	    menubar = new JPanel(new BorderLayout());
+	   	menubar.setLayout(new GridLayout(1,4));
+		
+	   	menubar.add(automatisch = new JButton("Automatische route"));
+		menubar.add(upload = new JButton("Upload"));
+	   	menubar.add(clear = new JButton("Clear"));
+	   	clear.addActionListener(new ActionListener() {
+			
+			@Override
+			public void actionPerformed(ActionEvent arg0) {
+				rightpanel.refresh();
+				leftpanel.clear();				
+			}
+		});
+	   	menubar.add(pauze = new JButton("Pauze"));
+		menubar.add(hervatten = new JButton("Hervatten"));
+		this.setLayout(new BorderLayout());
+		this.add(split, BorderLayout.CENTER);
+		this.add(menubar, BorderLayout.SOUTH);
+	}
+	public void setFieldSize(int y, int x, ArrayList<ArrayList<Integer>> cor){
+		rightpanel.setGridsize(x, y);
+    	leftpanel.drawField(x, y, cor);
+    	setRows(y);
+    	setColumns(x);
 	}
+	public void automatischBerekenen(Iconbar iconbar){
+		iconbar.setMessage("Zet eerste coordinaat", 0);
+		
+	}
+	public int getRows() {
+		return rows;
+	}
+	public void setRows(int rows) {
+		this.rows = rows;
+	}
+	public int getColumns() {
+		return columns;
+	}
+	public void setColumns(int columns) {
+		this.columns = columns;
+	}	
+	
 }

+ 120 - 0
gui/panels/RouteSplitpaneDisplay.java

@@ -0,0 +1,120 @@
+ package panels;
+import java.awt.BorderLayout;
+import java.awt.GridLayout;
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+import customComponents.Kruispunt;
+/**
+ * Write a description of class BoebotSimGUI here.
+ * 
+ * @author (your name) 
+ * @version (a version number or a date)
+ */
+public class RouteSplitpaneDisplay extends JPanel
+{
+   private ArrayList<ArrayList<Kruispunt>> map;
+   private int teller = -1;
+   private int ox;
+   private int oy;
+   private int orotation;
+   private int y;
+   private int x;
+   private int xx;
+   private int xy;
+   private int xrotation;
+   private int ex;
+   private int ey;
+   private JPanel content;
+   JButton pauze, hervatten;
+   JPanel menubar;
+   
+   public RouteSplitpaneDisplay()
+   {
+       content = new JPanel(new GridLayout(1,1));
+       menubar = new JPanel();
+       map = new ArrayList<ArrayList<Kruispunt>>();
+      
+     menubar.setLayout(new GridLayout(1,4));
+  menubar.add(pauze = new JButton("Pauze"));
+  menubar.add(hervatten = new JButton("Hervatten"));
+  
+       this.setLayout(new BorderLayout());
+       this.add(content, BorderLayout.CENTER);
+       this.add(menubar, BorderLayout.SOUTH);
+   }
+   public void vorigeStapBoebot()
+   {
+       if(teller > 0)
+       {
+           teller --;
+           //ox = boebotSimulator.ax.get(teller);
+           //oy = boebotSimulator.ay.get(teller);
+           //orotation = boebotSimulator.arotation.get(teller);
+           refresh();
+       }
+   }
+   public void volgendeStapBoebot()
+   {
+       if(teller < 0)
+       {
+           teller ++;
+           //ox = boebotSimulator.ax.get(teller);
+           //oy = boebotSimulator.ay.get(teller);
+           //orotation = boebotSimulator.arotation.get(teller);
+           refresh();
+       }
+   }
+   public void refresh()
+   {
+       content.removeAll();
+       content.setLayout(new GridLayout(y, x));
+       map.clear();
+       for(int row = 0; row < y; row ++)
+       {
+           map.add(row, new ArrayList<Kruispunt>());
+           for(int col = 0; col < x; col ++)
+           {
+               map.get(row).add(new Kruispunt());
+               Kruispunt kruispunt = map.get(row).get(col);
+               if(row == (y - ey -1) && col == ex)
+               {
+                   kruispunt.setFinish();
+               }
+               if(row == (y - oy - 1) && col == ox)
+               {
+                   kruispunt.setBoebot(orotation);
+               }
+               if(row == (y - xy -1) && col == xx)
+               {
+                   kruispunt.setGat(xrotation);
+               }
+               content.add(kruispunt);
+           }
+       }
+   }
+   public void setGridsize(int x, int y){
+    this.x = x;
+    this.y = y;
+    refresh();
+   }
+   public void setBoebot(int x,  int y, int o){
+    ox = x;
+    oy = y;
+    orotation = o;
+    refresh();
+   }
+   public void setGat(int x, int y, int o){
+	   xx = x;
+	   xy = y;
+	   xrotation = o;
+	   refresh();
+   }
+   public void setFinish(int x, int y){
+	   ex= x;
+	   ey = y;
+	   refresh();
+   }
+}

+ 197 - 0
gui/panels/RouteSplitpanePlanner.java

@@ -0,0 +1,197 @@
+package panels;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+
+import javax.swing.JPanel;
+import javax.xml.stream.events.Characters;
+
+import customComponents.MapLabel;
+
+public class RouteSplitpanePlanner extends JPanel{
+	
+	private int rows, columns;
+	private ArrayList<ArrayList<MapLabel>> labels = new ArrayList<ArrayList<MapLabel>>();
+	ArrayList<ArrayList<Integer>> coordinaten;
+	private ArrayList<ArrayList<MapLabel>> lines = new ArrayList<ArrayList<MapLabel>>();
+	ArrayList<Character> steps = new ArrayList<Character>();
+	private boolean automatisch;
+	private int orientation;
+	
+	public RouteSplitpanePlanner(){
+		setLayout(new FlowLayout());
+		coordinaten = new ArrayList<ArrayList<Integer>>();
+		automatisch = false;
+		orientation = 0;
+	}
+
+	public void drawField(int c, int r, ArrayList<ArrayList<Integer>> cor){
+		clear();
+		coordinaten = cor;
+		this.rows = r + 1;
+		this.columns = c + 1;
+	    for(int h = 0; h < rows -1; h++){
+	    	labels.add(new ArrayList<MapLabel>());
+	    	for(int v = 0; v < columns -1 ; v++){	
+	    		labels.get(h).add(new MapLabel(0 ,0, h, v));
+	    	}
+	    }
+	    
+	    
+		for(ArrayList<MapLabel> row : labels){
+			for(final MapLabel label : row){
+				add(label);
+				label.addMouseListener(new MouseAdapter() {
+					@Override
+					public void mouseClicked(MouseEvent e) {
+						if(automatisch){
+							
+						}else{
+							if(!label.isSelected() && e.getButton() == e.BUTTON1){
+								if(coordinaten.size() == 0){
+									label.isSelected(true);
+									coordinaten.add(new ArrayList<Integer>());
+									coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
+									coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
+								}else if(checkInRange(label.getXcoord(), label.getYcoord())){
+									label.isSelected(true);
+									coordinaten.add(new ArrayList<Integer>());
+									coordinaten.get(coordinaten.size()-1).add(label.getXcoord());
+									coordinaten.get(coordinaten.size()-1).add(label.getYcoord());
+									
+									lines.add(new ArrayList<MapLabel>());
+									lines.get(lines.size()-1).add(labels.get(coordinaten.get(coordinaten.size()-2).get(0)).get(coordinaten.get(coordinaten.size()-2).get(1)));
+									lines.get(lines.size()-1).add(label);
+									repaint();
+								}
+							}else if(label.isSelected() && e.getButton() == e.BUTTON3){
+								if(coordinaten.size() > 1){
+									if(label.getXcoord() == coordinaten.get(coordinaten.size()-1).get(0) && label.getYcoord() == coordinaten.get(coordinaten.size()-1).get(1) ){
+										lines.remove(lines.size() -1);
+										coordinaten.remove(coordinaten.size() -1);
+										label.isSelected(false);	
+										repaint();
+									}
+								}
+							}
+						}
+					}
+				});
+			}
+		}
+		boolean first = true;
+		for(int i = 0; i < coordinaten.size(); i++){
+			MapLabel label = labels.get(coordinaten.get(i).get(0)).get(coordinaten.get(i).get(1));
+			label.isSelected(true);
+			if(!first){
+				lines.add(new ArrayList<MapLabel>());
+				lines.get(lines.size()-1).add(labels.get(coordinaten.get(i-1).get(0)).get(coordinaten.get(i-1).get(1)));
+				lines.get(lines.size()-1).add(label);
+			}
+			first = false;
+		}
+		repaint();
+	}
+	
+	
+	public void paintComponent(Graphics g){
+		super.paintComponent(g);
+	    Graphics2D graphics = (Graphics2D) g;
+	    graphics.setStroke(new BasicStroke(3));
+	    if( rows > 0 && columns > 0){
+		    int rowheight = getHeight()/rows + 1;
+		    int columnwidth = getWidth()/columns + 1; 
+		    int x = 0;
+		    int y = rowheight;
+		    
+			for(ArrayList<MapLabel> row : labels){
+				for(final MapLabel label : row){
+					label.setSize(x += columnwidth, y,  5, 5);
+				}
+				x = 0;
+				y += rowheight;
+			}
+			x = y = 0;
+		    for(int i = 1; i <= rows + 1 ; i++){
+		    	graphics.drawLine(0, y += rowheight, getWidth(), y);
+		    }
+		    for(int i = 1; i <= columns + 1; i++){
+		    	graphics.drawLine(x += columnwidth, 0, x, getHeight());
+		    }
+		    
+		    graphics.setColor(new Color(255,0,0));
+		    for(ArrayList<MapLabel> labels: lines){
+		    	graphics.drawLine(labels.get(0).getX1(), labels.get(0).getY1(), labels.get(1).getX1(), labels.get(1).getY1());
+		    }
+	    }
+	}
+	
+	public void clear(){
+		for(ArrayList<MapLabel> row : labels){
+			for(MapLabel label : row){
+				label.isSelected(false);
+			}
+		}
+		lines.clear();
+		coordinaten.clear();
+		steps.clear();
+		orientation = 0;
+		repaint();
+	}
+	
+	public boolean checkInRange(int x, int y){
+		int currentx = coordinaten.get(coordinaten.size() -1).get(0);
+		int currenty = coordinaten.get(coordinaten.size() -1).get(1);
+
+		if(currenty == y ){
+			if(currentx + 1 == x){
+				setStep("down");
+				return true;
+			}else if(currentx - 1 == x){
+				setStep("up");
+				return true;
+			}
+		}else if(currentx == x){
+			if(currenty + 1 == y){
+				setStep("right");
+				return true;
+			}else if(currenty - 1 == y){
+				setStep("left");
+				return true;
+			}
+		}
+		return false;
+	}
+
+	public void setStep(String orient){
+		
+	}
+	public void setOrientation(int o){
+        orientation += o;
+        if (orientation == 360)
+        {
+            orientation = 0;
+        }else if(orientation == 450)
+        {
+            orientation = 90;
+        }
+		
+	}
+	public boolean isAutomatisch() {
+		return automatisch;
+	}
+
+	public void setAutomatisch(boolean automatisch) {
+		this.automatisch = automatisch;
+		
+	}
+	
+	
+
+}

+ 1 - 0
gui/pictures/boebot.png