Skip to content

Commit

Permalink
add category instance navigation feature #111
Browse files Browse the repository at this point in the history
  • Loading branch information
JeridiOmar committed Apr 30, 2023
1 parent 3559c52 commit c4e7cd1
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,11 @@ public void onUnmount() {

}

public Label getName() {
return name;
}

public void setName(Label name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import models.RootMoment;
import models.TemplateMoment;
import utils.GlobalVariables;
import utils.ModelisationNavigator;
import utils.MomentSearch;
import utils.dragAndDrop.DragStore;
import utils.scrollOnDragPane.ScrollOnDragPane;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void initialize(URL location, ResourceBundle resources) {
showFindDialog();
}
});
GlobalVariables.modelisationNavigator = new ModelisationNavigator(this.superPane, this.anchorPane);
}

public void setRootMoment(RootMoment m) {
Expand Down Expand Up @@ -178,9 +180,6 @@ public void centerNodeInScrollPaneY(ScrollPane scrollPane, Node node) {
}





private void showFindDialog() {
// Set up the dialog
Dialog<String> dialog = new Dialog<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@
import javafx.scene.layout.AnchorPane;
import models.Moment;
import org.fxmisc.richtext.InlineCssTextArea;
import utils.ModelisationNavigator;
import utils.MomentSearch;
import utils.SearchResult;

public class MomentSearchHandler implements EventHandler<ActionEvent> {

private final String HIGHLIGHT_STYLE = "-fx-background-color:" + "#fdff32" + "; -fx-fill:" + "#fdff32"+";";
private final String HIGHLIGHT_STYLE = "-fx-background-color:" + "#fdff32" + "; -fx-fill:" + "#fdff32" + ";";
private ButtonSearchType type;
private MomentSearch searchResult;
private ScrollPane scrollPane;
private AnchorPane anchorPane;
private Node previousNode;
ModelisationNavigator modelisationNavigator;

public MomentSearchHandler(ButtonSearchType type, MomentSearch searchResult, ScrollPane scrollPane,AnchorPane anchorPane) {
public MomentSearchHandler(ButtonSearchType type, MomentSearch searchResult, ScrollPane scrollPane, AnchorPane anchorPane) {
this.type = type;
this.searchResult = searchResult;
this.scrollPane = scrollPane;
this.anchorPane=anchorPane;
this.anchorPane = anchorPane;
this.modelisationNavigator = new ModelisationNavigator(this.scrollPane, this.anchorPane);
}

@Override
Expand All @@ -40,7 +43,7 @@ public void handle(ActionEvent event) {
event.consume(); // prevent the dialog from closing
return;
}
if(previousNode !=null){
if (previousNode != null) {
this.removeHighlight(previousNode);
}
Node currentNode;
Expand All @@ -51,49 +54,22 @@ public void handle(ActionEvent event) {
}
previousNode = currentNode;
scrollPane.requestFocus();
centerNodeInScrollPaneX(currentNode);
centerNodeInScrollPaneY(currentNode);
this.modelisationNavigator.centerNodeInScrollPaneX(currentNode);
this.modelisationNavigator.centerNodeInScrollPaneY(currentNode);

String initialNodeStyle = currentNode.getStyle();
currentNode.setStyle(initialNodeStyle+HIGHLIGHT_STYLE);
currentNode.setStyle(initialNodeStyle + HIGHLIGHT_STYLE);

event.consume(); // prevent the dialog from closing
}
public void centerNodeInScrollPaneX(Node node) {
double h = this.anchorPane.getBoundsInLocal().getWidth();//scrollpane
//System.out.println(node.getBoundsInParent());
Bounds bounds =
this.anchorPane.sceneToLocal(node.localToScene(node.getBoundsInLocal()));//scrollpane
//System.out.println(bounds);
double y = (bounds.getMaxX() +
bounds.getMinX()) / 2.0;
double v = this.scrollPane.getViewportBounds().getWidth();
this.scrollPane.setHvalue(this.scrollPane.getHmax() * ((y - 0.5 * v) / (h - v)));
// this.scrollPane.setHvalue(genHValue(node));
}
public void centerNodeInScrollPaneY(Node node) {
double h = this.anchorPane.getBoundsInLocal().getHeight();
Bounds bounds =
this.anchorPane.sceneToLocal(node.localToScene(node.getBoundsInLocal()));
double y = (bounds.getMaxY() +
bounds.getMinY()) / 2.0;
double v = this.scrollPane.getViewportBounds().getHeight();
System.out.println(node.getBoundsInParent());
System.out.println(bounds);
//testing two
double height = this.anchorPane.getBoundsInLocal().getHeight();
double y2 = node.getBoundsInParent().getMaxY();
//this.scrollPane.setVvalue(y2 / height);
this.scrollPane.setVvalue(this.scrollPane.getHmax() * ((y - 0.5 * v) / (h - v)));
// this.scrollPane.setVvalue(this.genVValue(node));
}

public void removeHighlight(Node node){
public void removeHighlight(Node node) {
String nodeStyle = node.getStyle();
node.setStyle(nodeStyle.replace(HIGHLIGHT_STYLE,""));
node.setStyle(nodeStyle.replace(HIGHLIGHT_STYLE, ""));
}
public void cleanSearchHighlight(){
if(previousNode !=null){

public void cleanSearchHighlight() {
if (previousNode != null) {
this.removeHighlight(previousNode);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import application.configuration.Configuration;
import components.schemaTree.Cell.appCommands.SchemaTreeCommandFactory;
import javafx.beans.binding.Bindings;
import javafx.scene.control.Menu;
import javafx.scene.control.Tooltip;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import models.ConcreteCategory;
import models.Moment;
import models.SchemaCategory;
import models.SchemaProperty;
import javafx.scene.control.MenuItem;
import utils.GlobalVariables;
import utils.ResourceLoader;
import utils.autoSuggestion.strategies.SuggestionStrategy;
Expand All @@ -22,6 +25,11 @@ public class SchemaTreeCategoryController extends SchemaTreeCellController {
private SchemaCategory category;
private SchemaTreeCommandFactory cmdFactory;
private GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();
private int currentNavigationIndex = -1;
@FXML
HBox navigationBox;
private Button leftNavigation;
private Button rightNavigation;

public SchemaTreeCategoryController(SchemaCategory model, SchemaTreeCommandFactory cmdFactory) {
super(model, cmdFactory);
Expand All @@ -37,6 +45,12 @@ protected SuggestionStrategy getSuggestionStrategy() {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
super.initialize(url, resourceBundle);
this.leftNavigation = new Button("<");
this.rightNavigation = new Button(">");
this.navigationBox.getChildren().add(this.leftNavigation);
this.navigationBox.getChildren().add(this.rightNavigation);


this.complementaryInfoTooltip = new Tooltip(Configuration.langBundle.getString("complementary_info_toolbox"));
complementaryInfoTooltip.setShowDelay(new Duration(0));
this.complementaryInfo.setTooltip(complementaryInfoTooltip);
Expand Down Expand Up @@ -79,6 +93,46 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
cmdFactory.removeTreeElement(category).execute();
});
optionsMenu.getItems().add(deleteButton);
if (this.category.getCurrentInterviewUses() <= 0) {
this.leftNavigation.setDisable(true);
this.rightNavigation.setDisable(true);
} else {
this.leftNavigation.setDisable(false);
this.rightNavigation.setDisable(false);
}
this.category.currentInterviewUsesProperty().addListener((obs, oldValue, newValue) -> {
if (newValue.intValue() <= 0) {
this.leftNavigation.setDisable(true);
this.rightNavigation.setDisable(true);
} else {
this.leftNavigation.setDisable(false);
this.rightNavigation.setDisable(false);
}
});
Tooltip navigationButtonTooltip = new Tooltip(Configuration.langBundle.getString("navigate_category"));
navigationButtonTooltip.setShowDelay(new Duration(100));
this.leftNavigation.setTooltip(navigationButtonTooltip);
this.rightNavigation.setTooltip(navigationButtonTooltip);

this.leftNavigation.setOnMouseClicked((e) -> {

this.currentNavigationIndex = Math.floorMod(this.currentNavigationIndex - 1, this.category.getCurrentInterviewUses());

GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneX(this.getNavigationNode(this.currentNavigationIndex));
GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneY(this.getNavigationNode(this.currentNavigationIndex));

});
this.rightNavigation.setOnMouseClicked((e) -> {
this.currentNavigationIndex = Math.floorMod(this.currentNavigationIndex + 1, this.category.getCurrentInterviewUses());

GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneX(this.getNavigationNode(this.currentNavigationIndex));
GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneY(this.getNavigationNode(this.currentNavigationIndex));

});
}

private void addColorChange() {
Expand Down Expand Up @@ -183,4 +237,15 @@ public void updateCategoryIcon(String color) {
break;
}
}

public Node getNavigationNode(int index) {
Moment navigationMoment = GlobalVariables.nodeViews.
getInstanceByCategory(this.category, this.currentNavigationIndex);
for (ConcreteCategory category : navigationMoment.getCategories()) {
if (category.getSchemaCategory().equals(this.category)) {
return category.getController().getName();
}
}
return navigationMoment.getController().nameBox;
}
}
2 changes: 2 additions & 0 deletions src/main/java/utils/GlobalVariables.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class GlobalVariables {
private static String currentProjectPath;
private static SimpleObjectProperty<Descripteme> changedDescripteme = new SimpleObjectProperty<>();
public static NodeView nodeViews = new NodeView();
public static ModelisationNavigator modelisationNavigator;
public SimpleBooleanProperty isMomentSearchClicked;

private GlobalVariables() {
this.isMomentSearchClicked = new SimpleBooleanProperty(false);
}
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/utils/InterviewNodes.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
package utils;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import models.ConcreteCategory;
import models.Moment;
import models.SchemaCategory;

import java.util.ArrayList;
import java.util.HashMap;

public class InterviewNodes {
private HashMap<Moment, Node> interviewNodesMap = new HashMap<>();
private HashMap<SchemaCategory, ArrayList<Moment>> categoryNodesMap;
public InterviewNodes() {
this.interviewNodesMap = new HashMap<>();
}

public InterviewNodes(Moment moment, Node node) {
this.interviewNodesMap = new HashMap<>();
this.categoryNodesMap= new HashMap<>();
this.interviewNodesMap.put(moment, node);
}

public void add(Moment moment, Node node) {
this.interviewNodesMap.put(moment, node);
try{
ObservableList<ConcreteCategory> momentCategories = moment.getCategories();
for (ConcreteCategory category : momentCategories){
if(!this.categoryNodesMap.containsKey(category.getSchemaCategory())){
ArrayList<Moment> moments = new ArrayList<>();
moments.add(moment);
this.categoryNodesMap.put(category.getSchemaCategory(),moments);
}else{
this.categoryNodesMap.get(category.getSchemaCategory()).add(moment);
}
}
}catch (Exception exception){
exception.printStackTrace();
}


}

public Node getNodeByMomentName(String name) {
Expand All @@ -28,7 +50,7 @@ public Node getNodeByMomentName(String name) {
}
return null;
}
//test

public Moment getMomentByMomentName(String name) {
for (Moment moment : this.interviewNodesMap.keySet()) {
if(moment.getName().equals(name)){
Expand Down Expand Up @@ -57,5 +79,18 @@ public void setInterviewNodesMap(HashMap<Moment, Node> interviewNodesMap) {

public void remove(Moment moment) {
this.interviewNodesMap.remove(moment);
ObservableList<ConcreteCategory> momentCategories = moment.getCategories();
for (ConcreteCategory category : momentCategories){
if(this.categoryNodesMap.containsKey(category.getSchemaCategory())){
this.categoryNodesMap.get(category.getSchemaCategory()).remove(moment);
}
}

}
public Moment getInstanceByCategory(SchemaCategory schemaCategory,int index){
if(this.categoryNodesMap.containsKey(schemaCategory)){
return this.categoryNodesMap.get(schemaCategory).get(index);
}
return null;
}
}
37 changes: 37 additions & 0 deletions src/main/java/utils/ModelisationNavigator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package utils;

import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.AnchorPane;

public class ModelisationNavigator {

ScrollPane scrollPane;
AnchorPane anchorPane;

public ModelisationNavigator(ScrollPane scrollPane, AnchorPane anchorPane) {
this.anchorPane = anchorPane;
this.scrollPane = scrollPane;
}

public void centerNodeInScrollPaneX(Node node) {
double h = this.anchorPane.getBoundsInLocal().getWidth();
Bounds bounds =
this.anchorPane.sceneToLocal(node.localToScene(node.getBoundsInLocal()));
double y = (bounds.getMaxX() +
bounds.getMinX()) / 2.0;
double v = this.scrollPane.getViewportBounds().getWidth();
this.scrollPane.setHvalue(this.scrollPane.getHmax() * ((y - 0.5 * v) / (h - v)));
}

public void centerNodeInScrollPaneY(Node node) {
double h = this.anchorPane.getBoundsInLocal().getHeight();
Bounds bounds =
this.anchorPane.sceneToLocal(node.localToScene(node.getBoundsInLocal()));
double y = (bounds.getMaxY() +
bounds.getMinY()) / 2.0;
double v = this.scrollPane.getViewportBounds().getHeight();
this.scrollPane.setVvalue(this.scrollPane.getHmax() * ((y - 0.5 * v) / (h - v)));
}
}
15 changes: 12 additions & 3 deletions src/main/java/utils/NodeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javafx.scene.Node;
import models.Interview;
import models.Moment;
import models.SchemaCategory;

import java.util.HashMap;

Expand All @@ -23,13 +24,21 @@ public void addMoment(Moment moment, Node node) {
this.nodeList.put(currentInterview, new InterviewNodes(moment, node));
}
}
public Node getNodeByMomentName(String name){

public Node getNodeByMomentName(String name) {
return this.nodeList.get(globalVariables.getProject().getSelectedInterview()).getNodeByMomentName(name);
}
public Moment getMomentByMomentName(String name){

public Moment getMomentByMomentName(String name) {
return this.nodeList.get(globalVariables.getProject().getSelectedInterview()).getMomentByMomentName(name);
}
public InterviewNodes getCurrentInterviewNodes(){

public Moment getInstanceByCategory(SchemaCategory schemaCategory, int index) {
return this.nodeList.get(this.globalVariables.getProject().getSelectedInterview())
.getInstanceByCategory(schemaCategory, index);
}

public InterviewNodes getCurrentInterviewNodes() {
return this.nodeList.get(globalVariables.getProject().getSelectedInterview());
}

Expand Down
Loading

0 comments on commit c4e7cd1

Please sign in to comment.