Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dragging tags outside of component fixed #18

Merged
merged 5 commits into from
Jul 20, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/dk/cs/aau/huppaal/presentations/TagPresentation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dk.cs.aau.huppaal.presentations;

import dk.cs.aau.huppaal.abstractions.Component;
import dk.cs.aau.huppaal.abstractions.Nail;
import dk.cs.aau.huppaal.controllers.CanvasController;
import dk.cs.aau.huppaal.utility.UndoRedoStack;
import dk.cs.aau.huppaal.utility.colors.Color;
Expand All @@ -9,13 +10,16 @@
import javafx.application.Platform;
import javafx.beans.binding.When;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.beans.value.ObservableDoubleValue;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.LineTo;
Expand Down Expand Up @@ -212,6 +216,31 @@ private void initializeShape() {
textField.requestFocus(); // This needs to be done twice because of reasons
}

Node parent;

if(getParent() instanceof NailPresentation){
//Get the correct parent for guards, selects, synchronizations, and updates
parent = getParent();
} else {
//Gte the correct parent for location names
parent = getParent().getParent();
}

//Handle the horizontal placement of the tag
if(parent.localToParent(getBoundsInParent()).getCenterX() > getComponent().widthProperty().doubleValue() - textField.getWidth()) {
setTranslateX(getTranslateX() + getComponent().widthProperty().doubleValue() - textField.getWidth() - parent.localToParent(getBoundsInParent()).getCenterX());
} else if (parent.localToParent(getBoundsInParent()).getCenterX() - textField.getWidth() < 0) {
setTranslateX(getTranslateX() - (parent.localToParent(getBoundsInParent()).getCenterX() - textField.getWidth()));
}

//Handle the vertical placement of the tag
if(parent.localToParent(getBoundsInParent()).getCenterY() > getComponent().heightProperty().doubleValue() - textField.getHeight()) {
setTranslateY(getTranslateY() + getComponent().heightProperty().doubleValue() - textField.getHeight() - parent.localToParent(getBoundsInParent()).getCenterY());
} else if (parent.localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2 < 0) {
setTranslateY(getTranslateY() - (parent.localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2));
}


});

textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
Expand Down