|
|
@@ -21,9 +21,14 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
ArrayList<ArrayList<Integer>> coordinaten;
|
|
|
private ArrayList<ArrayList<MapLabel>> lines = new ArrayList<ArrayList<MapLabel>>();
|
|
|
ArrayList<Character> steps = new ArrayList<Character>();
|
|
|
+ ArrayList<ArrayList<Integer>> automatischcor = new ArrayList<ArrayList<Integer>>();
|
|
|
private boolean automatisch;
|
|
|
private int orientation;
|
|
|
|
|
|
+ private int x, y, ex, ey;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public RouteSplitpanePlanner(){
|
|
|
setLayout(new FlowLayout());
|
|
|
coordinaten = new ArrayList<ArrayList<Integer>>();
|
|
|
@@ -31,9 +36,12 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
orientation = 0;
|
|
|
}
|
|
|
|
|
|
- public void drawField(int c, int r, ArrayList<ArrayList<Integer>> cor){
|
|
|
+ public void drawField(int c, int r, ArrayList<ArrayList<Integer>> cor, ArrayList<Character> stappen){
|
|
|
clear();
|
|
|
+ labels.clear();
|
|
|
+ this.removeAll();
|
|
|
coordinaten = cor;
|
|
|
+ this.steps = stappen;
|
|
|
this.rows = r + 1;
|
|
|
this.columns = c + 1;
|
|
|
for(int h = 0; h < rows -1; h++){
|
|
|
@@ -42,7 +50,7 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
labels.get(h).add(new MapLabel(0 ,0, h, v));
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
for(ArrayList<MapLabel> row : labels){
|
|
|
for(final MapLabel label : row){
|
|
|
@@ -50,37 +58,7 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ labelClick(label, e.getButton());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -96,9 +74,68 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
}
|
|
|
first = false;
|
|
|
}
|
|
|
+ revalidate();
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
+ public void labelClick(MapLabel label, int e){
|
|
|
+ if(automatisch){
|
|
|
+ if(automatischcor.size() == 0 ){
|
|
|
+ Iconbar.setMessage("Geef 2e coordinaat", 0);
|
|
|
+ automatischcor.add(new ArrayList<Integer>());
|
|
|
+ automatischcor.get(0).add(rows-label.xcoord-1);
|
|
|
+ automatischcor.get(0).add(label.ycoord);
|
|
|
+ }else{
|
|
|
+ Iconbar.setMessage("Route gegenereerd!", 2000);
|
|
|
+ label.isSelected(true);
|
|
|
+ System.out.println( automatischcor.get(0).get(0));
|
|
|
+ System.out.println( automatischcor.get(0).get(1));
|
|
|
+ System.out.println(label.xcoord);
|
|
|
+ System.out.println(label.ycoord);
|
|
|
+ berekenRoute(label.ycoord, rows-label.xcoord-1, automatischcor.get(0).get(1), automatischcor.get(0).get(0), 0);
|
|
|
+ System.out.println(coordinaten);
|
|
|
+ System.out.println(steps);
|
|
|
+ drawField(columns-1, rows-1, new ArrayList<ArrayList<Integer>>(coordinaten), new ArrayList<Character>(steps));
|
|
|
+
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(e == 0x01){
|
|
|
+ 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());
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(0);
|
|
|
+ }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);
|
|
|
+ setStep();
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+ }else if(label.isSelected() && e == 0x03){
|
|
|
+ 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);
|
|
|
+ orientation = coordinaten.get(coordinaten.size()-1).get(2);
|
|
|
+ steps.remove(steps.size() -1);
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void stepBackwards(){
|
|
|
+ MapLabel label =labels.get(coordinaten.get(coordinaten.size()-1).get(0)).get(coordinaten.get(coordinaten.size()-1).get(1));
|
|
|
+ labelClick(label, 0x03);
|
|
|
+ }
|
|
|
|
|
|
public void paintComponent(Graphics g){
|
|
|
super.paintComponent(g);
|
|
|
@@ -138,10 +175,13 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
label.isSelected(false);
|
|
|
}
|
|
|
}
|
|
|
+ automatisch = false;
|
|
|
lines.clear();
|
|
|
coordinaten.clear();
|
|
|
steps.clear();
|
|
|
orientation = 0;
|
|
|
+ automatischcor.clear();
|
|
|
+ ex = ey = x = y = 0;
|
|
|
repaint();
|
|
|
}
|
|
|
|
|
|
@@ -151,27 +191,188 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
|
|
|
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 setStep(){
|
|
|
+ int last = coordinaten.size() -1;
|
|
|
+ int x1 = coordinaten.get(last-1).get(1);
|
|
|
+ int y1 = rows - coordinaten.get(last-1).get(0) -1;
|
|
|
+ int x2 = coordinaten.get(last).get(1);
|
|
|
+ int y2 = rows - coordinaten.get(last).get(0) - 1;
|
|
|
+
|
|
|
+ if(x1 < x2)
|
|
|
+ {
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ steps.add('v');
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ steps.add('r');
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ steps.add('a');
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ steps.add('l');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(x1 > x2)
|
|
|
+ {
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ steps.add('v');
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ steps.add('l');
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ steps.add('k');
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ steps.add('r');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(y1 < y2)
|
|
|
+ {
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ steps.add('v');
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+
|
|
|
+ steps.add('r');
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+
|
|
|
+ steps.add('a');
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+
|
|
|
+ steps.add('l');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(y1 > y2)
|
|
|
+ {
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ steps.add('v');
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+
|
|
|
+ steps.add('r');
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+
|
|
|
+ steps.add('a');
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+
|
|
|
+ steps.add('l');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(orientation);
|
|
|
+ System.out.println(steps);
|
|
|
}
|
|
|
+
|
|
|
+ public void turnleft()
|
|
|
+ {
|
|
|
+ orientation = orientation - 90;
|
|
|
+ if (orientation < 0)
|
|
|
+ {
|
|
|
+ orientation = 270;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void turnright()
|
|
|
+ {
|
|
|
+ orientation = orientation + 90;
|
|
|
+ if (orientation > 270)
|
|
|
+ {
|
|
|
+ orientation = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void keren()
|
|
|
+ {
|
|
|
+ orientation = orientation + 180;
|
|
|
+ if (orientation == 360)
|
|
|
+ {
|
|
|
+ orientation = 0;
|
|
|
+ }
|
|
|
+ if(orientation == 450)
|
|
|
+ {
|
|
|
+ orientation = 90;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void vooruit()
|
|
|
+ {
|
|
|
+ if (orientation == 0 && y < rows)
|
|
|
+ {
|
|
|
+ y ++;
|
|
|
+ }
|
|
|
+ if (orientation == 90 && x < columns)
|
|
|
+ {
|
|
|
+ x ++;
|
|
|
+ }
|
|
|
+ if (orientation == 180 && y > 0)
|
|
|
+ {
|
|
|
+ y --;
|
|
|
+ }
|
|
|
+ if (orientation == 270 && x > 0)
|
|
|
+ {
|
|
|
+ x --;
|
|
|
+ }
|
|
|
+ coordinaten.add(new ArrayList<Integer>());
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(rows-y-1);
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(x);
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(orientation);
|
|
|
+ }
|
|
|
+ public int getOrientation() {
|
|
|
+ return orientation;
|
|
|
+ }
|
|
|
+
|
|
|
public void setOrientation(int o){
|
|
|
orientation += o;
|
|
|
if (orientation == 360)
|
|
|
@@ -188,10 +389,185 @@ public class RouteSplitpanePlanner extends JPanel{
|
|
|
}
|
|
|
|
|
|
public void setAutomatisch(boolean automatisch) {
|
|
|
+ boolean labelselected = false;
|
|
|
+ for(ArrayList<MapLabel> row:labels){
|
|
|
+ for(MapLabel label1:row){
|
|
|
+ if(label1.isSelected()){
|
|
|
+ labelselected = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(labelselected){
|
|
|
+ Iconbar.setMessage("Zet tweede coordinaat", 0);
|
|
|
+ automatischcor.add(new ArrayList<Integer>());
|
|
|
+ automatischcor.get(0).add(coordinaten.get(coordinaten.size()-1).get(0));
|
|
|
+ automatischcor.get(0).add(coordinaten.get(coordinaten.size()-1).get(1));
|
|
|
+ System.out.println(automatischcor.get(0).get(0));
|
|
|
+ System.out.println(automatischcor.get(0).get(1));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ Iconbar.setMessage("Zet eerste coordinaat", 0);
|
|
|
+ }
|
|
|
this.automatisch = automatisch;
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ public void berekenRoute(int eindx, int eindy, int beginx, int beginy, int rotatie)
|
|
|
+ {
|
|
|
+ coordinaten.add(new ArrayList<Integer>());
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(rows-beginy-1);
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(beginx);
|
|
|
+ coordinaten.get(coordinaten.size()-1).add(rotatie);
|
|
|
+ char[] route = new char[40];
|
|
|
+ int teller = 0;
|
|
|
+ orientation = rotatie;
|
|
|
+ int lengte = 0;
|
|
|
+ if(eindx <= columns && eindy <= rows && eindx >= 0 && eindy >= 0)
|
|
|
+ {
|
|
|
+ ex = eindx;
|
|
|
+ ey = eindy;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+ if(beginx <= columns && beginy <= rows && beginx >= 0 && beginy >= 0)
|
|
|
+ {
|
|
|
+ x = beginx;
|
|
|
+ y = beginy;
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+ while(ex != x)
|
|
|
+ {
|
|
|
+ if(x < ex)
|
|
|
+ {
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ vooruit();
|
|
|
+ steps.add('v');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ vooruit();
|
|
|
+ steps.add('r');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ vooruit();
|
|
|
+ steps.add('k');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ vooruit();
|
|
|
+ steps.add('l');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(x > ex)
|
|
|
+ {
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ vooruit();
|
|
|
+ steps.add('v');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ vooruit();
|
|
|
+ steps.add('l');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ vooruit();
|
|
|
+ steps.add('k');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ vooruit();
|
|
|
+ steps.add('r');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ while(ey != y)
|
|
|
+ {
|
|
|
+ if(y < ey)
|
|
|
+ {
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ vooruit();
|
|
|
+ steps.add('v');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ vooruit();
|
|
|
+ steps.add('r');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ vooruit();
|
|
|
+ steps.add('k');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ vooruit();
|
|
|
+ steps.add('l');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(y > ey)
|
|
|
+ {
|
|
|
+ if(orientation == 180)
|
|
|
+ {
|
|
|
+ vooruit();
|
|
|
+ steps.add('v');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 90)
|
|
|
+ {
|
|
|
+ turnright();
|
|
|
+ vooruit();
|
|
|
+ steps.add('r');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 0)
|
|
|
+ {
|
|
|
+ keren();
|
|
|
+ vooruit();
|
|
|
+ steps.add('k');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ if(orientation == 270)
|
|
|
+ {
|
|
|
+ turnleft();
|
|
|
+ vooruit();
|
|
|
+ steps.add('l');
|
|
|
+ teller ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|