Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NewLocation2 implements EventHandler<MouseEvent> {
- public void handle(MouseEvent event) {
- String temp = "";
- display.setCursor(Cursor.DEFAULT);
- if (listView.getSelectionModel().isEmpty()) {
- color = Color.BLACK;
- temp = "none";
- } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("bus")) {
- color = Color.RED;
- temp = "Bus";
- } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("underground")) {
- color = Color.BLUE;
- temp = "underground";
- } else if (listView.getSelectionModel().getSelectedItem().equalsIgnoreCase("train")) {
- color = Color.GREEN;
- temp = "train";
- }
- if (namnBtn.isSelected()) {
- String type = "Named";
- NamedPlaceAlert nameAlert = new NamedPlaceAlert();
- Optional<ButtonType> nameResult = nameAlert.showAndWait();
- if (nameAlert.getName().isEmpty()) {
- String unnamed = "Unnamed";
- nameAlert.setName(unnamed);
- }
- if (xCoordinate.containsKey(event.getX()) && yCoordinate.containsKey(event.getY())) {
- Set<Place> places = xCoordinate.get(event.getX());
- if (!places.isEmpty()) {
- Alert msg = new Alert(Alert.AlertType.ERROR, "Place already exists on given coordinates");
- }
- } else if (nameResult.isPresent() && nameResult.get() == ButtonType.OK) {
- triangle = new NamedPlace(event.getX() - 15, event.getY() - 30, color, false, nameAlert.getName(),
- temp, type);
- center.getChildren().add(triangle);
- triangles.add(triangle);
- String namn = triangle.getName();
- Set<Place> nPlaces = alla.get(namn);
- if (nPlaces == null) {
- nPlaces = new HashSet<>();
- alla.put(namn, nPlaces);
- }
- Set<Place> xPlaces = xCoordinate.get(triangle.getX());
- if (xPlaces == null) {
- xPlaces = new HashSet<>();
- xCoordinate.put(triangle.getX(), xPlaces);
- }
- Set<Place> yPlaces = yCoordinate.get(triangle.getY());
- if (yPlaces == null) {
- yPlaces = new HashSet<>();
- yCoordinate.put(triangle.getY(), yPlaces);
- }
- xPlaces.add(triangle);
- yPlaces.add(triangle);
- nPlaces.add(triangle);
- changed = true;
- }
- display.removeEventHandler(MouseEvent.MOUSE_CLICKED, newLocation2);
- newBtn.setDisable(false);
- } else if (describedBtn.isSelected()) {
- String type = "Described";
- DescribedPlaceAlert describedAlert = new DescribedPlaceAlert();
- Optional<ButtonType> describedResult = describedAlert.showAndWait();
- if (describedAlert.getName().isEmpty()) {
- String unnamed = "Unnamed";
- describedAlert.setName(unnamed);
- }
- if (describedAlert.getDescription().isEmpty()) {
- String unnamed = "No Description";
- describedAlert.setDesc(unnamed);
- }
- if (xCoordinate.containsKey(event.getX()) && yCoordinate.containsKey(event.getY())) {
- Set<Place> places = xCoordinate.get(event.getX());
- if (!places.isEmpty()) {
- Alert msg = new Alert(Alert.AlertType.ERROR, "Place already exists on given coordinates");
- }
- } else if (describedResult.isPresent() && describedResult.get() == ButtonType.OK) {
- triangle = new DescribedPlace(event.getX() - 15, event.getY() - 30, color, false,
- describedAlert.getName(), temp, type, describedAlert.getDescription());
- center.getChildren().add(triangle);
- triangles.add(triangle);
- String namn = triangle.getName();
- Set<Place> nPlaces = alla.get(namn);
- if (nPlaces == null) {
- nPlaces = new HashSet<>();
- alla.put(namn, nPlaces);
- }
- Set<Place> xPlaces = xCoordinate.get(triangle.getX());
- if (xPlaces == null) {
- xPlaces = new HashSet<>();
- xCoordinate.put(triangle.getX(), xPlaces);
- }
- Set<Place> yPlaces = yCoordinate.get(triangle.getY());
- if (yPlaces == null) {
- yPlaces = new HashSet<>();
- yCoordinate.put(triangle.getY(), yPlaces);
- }
- xPlaces.add(triangle);
- yPlaces.add(triangle);
- nPlaces.add(triangle);
- changed = true;
- }
- display.removeEventHandler(MouseEvent.MOUSE_CLICKED, newLocation2);
- newBtn.setDisable(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement