Advertisement
Guest User

Untitled

a guest
May 21st, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. class NewLocation2 implements EventHandler<MouseEvent> {
  2. public void handle(MouseEvent event) {
  3. String temp = "";
  4. display.setCursor(Cursor.DEFAULT);
  5. if (listView.getSelectionModel().isEmpty()) {
  6. color = Color.BLACK;
  7. temp = "none";
  8. } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("bus")) {
  9. color = Color.RED;
  10. temp = "Bus";
  11. } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("underground")) {
  12. color = Color.BLUE;
  13. temp = "underground";
  14. } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("train")) {
  15. color = Color.GREEN;
  16. temp = "train";
  17. }
  18. if (namnBtn.isSelected()) {
  19. String type = "Named";
  20. NamedPlaceAlert nameAlert = new NamedPlaceAlert();
  21. Optional<ButtonType> nameResult = nameAlert.showAndWait();
  22. if (nameAlert.getName().isEmpty()) {
  23. String unnamed = "Unnamed";
  24. nameAlert.setName(unnamed);
  25. }
  26. if (xCoordinate.containsKey(event.getX()) && yCoordinate.containsKey(event.getY())) {
  27. Set<Place> places = xCoordinate.get(event.getX());
  28. if (!places.isEmpty()) {
  29. Alert msg = new Alert(Alert.AlertType.ERROR, "Place already exists on given coordinates");
  30. }
  31. } else if (nameResult.isPresent() && nameResult.get() == ButtonType.OK) {
  32.  
  33. triangle = new NamedPlace(event.getX() - 15, event.getY() - 30, color, false, nameAlert.getName(),
  34. temp, type);
  35. center.getChildren().add(triangle);
  36. triangles.add(triangle);
  37. String namn = triangle.getName();
  38.  
  39. Set<Place> nPlaces = alla.get(namn);
  40. if (nPlaces == null) {
  41. nPlaces = new HashSet<>();
  42. alla.put(namn, nPlaces);
  43. }
  44. Set<Place> xPlaces = xCoordinate.get(triangle.getX());
  45. if (xPlaces == null) {
  46. xPlaces = new HashSet<>();
  47. xCoordinate.put(triangle.getX(), xPlaces);
  48. }
  49. Set<Place> yPlaces = yCoordinate.get(triangle.getY());
  50. if (yPlaces == null) {
  51. yPlaces = new HashSet<>();
  52. yCoordinate.put(triangle.getY(), yPlaces);
  53. }
  54. xPlaces.add(triangle);
  55. yPlaces.add(triangle);
  56. nPlaces.add(triangle);
  57.  
  58. changed = true;
  59. }
  60. display.removeEventHandler(MouseEvent.MOUSE_CLICKED, newLocation2);
  61. newBtn.setDisable(false);
  62.  
  63. } else if (describedBtn.isSelected()) {
  64. String type = "Described";
  65. DescribedPlaceAlert describedAlert = new DescribedPlaceAlert();
  66. Optional<ButtonType> describedResult = describedAlert.showAndWait();
  67. if (describedAlert.getName().isEmpty()) {
  68. String unnamed = "Unnamed";
  69. describedAlert.setName(unnamed);
  70. }
  71. if (describedAlert.getDescription().isEmpty()) {
  72. String unnamed = "No Description";
  73. describedAlert.setDesc(unnamed);
  74. }
  75. if (xCoordinate.containsKey(event.getX()) && yCoordinate.containsKey(event.getY())) {
  76. Set<Place> places = xCoordinate.get(event.getX());
  77. if (!places.isEmpty()) {
  78. Alert msg = new Alert(Alert.AlertType.ERROR, "Place already exists on given coordinates");
  79. }
  80. } else if (describedResult.isPresent() && describedResult.get() == ButtonType.OK) {
  81.  
  82. triangle = new DescribedPlace(event.getX() - 15, event.getY() - 30, color, false,
  83. describedAlert.getName(), temp, type, describedAlert.getDescription());
  84. center.getChildren().add(triangle);
  85. triangles.add(triangle);
  86. String namn = triangle.getName();
  87. Set<Place> nPlaces = alla.get(namn);
  88. if (nPlaces == null) {
  89. nPlaces = new HashSet<>();
  90. alla.put(namn, nPlaces);
  91. }
  92. Set<Place> xPlaces = xCoordinate.get(triangle.getX());
  93. if (xPlaces == null) {
  94. xPlaces = new HashSet<>();
  95. xCoordinate.put(triangle.getX(), xPlaces);
  96. }
  97. Set<Place> yPlaces = yCoordinate.get(triangle.getY());
  98. if (yPlaces == null) {
  99. yPlaces = new HashSet<>();
  100. yCoordinate.put(triangle.getY(), yPlaces);
  101. }
  102. xPlaces.add(triangle);
  103. yPlaces.add(triangle);
  104. nPlaces.add(triangle);
  105.  
  106. changed = true;
  107. }
  108. display.removeEventHandler(MouseEvent.MOUSE_CLICKED, newLocation2);
  109. newBtn.setDisable(false);
  110.  
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement