|
@@ -1,26 +1,24 @@
|
|
|
package panels;
|
|
package panels;
|
|
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
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 java.awt.GridLayout;
|
|
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
|
|
+import java.text.NumberFormat;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
|
|
-import javax.activation.UnsupportedDataTypeException;
|
|
|
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JFileChooser;
|
|
|
|
|
+import javax.swing.JFormattedTextField;
|
|
|
|
|
+import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
+import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
|
+import javax.swing.text.NumberFormatter;
|
|
|
|
|
|
|
|
-import windows.Remote;
|
|
|
|
|
-import menubar.Menu_file;
|
|
|
|
|
import menubar.Menubar;
|
|
import menubar.Menubar;
|
|
|
|
|
+import windows.Remote;
|
|
|
import customComponents.ComWriter;
|
|
import customComponents.ComWriter;
|
|
|
|
|
+import customComponents.Filehandling;
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MainMenu extends JPanel{
|
|
public class MainMenu extends JPanel{
|
|
@@ -28,191 +26,149 @@ public class MainMenu extends JPanel{
|
|
|
RouteSplitpane routeSplitpane;
|
|
RouteSplitpane routeSplitpane;
|
|
|
Iconbar iconbar;
|
|
Iconbar iconbar;
|
|
|
ComWriter bluetooth;
|
|
ComWriter bluetooth;
|
|
|
- String currentRouteFile;
|
|
|
|
|
Remote remote;
|
|
Remote remote;
|
|
|
- char[] currentRoute;
|
|
|
|
|
-
|
|
|
|
|
- final static Charset ENCODING = StandardCharsets.UTF_8;
|
|
|
|
|
|
|
+ Filehandling file;
|
|
|
|
|
|
|
|
|
|
+ String currentRouteFile;
|
|
|
|
|
+ int maxx, maxy;
|
|
|
|
|
+ ArrayList<ArrayList<Integer>> currentRouteCoordinates;
|
|
|
|
|
+ ArrayList<Character> currentRouteSteps;
|
|
|
|
|
|
|
|
- public MainMenu(){
|
|
|
|
|
|
|
+ public MainMenu(){
|
|
|
menubar = new Menubar();
|
|
menubar = new Menubar();
|
|
|
routeSplitpane = new RouteSplitpane();
|
|
routeSplitpane = new RouteSplitpane();
|
|
|
iconbar = new Iconbar();
|
|
iconbar = new Iconbar();
|
|
|
- bluetooth = new ComWriter();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ file = new Filehandling();
|
|
|
|
|
+ //bluetooth = new ComWriter();
|
|
|
remote = new Remote(new AfstandbedieningPanel(bluetooth));
|
|
remote = new Remote(new AfstandbedieningPanel(bluetooth));
|
|
|
remote.dispose();
|
|
remote.dispose();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
setLayout(new BorderLayout(0,0));
|
|
setLayout(new BorderLayout(0,0));
|
|
|
add(menubar, BorderLayout.NORTH);
|
|
add(menubar, BorderLayout.NORTH);
|
|
|
add(routeSplitpane);
|
|
add(routeSplitpane);
|
|
|
add(iconbar, BorderLayout.SOUTH);
|
|
add(iconbar, BorderLayout.SOUTH);
|
|
|
- currentRouteFile = "Nieuwe route";
|
|
|
|
|
- iconbar.currentroute.setText("Nieuwe route");
|
|
|
|
|
- menubarMouseListeners();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ add(iconbar, BorderLayout.SOUTH);
|
|
|
|
|
+
|
|
|
|
|
+ currentRouteCoordinates = new ArrayList<ArrayList<Integer>>();
|
|
|
|
|
+ currentRouteSteps = new ArrayList<Character>();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ menubarMouseListeners();
|
|
|
|
|
+
|
|
|
|
|
+ currentRouteFile = "";
|
|
|
|
|
+ iconbar.currentroute.setText("Geen bestand");
|
|
|
|
|
+ menubar.menu_file.opslaan.setEnabled(false);
|
|
|
|
|
+ menubar.menu_file.opslaanals.setEnabled(false);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public String getCurrentRouteFile() {
|
|
public String getCurrentRouteFile() {
|
|
|
return currentRouteFile;
|
|
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);
|
|
|
|
|
|
|
+ //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);
|
|
|
|
|
+ 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);
|
|
|
|
|
+ iconbar.currentGridSize.setText( maxx + " x " + maxy);
|
|
|
|
|
+ tempcorarray.remove(0);
|
|
|
|
|
+ currentRouteCoordinates = tempcorarray;
|
|
|
|
|
+ currentRouteFile = route;
|
|
|
|
|
+ iconbar.currentroute.setText(currentRouteFile);
|
|
|
|
|
+ menubar.menu_file.opslaan.setEnabled(true);
|
|
|
|
|
+ menubar.menu_file.opslaanals.setEnabled(true);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ int[] tempsize = sizePopup();
|
|
|
|
|
+ if(tempsize != null){
|
|
|
|
|
+ routeSplitpane.rightpanel.setGridsize(tempsize[0], tempsize[1]);
|
|
|
|
|
+ iconbar.currentGridSize.setText(tempsize[0] + " x " + tempsize[1]);
|
|
|
|
|
+ currentRouteCoordinates.clear();
|
|
|
|
|
+ currentRouteFile = "new";
|
|
|
|
|
+ iconbar.currentroute.setText("Nieuw bestand");
|
|
|
|
|
+ menubar.menu_file.opslaan.setEnabled(false);
|
|
|
|
|
+ menubar.menu_file.opslaanals.setEnabled(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //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());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //popup om de grootte van het veld in te voeren.
|
|
|
|
|
+ public int[] sizePopup(){
|
|
|
|
|
+ NumberFormatter formatter = new NumberFormatter(NumberFormat.getInstance());
|
|
|
|
|
+ formatter.setValueClass(Integer.class);
|
|
|
|
|
+ formatter.setMinimum(0);
|
|
|
|
|
+ formatter.setMaximum(40);
|
|
|
|
|
+ formatter.setCommitsOnValidEdit(true);
|
|
|
|
|
|
|
|
- //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);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ JFormattedTextField field1 = new JFormattedTextField(formatter);
|
|
|
|
|
+ JFormattedTextField field2 = new JFormattedTextField(formatter);
|
|
|
|
|
+
|
|
|
|
|
+ JPanel panel = new JPanel(new GridLayout(0, 1));
|
|
|
|
|
+ panel.add(new JLabel("Hoogte:"));
|
|
|
|
|
+ panel.add(field1);
|
|
|
|
|
+ panel.add(new JLabel("Breedte:"));
|
|
|
|
|
+ panel.add(field2);
|
|
|
|
|
+ int result = JOptionPane.showConfirmDialog(null, panel, "Veld grootte", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
|
|
+ if (result == JOptionPane.OK_OPTION) {
|
|
|
|
|
+ if(field1.getValue() == null || field2.getValue() == null){
|
|
|
|
|
+ JOptionPane.showMessageDialog(null, "Ongeldige grootte");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return new int[]{(int) field1.getValue(),(int) field2.getValue()} ;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void menubarMouseListeners(){
|
|
public void menubarMouseListeners(){
|
|
|
//maakt de mouse listners voor de menubar
|
|
//maakt de mouse listners voor de menubar
|
|
|
- menubar.menu_file.openen.addMouseListener(new MouseListener() {
|
|
|
|
|
|
|
+ menubar.menu_file.openen.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@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("");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
|
+ JFileChooser c = new JFileChooser();
|
|
|
|
|
+ c.setFileFilter(new FileNameExtensionFilter("Route bestanden", "rt"));
|
|
|
|
|
+ int rVal = c.showOpenDialog(MainMenu.this);
|
|
|
|
|
+ if (rVal == JFileChooser.APPROVE_OPTION) {
|
|
|
|
|
+ setCurrentRouteFile(c.getSelectedFile().getAbsolutePath(), file.readRouteFile(c.getSelectedFile().getAbsolutePath()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- @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
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ menubar.menu_file.opslaan.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
|
|
- // TODO Auto-generated method stub
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public void actionPerformed(ActionEvent arg0) {
|
|
|
|
|
+ file.writeRouteFile(maxx, maxy, currentRouteCoordinates, currentRouteFile);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- menubar.menu_file.nieuw.addMouseListener(new MouseListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void mouseReleased(MouseEvent e) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- @Override
|
|
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
|
|
- setCurrentRouteFile("Nieuwe route");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ menubar.menu_file.opslaanals.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void mouseExited(MouseEvent e) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- @Override
|
|
|
|
|
- public void mouseEntered(MouseEvent e) {
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- @Override
|
|
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public void actionPerformed(ActionEvent arg0) {
|
|
|
|
|
+ JFileChooser c = new JFileChooser();
|
|
|
|
|
+ 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());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- iconbar.irremote.addMouseListener(new MouseListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void mouseReleased(MouseEvent e) {
|
|
|
|
|
- // TODO Auto-generated method stub
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ menubar.menu_file.nieuw.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@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
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
|
+ setCurrentRouteFile("Nieuwe route", null);
|
|
|
}
|
|
}
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ iconbar.irremote.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void mouseClicked(MouseEvent e) {
|
|
|
|
|
- // TODO Auto-generated method stub
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
|
+ createRemote();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -221,7 +177,7 @@ public class MainMenu extends JPanel{
|
|
|
if(remote.isShowing()){
|
|
if(remote.isShowing()){
|
|
|
remote.dispose();
|
|
remote.dispose();
|
|
|
}else{
|
|
}else{
|
|
|
- remote.show();
|
|
|
|
|
|
|
+ remote.show(true);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|