jancoow hace 11 años
padre
commit
300f2094fe

+ 79 - 0
gui/customComponents/ComWriter.java

@@ -0,0 +1,79 @@
+package customComponents;
+
+import gnu.io.CommPortIdentifier;
+import gnu.io.NoSuchPortException;
+import gnu.io.PortInUseException;
+import gnu.io.SerialPort;
+import gnu.io.UnsupportedCommOperationException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+// Com1Writer.java 1.1 12/02/22  voor BlueJ omgeving
+// @author Jan Woolderink
+// @author Johan Talboom
+// @version 24/12/13
+//
+
+public class ComWriter
+{
+    private CommPortIdentifier portId;
+    private static SerialPort serialPort;
+    private OutputStream outputStream;
+    private InputStream inputStream;
+
+    public ComWriter() 
+    {
+        initCom();
+    }
+    
+    private void initCom() 
+    {
+        try 
+        {
+            portId = CommPortIdentifier.getPortIdentifier("/dev/rfcomm0");
+        } catch (NoSuchPortException e) { e.printStackTrace(); }
+     
+        try 
+        {
+            serialPort = (SerialPort) portId.open("SimpleWriteApp", 2000);
+        } catch (PortInUseException e) { e.printStackTrace(); }
+     
+        try 
+        {
+            outputStream = serialPort.getOutputStream();
+            inputStream = serialPort.getInputStream();
+        } catch (IOException e) { e.printStackTrace(); }
+
+        try 
+        {
+            serialPort.setSerialPortParams(9600,
+                                           SerialPort.DATABITS_8,
+                                           SerialPort.STOPBITS_1,
+                                           SerialPort.PARITY_NONE);
+        } catch (UnsupportedCommOperationException e) {}
+     
+        System.out.println("COM6: ");
+        System.out.println(serialPort.getBaudRate());
+        System.out.println(serialPort.getDataBits());
+        System.out.println(serialPort.getStopBits());
+    }
+    private void setBaudRate(int baudRate)
+    {
+        int dataBits = serialPort.getDataBits();
+        int stopBits = serialPort.getStopBits();
+        int parity = serialPort.getParity();
+        try 
+        {
+            serialPort.setSerialPortParams(baudRate,dataBits, stopBits, parity);
+        } catch (UnsupportedCommOperationException e) 
+            {System.out.println("Onbekende baudrate");}
+    } 
+    public void writeString(String tekst) 
+    {
+        try 
+        {
+            outputStream.write(tekst.getBytes());
+        } catch (IOException e) {}        
+    }
+}

+ 17 - 16
gui/main/Main.java

@@ -13,22 +13,23 @@ public class Main {
             // Set System L&F
         UIManager.setLookAndFeel(
             UIManager.getSystemLookAndFeelClassName());
-    } 
-    catch (UnsupportedLookAndFeelException e) {
-       // handle exception
-    }
-    catch (ClassNotFoundException e) {
-       // handle exception
-    }
-    catch (InstantiationException e) {
-       // handle exception
-    }
-    catch (IllegalAccessException e) {
-       // handle exception
-    }
-
-		new MainFrame(new MainMenu());
+	    } 
+	    catch (UnsupportedLookAndFeelException e) {
+	       // handle exception
+	    }
+	    catch (ClassNotFoundException e) {
+	       // handle exception
+	    }
+	    catch (InstantiationException e) {
+	       // handle exception
+	    }
+	    catch (IllegalAccessException e) {
+	       // handle exception
+	    }
 	
-	}
+	    
+		new MainFrame(new MainMenu());
+		
+		}
 
 }

+ 46 - 6
gui/menubar/Menu_file.java

@@ -1,21 +1,61 @@
 package menubar;
 
+import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
+import javax.swing.KeyStroke;
 
 public class Menu_file extends JMenu {
+	public JMenuItem nieuw, openen, opslaan, opslaanals, afsluiten;
+	
 	public Menu_file(){
+		nieuw = new JMenuItem("Nieuw");
+		openen = new JMenuItem("Openen");
+		opslaan = new JMenuItem("Opslaan");
+		
+		opslaanals = new JMenuItem("Opslaan als");
+		
+		afsluiten = new JMenuItem("Afsluiten");
+		afsluiten.addMouseListener(new MouseListener() {
+			@Override
+			public void mouseReleased(MouseEvent e) {}
+			@Override
+			public void mousePressed(MouseEvent e) {
+				System.exit(0);				
+			}
+			@Override
+			public void mouseClicked(MouseEvent e) {}
+			@Override
+			public void mouseEntered(MouseEvent e) {}
+			@Override
+			public void mouseExited(MouseEvent e) {}
+		});
+		
 		setText("Bestand");
 		addSeparator();
-		add(new JMenuItem("Nieuw"));
-		add(new JMenuItem("Openen"));
+		
+		
+		//keystrokes
+		nieuw.setAccelerator(KeyStroke.getKeyStroke(
+		          KeyEvent.VK_N, ActionEvent.CTRL_MASK));
+		openen.setAccelerator(KeyStroke.getKeyStroke(
+		          KeyEvent.VK_O, ActionEvent.CTRL_MASK));
+		opslaan.setAccelerator(KeyStroke.getKeyStroke(
+		          KeyEvent.VK_S, ActionEvent.CTRL_MASK));
+		afsluiten.setAccelerator(KeyStroke.getKeyStroke(
+		          KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+		
+		add(nieuw);
+		add(openen);
 		addSeparator();
-		add(new JMenuItem("Opslaan"));
-		add(new JMenuItem("Opslaan als"));	
+		add(opslaan);
+		add(opslaanals);	
 		addSeparator();
-		add(new JMenuItem("Afsluiten"));
+		add(afsluiten);
 	}
-
+	public void test(){};
 }

+ 2 - 0
gui/menubar/Menu_help.java

@@ -1,10 +1,12 @@
 package menubar;
 
 import javax.swing.JMenu;
+import javax.swing.JMenuItem;
 
 public class Menu_help extends JMenu{
 	public Menu_help(){
 		setToolTipText("Help menu");
 		setText("Help");
+		add(new JMenuItem("Over brobotRouteplanner"));
 	}
 }

+ 12 - 4
gui/menubar/Menubar.java

@@ -2,15 +2,23 @@ package menubar;
 
 import java.awt.FlowLayout;
 
+import javax.swing.JMenu;
 import javax.swing.JMenuBar;
 import javax.swing.border.EmptyBorder;
 
 public class Menubar extends JMenuBar{
+	public Menu_file menu_file;
+	public Menu_edit menu_edit;
+	public Menu_help menu_help;
 	public Menubar(){
-    	setBorder(new EmptyBorder(0, 15, 0, 15));
+    	menu_file = new Menu_file();
+    	menu_edit = new Menu_edit();
+    	menu_help = new Menu_help();
+		
+		setBorder(new EmptyBorder(0, 15, 0, 15));
 		setLayout(new FlowLayout(80));
-		add(new Menu_file());
-		add(new Menu_edit());
-		add(new Menu_help());
+		add(menu_file);
+		add(menu_edit);
+		add(menu_help);
 	}
 }

+ 141 - 0
gui/panels/AfstandbedieningPanel.java

@@ -0,0 +1,141 @@
+package panels;
+
+import java.awt.Color;
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+
+import customComponents.ComWriter;
+
+public class AfstandbedieningPanel extends JPanel {
+
+	private JSlider slider;
+	private JLabel current;
+	private JPanel richtingPanel;
+	private ComWriter bluetooth;
+	
+	public AfstandbedieningPanel(ComWriter comwriter){
+		super();	
+		this.bluetooth = comwriter;
+		setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
+		
+		richtingPanel = new JPanel(new GridLayout(3,3));
+		richtingPanel.setBackground(Color.BLACK);		
+		add(richtingPanel);
+		String[]naam = {"omhoog","links","stopButton","rechts","omlaag"};
+		ImageIcon[] plaatjes = getPlaatjes(naam);
+		boolean[]array = {false,true,false,
+						  true,true,true,
+						  false,true,false};
+		char[]characters = {'v','l','s','r','a'};
+		
+		makeRichtingPanel(array, characters, plaatjes);
+		
+		
+
+			
+		
+		JPanel sliderPanel = new JPanel();
+		add(sliderPanel);
+		
+		slider = new JSlider(0,100,50);
+		slider.setPaintLabels(true);
+		slider.setPaintTicks(true);
+		slider.setMajorTickSpacing(10);
+		sliderPanel.add(slider);
+		
+		current = new JLabel();
+		current.setText(getCurrentSlider()+"");
+		
+
+		JPanel buttonPanel = new JPanel(new GridLayout(1,4));
+		add(buttonPanel);
+		
+		JButton closeButton = new JButton("Close");
+		
+		buttonPanel.add(closeButton);
+		
+		JButton toevoegen = new JButton("zet snelheid");
+		toevoegen.addActionListener(new ActionListener(){
+
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				System.out.println(getCurrentSlider());
+				
+				
+			}
+			
+		});
+		buttonPanel.add(toevoegen);		
+	}
+	
+	public void setCurrentSlider(int waarde){
+		slider.setValue(waarde);
+		current.setText(waarde+"");
+	}
+	
+	public int getCurrentSlider(){
+		return slider.getValue();
+	}
+	
+	public ImageIcon[] getPlaatjes(String[]naam){
+		ImageIcon[]plaatjes = new ImageIcon[naam.length];
+		
+		for(int n = 0; n < plaatjes.length; n++){
+			plaatjes[n] = new ImageIcon("src/pictures/"+naam[n]+".png");
+		}
+		
+		return plaatjes;
+				
+	}
+	
+	public JButton makeButton(ImageIcon plaatje,final char charac){
+		JButton button = new JButton(plaatje);
+		button.setContentAreaFilled(false);
+		button.setFocusPainted(false);
+		button.addActionListener(new ActionListener(){
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				bluetooth.writeString(""+charac);
+			}
+			
+		});
+		return button;
+	}
+	
+	public JLabel makeLabel(){
+		JLabel label = new JLabel();
+		label.setBackground(getBackground());
+		return label;
+	}
+	
+	public void makeRichtingPanel(boolean[]array,char[]characters,ImageIcon[]plaatjes){
+		int teller = 0;
+		for(boolean check : array){
+			if(check){
+				JButton button = makeButton(plaatjes[teller], characters[teller]);
+				
+				richtingPanel.add(button);
+				teller++;
+			}
+			else{
+				JLabel label = makeLabel();
+				richtingPanel.add(label);
+			}
+		}
+		
+	}
+}
+	
+	
+	
+	
+

+ 13 - 0
gui/panels/Iconbar.java

@@ -1,9 +1,22 @@
 package panels;
 
+import java.awt.GridLayout;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
 
 public class Iconbar extends JPanel {
+	public JButton irremote;
+	public JLabel currentroute;
+		
 	public Iconbar(){
+		currentroute = new JLabel();
+		irremote = new JButton("Afstandsbediening");
 		
+		this.setLayout(new GridLayout(0,5,10,10));
+		this.add(irremote);
+		this.add(currentroute);
 	}
+	
 }

+ 201 - 2
gui/panels/MainMenu.java

@@ -1,28 +1,227 @@
 package panels;
 
 import java.awt.BorderLayout;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
 
+import javax.activation.UnsupportedDataTypeException;
+import javax.swing.JFileChooser;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
+import windows.Remote;
+import menubar.Menu_file;
 import menubar.Menubar;
+import customComponents.ComWriter;
 
 
 public class MainMenu extends JPanel{
 	Menubar menubar;
 	RouteSplitpane routeSplitpane;
 	Iconbar iconbar;
+	ComWriter bluetooth;
+	String currentRouteFile;
+	Remote remote;
+	char[] currentRoute;
+	
+	final static Charset ENCODING = StandardCharsets.UTF_8;
+	
 	
     public MainMenu(){
     	menubar = new Menubar();
     	routeSplitpane = new RouteSplitpane();
     	iconbar = new Iconbar();
-    	
+    	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);
+    	currentRouteFile = "Nieuwe route";
+    	iconbar.currentroute.setText("Nieuwe route");
+    	menubarMouseListeners();
     }
     
-      
+    
+    public String getCurrentRouteFile() {
+		return currentRouteFile;
+	}
+	public void setCurrentRouteFile(String route){
+		int 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) {
+    		currentRouteFile = route;
+    		iconbar.currentroute.setText(route);
+          }
+        }
+    
+    //route uitlezen uit een file en de file controleren
+	public void readRouteFile(String aFileName){
+		Path path = Paths.get(aFileName);
+		try {
+			List<String> routebestand = Files.readAllLines(path, ENCODING);
+			if(routebestand.size() == 0 || !routebestand.get(0).contains("broboticsrouteplanner")){
+				JOptionPane.showConfirmDialog(null, "Route niet geldig!", "Alert: " + "Fout", JOptionPane.INFORMATION_MESSAGE);
+				System.out.println("Route bestand niet geldig!");	
+			}else{
+				setCurrentRouteFile(path.toString());
+				String[] route = routebestand.get(2).split("|");
+				for(String cor:route){
+					System.out.println(cor);
+				}
+				
+			}
+		} catch (IOException e) {
+			JOptionPane.showMessageDialog(null, "Route niet geldig!", "Alert: " + "Fout", JOptionPane.INFORMATION_MESSAGE);
+			System.out.println("Route bestand niet geldig!");
+		}
+	}
+	
+	 //route file schrijven 
+	public void writeRouteFile(List<String> aLines, String aFileName) throws IOException {
+	    Path path = Paths.get(aFileName);
+	    Files.write(path, aLines, ENCODING);
+	}
+	
+	//route verzenden naar de boebot
+	public void sendRoute(char[] route){
+		char[] newroute = new char[route.length + 2];
+		newroute[0] =  '?';
+		for(int i=0; i < route.length; i++){
+			newroute[i+1] = route[i];
+		}
+		newroute[newroute.length] = '?';
+		bluetooth.writeString(route.toString());
+	}
+		
+	//nieuwe routefile aanmaken
+	public void createRouteFile(String filename, List<String> aLines, String aFileName) throws IOException {
+		File file = new File("example.txt");
+		Path path = Paths.get(aFileName);
+	    Files.write(path, aLines, ENCODING);
+	}
+    
+    public void menubarMouseListeners(){
+    	//maakt de mouse listners voor de menubar
+		menubar.menu_file.openen.addMouseListener(new MouseListener() {
+			@Override
+			public void mouseReleased(MouseEvent e) {}
+			@Override
+			public void mousePressed(MouseEvent e) {
+		      JFileChooser c = new JFileChooser();
+		      // Demonstrate "Open" dialog:
+		      int rVal = c.showOpenDialog(MainMenu.this);
+		      if (rVal == JFileChooser.APPROVE_OPTION) {
+		        readRouteFile(c.getSelectedFile().getAbsolutePath());
+		      }
+		      if (rVal == JFileChooser.CANCEL_OPTION) {
+		        //filename.setText("You pressed cancel");
+		        //dir.setText("");
+		      }
+			}
+			@Override
+			public void mouseExited(MouseEvent e) {}
+			@Override
+			public void mouseEntered(MouseEvent e) {}
+			@Override
+			public void mouseClicked(MouseEvent e) {}
+		});
+		menubar.menu_file.opslaan.addMouseListener(new MouseListener() {
+			@Override
+			public void mouseReleased(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			
+			@Override
+			public void mousePressed(MouseEvent e) {
+				if(currentRouteFile == "Nieuwe Route"){
+					
+				}
+			}
+			
+			@Override
+			public void mouseExited(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			
+			@Override
+			public void mouseEntered(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			
+			@Override
+			public void mouseClicked(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+		});
+		menubar.menu_file.nieuw.addMouseListener(new MouseListener() {	
+			@Override
+			public void mouseReleased(MouseEvent e) {
+				
+			}	
+			@Override
+			public void mousePressed(MouseEvent e) {
+				setCurrentRouteFile("Nieuwe route");
+			}
+			@Override
+			public void mouseExited(MouseEvent e) {
+				
+			}
+			@Override
+			public void mouseEntered(MouseEvent e) {
+				
+			}
+			@Override
+			public void mouseClicked(MouseEvent e) {
+				
+			}
+		});
+		iconbar.irremote.addMouseListener(new MouseListener() {
+			@Override
+			public void mouseReleased(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			@Override
+			public void mousePressed(MouseEvent e) {
+		    	createRemote();
+			}
+			@Override
+			public void mouseExited(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			@Override
+			public void mouseEntered(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+			@Override
+			public void mouseClicked(MouseEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+		});
+    }
 
+    public void createRemote(){
+    	if(remote.isShowing()){
+    		remote.dispose();
+    	}else{
+    		remote.show();
+    	}
+    }
 }

BIN
gui/pictures/links.png


BIN
gui/pictures/omhoog.png


BIN
gui/pictures/omlaag.png


BIN
gui/pictures/rechts.png


BIN
gui/pictures/stopButton.png


+ 3 - 0
gui/routes/test.rt

@@ -0,0 +1,3 @@
+broboticsrouteplanner
+Testroute
+2,2|1,2|2,2|2,3

+ 24 - 1
gui/windows/Remote.java

@@ -1,7 +1,30 @@
 package windows;
 
+import java.awt.Dimension;
+
 import javax.swing.JFrame;
+import javax.swing.JPanel;
 
 public class Remote extends JFrame {
-
+	public Remote(JPanel jp){
+		setup();
+		setPane(jp);
+	}
+	public Remote(){
+		setup();
+	}
+	
+	public void setPane(JPanel jp){
+		repaint();
+		this.setContentPane(jp);
+		this.pack();
+	}
+	
+	private void setup(){
+		setTitle("Afstandsbediening");
+        setMinimumSize(new Dimension(257,345));
+        this.setBounds(0, 0, 550, 400);
+        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+		setVisible(true);
+	}
 }