RouteSplitpaneDisplay.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package panels;
  2. import java.awt.BorderLayout;
  3. import java.awt.GridLayout;
  4. import java.util.ArrayList;
  5. import javax.swing.JButton;
  6. import javax.swing.JPanel;
  7. import customComponents.Kruispunt;
  8. /**
  9. * Write a description of class BoebotSimGUI here.
  10. *
  11. * @author (your name)
  12. * @version (a version number or a date)
  13. */
  14. public class RouteSplitpaneDisplay extends JPanel
  15. {
  16. private ArrayList<ArrayList<Kruispunt>> map;
  17. private int teller = -1;
  18. private int ox;
  19. private int oy;
  20. private int orotation;
  21. private int y;
  22. private int x;
  23. private int xx;
  24. private int xy;
  25. private int xrotation;
  26. private int ex;
  27. private int ey;
  28. private JPanel content;
  29. public RouteSplitpaneDisplay()
  30. {
  31. content = new JPanel(new GridLayout(1,1));
  32. map = new ArrayList<ArrayList<Kruispunt>>();
  33. this.setLayout(new BorderLayout());
  34. this.add(content, BorderLayout.CENTER);
  35. }
  36. public void vorigeStapBoebot()
  37. {
  38. if(teller > 0)
  39. {
  40. teller --;
  41. //ox = boebotSimulator.ax.get(teller);
  42. //oy = boebotSimulator.ay.get(teller);
  43. //orotation = boebotSimulator.arotation.get(teller);
  44. refresh();
  45. }
  46. }
  47. public void volgendeStapBoebot()
  48. {
  49. if(teller < 0)
  50. {
  51. teller ++;
  52. //ox = boebotSimulator.ax.get(teller);
  53. //oy = boebotSimulator.ay.get(teller);
  54. //orotation = boebotSimulator.arotation.get(teller);
  55. refresh();
  56. }
  57. }
  58. public void refresh()
  59. {
  60. content.removeAll();
  61. content.setLayout(new GridLayout(y, x));
  62. map.clear();
  63. for(int row = 0; row < y; row ++)
  64. {
  65. map.add(row, new ArrayList<Kruispunt>());
  66. for(int col = 0; col < x; col ++)
  67. {
  68. map.get(row).add(new Kruispunt());
  69. Kruispunt kruispunt = map.get(row).get(col);
  70. if(row == (ey - 1 ) && col == ex)
  71. {
  72. kruispunt.setFinish();
  73. }
  74. if(row == (oy - 1) && col == ox)
  75. {
  76. kruispunt.setBoebot(orotation);
  77. }
  78. if(row == (xy -1) && col == xx)
  79. {
  80. kruispunt.setGat(xrotation);
  81. }
  82. content.add(kruispunt);
  83. }
  84. }
  85. this.add(content);
  86. this.revalidate();
  87. this.repaint();
  88. }
  89. public void clear(){
  90. ox = oy = xx = xy = ex = ey = -1;
  91. System.out.println("test");
  92. refresh();
  93. }
  94. public void setGridsize(int x, int y){
  95. this.x = x;
  96. this.y = y;
  97. refresh();
  98. }
  99. public void setBoebot(int x, int y, int o){
  100. ox = x;
  101. oy = y+1;
  102. orotation = o;
  103. refresh();
  104. }
  105. public void setGat(int x, int y, int o){
  106. xx = x;
  107. xy = y + 1;
  108. xrotation = o;
  109. refresh();
  110. }
  111. public void setFinish(int x, int y){
  112. ex= x;
  113. ey = y + 1;
  114. refresh();
  115. }
  116. }