Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. public class GUIAppointment extends Rectangle {
  2.  
  3. private String customer, service, employee, datetime, price, duration;
  4. private Appointment appointment;
  5. private int r, g, b;
  6. private Color[] allColors;
  7. private Color c1 = new Color(0.96, 0.31, 0.26, 0.8);
  8. private Color c2 = new Color(0.77, 0.96, 0.26, 0.8);
  9. private Color c3 = new Color(0.26, 0.96, 0.6, 0.8);
  10. private Color c4 = new Color(0.26, 0.58, 0.96, 0.8);
  11. private Color c5 = new Color(0.66, 0.26, 0.96, 0.8);
  12.  
  13. private Color hovc1 = new Color(0.96, 0.31, 0.26, 1);
  14. private Color hovc2 = new Color(0.77, 0.96, 0.26, 1);
  15. private Color hovc3 = new Color(0.26, 0.96, 0.6, 1);
  16. private Color hovc4 = new Color(0.26, 0.58, 0.96, 1);
  17. private Color hovc5 = new Color(0.66, 0.26, 0.96, 1);
  18.  
  19.  
  20. private String date;
  21.  
  22. public GUIAppointment(Appointment appointment) {
  23. this.appointment = appointment;
  24. this.customer = appointment.getCustomer();
  25. this.service = appointment.getService();
  26. this.employee = appointment.getEmployee();
  27. this.datetime = appointment.getTime();
  28. this.price = String.valueOf(appointment.getPrice());
  29. this.duration = String.valueOf(appointment.getDuration());
  30.  
  31. String appDate = appointment.getTime();
  32. String[] parts1 = appDate.split(" ");
  33. String[] parts2 = parts1[0].split("-");
  34. date = parts2[2] + "." + parts2[1] + "." + parts2[0];
  35. }
  36.  
  37. public boolean isRezisable() {
  38. return true;
  39. }
  40.  
  41. public double minWidth(double height) {
  42. return 0.0;
  43. }
  44.  
  45.  
  46. public void compHeight() {
  47. this.setHeight(appointment.getDuration());
  48. }
  49.  
  50. public void compWidth() {
  51. this.setWidth(200);
  52. }
  53.  
  54. public void compColor(Appointment appointment) {
  55. DBConnection dbConnection = new DBConnection();
  56. ObservableList<String> allEmployees = dbConnection.getAllEmployees();
  57.  
  58. int id = appointment.getEmployeeID(appointment.getEmployee());
  59.  
  60. switch(id) {
  61. case 0:
  62. this.setFill(c1);
  63. break;
  64. case 1:
  65. this.setFill(c2);
  66. break;
  67. case 2:
  68. this.setFill(c3);
  69. break;
  70. case 3:
  71. this.setFill(c4);
  72. break;
  73. case 4:
  74. this.setFill(c5);
  75. break;
  76. }
  77. }
  78.  
  79. public Color getColor() {
  80. return (Color) this.getFill();
  81. }
  82.  
  83. public String getDate() {
  84. return date;
  85. }
  86.  
  87. public void selectAnchorPane(Appointment appointment) {
  88. AnchorPane[] apArray = {anchorPane1, anchorPane2, anchorPane3, anchorPane4, anchorPane5};
  89.  
  90. String appDate = appointment.getTime();
  91. String[] parts1 = appDate.split(" ");
  92. String[] parts2 = parts1[0].split("-");
  93. String finalDate = parts2[2] + "." + parts2[1] + "." + parts2[0];
  94.  
  95. String[] compOffset = parts1[1].split(":");
  96. String compOffsetHour = compOffset[0];
  97. String compOffsetMinute = compOffset[1];
  98.  
  99. int finalHour = Integer.parseInt(compOffsetHour);
  100. int finalMinute = Integer.parseInt(compOffsetMinute);
  101.  
  102. double offset = finalHour*60 + finalMinute;
  103.  
  104.  
  105. for(int i = 0; i < 5; i++){
  106.  
  107. if(finalDate.equals(weekDates[i])) {
  108.  
  109. GUIAppointment guiAppointment = new GUIAppointment(appointment);
  110. allGuiAppointments.add(guiAppointment);
  111.  
  112. guiAppointment.compHeight();
  113. guiAppointment.compColor(appointment);
  114. apArray[i].getChildren().add(guiAppointment);
  115. int j = checkCollision(guiAppointment);
  116.  
  117.  
  118. if(j > 1) {
  119. guiAppointment.widthProperty().bind(apArray[i].widthProperty());
  120. apArray[i].setTopAnchor(guiAppointment, offset);
  121. apArray[i].setLeftAnchor(guiAppointment, 0.0);
  122. apArray[i].setRightAnchor(guiAppointment, apArray[i].getWidth() / j);
  123. }
  124. else {
  125. guiAppointment.widthProperty().bind(apArray[i].widthProperty());
  126. apArray[i].setTopAnchor(guiAppointment, offset);
  127. apArray[i].setLeftAnchor(guiAppointment, 0.0);
  128. apArray[i].setRightAnchor(guiAppointment, 0.0);
  129. }
  130.  
  131. }
  132. }
  133. }
  134.  
  135. public int checkCollision(GUIAppointment guiApp) {
  136.  
  137. List<GUIAppointment> sameDateAppointments = new ArrayList<GUIAppointment>();
  138. int i = 0;
  139.  
  140. for(GUIAppointment GUIapp : allGuiAppointments) {
  141. if(guiApp.getDate().equals(GUIapp.getDate())) {
  142. sameDateAppointments.add(GUIapp);
  143. }
  144. }
  145.  
  146. for(GUIAppointment GUIapp : sameDateAppointments) {
  147. if(GUIapp.getBoundsInParent().intersects(guiApp.getBoundsInParent())) {
  148. i++;
  149. }
  150. }
  151.  
  152. System.out.println("[!] " + i);
  153. return i;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement