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 3 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
34 changes: 34 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,9 +10,11 @@
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;
Expand Down Expand Up @@ -212,6 +215,37 @@ private void initializeShape() {
textField.requestFocus(); // This needs to be done twice because of reasons
}

//Handle constraints for guards, selects, synchronizations, and updates
if(getParent() instanceof NailPresentation){
if(getParent().localToParent(getBoundsInParent()).getCenterX() > getComponent().widthProperty().doubleValue() - textField.getWidth()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the two cases are very similar, I think there should be a function (or just extract the object that you work on)

somthing like:
if (getParent() instanof NailPresentation) {
o = getParent()
} else {
o = getParent.getParent()
}

if (o.localToParent(...
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely, must have missed it as I ran through it

setTranslateX(getTranslateX() + getComponent().widthProperty().doubleValue() - textField.getWidth() - getParent().localToParent(getBoundsInParent()).getCenterX());
} else if (getParent().localToParent(getBoundsInParent()).getCenterX() - textField.getWidth() < 0) {
setTranslateX(getTranslateX() - (getParent().localToParent(getBoundsInParent()).getCenterX() - textField.getWidth()));
}

if(getParent().localToParent(getBoundsInParent()).getCenterY() > getComponent().heightProperty().doubleValue() - textField.getHeight()) {
setTranslateY(getTranslateY() + getComponent().heightProperty().doubleValue() - textField.getHeight() - getParent().localToParent(getBoundsInParent()).getCenterY());
} else if (getParent().localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2 < 0) {
setTranslateY(getTranslateY() - (getParent().localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2));
}
}

//Handle constraints for location names
else {
if(getParent().getParent().localToParent(getBoundsInParent()).getCenterX() > getComponent().widthProperty().doubleValue() - textField.getWidth()) {
setTranslateX(getTranslateX() + getComponent().widthProperty().doubleValue() - textField.getWidth() - getParent().getParent().localToParent(getBoundsInParent()).getCenterX());
} else if (getParent().getParent().localToParent(getBoundsInParent()).getCenterX() - textField.getWidth() < 0) {
setTranslateX(getTranslateX() - (getParent().getParent().localToParent(getBoundsInParent()).getCenterX() - textField.getWidth()));
}

if(getParent().getParent().localToParent(getBoundsInParent()).getCenterY() > getComponent().heightProperty().doubleValue() - textField.getHeight()) {
setTranslateY(getTranslateY() + getComponent().heightProperty().doubleValue() - textField.getHeight() - getParent().getParent().localToParent(getBoundsInParent()).getCenterY());
} else if (getParent().getParent().localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2 < 0) {
setTranslateY(getTranslateY() - (getParent().getParent().localToParent(getBoundsInParent()).getCenterY() - textField.getHeight() - GRID_SIZE * 2));
}
}


});

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