Skip to content

Commit

Permalink
Merge 8096572 into 06b8d83
Browse files Browse the repository at this point in the history
  • Loading branch information
JeridiOmar authored May 6, 2023
2 parents 06b8d83 + 8096572 commit f5d6d3a
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public RichTextAreaController(InterviewText interviewText, List<AnnotationColor>
showFindDialog(area);
}
});

}

private void showFindDialog(InlineCssTextArea richTextArea) {
Expand All @@ -88,8 +89,8 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
dialog.getDialogPane().getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/application.css")).toExternalForm());
dialog.getDialogPane().setPrefWidth(450);
dialog.setResizable(true);
dialog.setTitle(Configuration.langBundle.getString("find"));
dialog.setHeaderText(Configuration.langBundle.getString("find"));
dialog.setTitle(Configuration.langBundle.getString("find_text"));
dialog.setHeaderText(Configuration.langBundle.getString("find_text"));
dialog.setResizable(false);

// Set up the buttons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@
import components.modelisationSpace.search.MomentSearchHandler;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Bounds;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.*;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.transform.Scale;
import javafx.stage.Modality;
import models.RootMoment;
import models.TemplateMoment;
import utils.GlobalVariables;
import utils.ModelisationNavigator;
import utils.MomentSearch;
import utils.SearchProperties;
import utils.dragAndDrop.DragStore;
import utils.scrollOnDragPane.ScrollOnDragPane;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Objects;
Expand All @@ -57,6 +65,7 @@ public class ModelisationSpaceController extends ScrollOnDragPane implements Ini
private MomentSearchHandler previousButtonHandler;
GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();
private MomentSearch searchResult;
private SearchProperties searchProperties;

public ModelisationSpaceController() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/views/modelisationSpace/ModelisationSpace.fxml"));
Expand All @@ -78,6 +87,7 @@ public void initialize(URL location, ResourceBundle resources) {
super.initialize(location, resources);
paneCmdFactory = new ScrollPaneCommandFactory(superPane);
this.searchResult = new MomentSearch();
this.searchProperties = new SearchProperties();
setupDragAndDrop();
this.isSearchClicked = new SimpleBooleanProperty(false);
globalVariables.isMomentSearchClicked = this.isSearchClicked;
Expand All @@ -93,6 +103,7 @@ public void initialize(URL location, ResourceBundle resources) {
}
});
GlobalVariables.modelisationNavigator = new ModelisationNavigator(this.superPane, this.anchorPane);

}

public void setRootMoment(RootMoment m) {
Expand Down Expand Up @@ -185,10 +196,10 @@ private void showFindDialog() {
Dialog<String> dialog = new Dialog<>();
dialog.initModality(Modality.WINDOW_MODAL);
dialog.getDialogPane().getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/application.css")).toExternalForm());
dialog.getDialogPane().setPrefWidth(450);
dialog.getDialogPane().setPrefWidth(750);
dialog.setResizable(true);
dialog.setTitle(Configuration.langBundle.getString("find"));
dialog.setHeaderText(Configuration.langBundle.getString("find"));
dialog.setTitle(Configuration.langBundle.getString("find_moment"));
dialog.setHeaderText(Configuration.langBundle.getString("find_moment"));
dialog.setResizable(false);

// Set up the buttons
Expand All @@ -206,42 +217,114 @@ private void showFindDialog() {
Label matchCountLabel = new Label();
matchCountLabel.setVisible(false);

//Create the radios choices
// Create a ToggleGroup to ensure that only one radio button is selected at a time
ToggleGroup toggleGroup = new ToggleGroup();

// Create four RadioButtons and add them to the ToggleGroup
RadioButton moment_name_choice = new RadioButton(Configuration.langBundle.getString("moment_name"));
moment_name_choice.setToggleGroup(toggleGroup);
moment_name_choice.setOnAction(e -> {
if (moment_name_choice.isSelected()) {
this.searchProperties.setChoiceMomentName();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});

RadioButton category_name_choice = new RadioButton(Configuration.langBundle.getString("category_name"));
category_name_choice.setToggleGroup(toggleGroup);
category_name_choice.setOnAction(e -> {
if (category_name_choice.isSelected()) {
this.searchProperties.setChoiceCategoryName();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});

RadioButton property_name_choice = new RadioButton(Configuration.langBundle.getString("property_name"));
property_name_choice.setToggleGroup(toggleGroup);
property_name_choice.setOnAction(e -> {
if (property_name_choice.isSelected()) {
this.searchProperties.setChoicePropertyName();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});

RadioButton property_value_choice = new RadioButton(Configuration.langBundle.getString("property_value"));
property_value_choice.setToggleGroup(toggleGroup);
property_value_choice.setOnAction(e -> {
if (property_value_choice.isSelected()) {
this.searchProperties.setChoicePropertyValue();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});


RadioButton all_choice = new RadioButton(Configuration.langBundle.getString("all"));
all_choice.setToggleGroup(toggleGroup);
all_choice.setOnAction(e -> {
if (all_choice.isSelected()) {
this.searchProperties.setChoiceAll();
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
});


Label choicesLabel = new Label(Configuration.langBundle.getString("search_in"));
// Create an HBox container and add the RadioButtons to it
HBox choicesHbox = new HBox(10); // 10 is the spacing between the controls
choicesHbox.setPadding(new Insets(10)); // Set some padding around the container
choicesHbox.getChildren().
addAll(choicesLabel, moment_name_choice, category_name_choice, property_name_choice, property_value_choice, all_choice);
// Set up the grid pane
HBox gridPane = new HBox();
gridPane.setSpacing(15);
gridPane.setAlignment(Pos.BASELINE_CENTER);
gridPane.getChildren().add(findLabel);
gridPane.getChildren().add(findTextField);
gridPane.getChildren().add(matchCountLabel);
dialog.getDialogPane().setContent(gridPane);
//create vbox
VBox vBox = new VBox(20);
vBox.getChildren().add(choicesHbox);
vBox.getChildren().add(gridPane);

dialog.getDialogPane().setContent(vBox);

Button findPreviousButton = (Button) dialog.getDialogPane().lookupButton(findPreviousButtonType);
Button findNextButton = (Button) dialog.getDialogPane().lookupButton(findNextButtonType);
Button closeButton = (Button) dialog.getDialogPane().lookupButton(closeButtonType);
//Init Buttons on disabled
findNextButton.setDisable(true);
findPreviousButton.setDisable(true);
moment_name_choice.fire();

// handle search result label
findTextField.textProperty().addListener((obs, oldText, newText) -> {
if (!newText.isEmpty()) {
this.searchResult.countOccurrences(newText);
matchCountLabel.setVisible(true);

matchCountLabel.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int resultCount = this.searchResult.getResultCount();
s += resultCount + " ";
s += Configuration.langBundle.getString("matches_found") + ".";
return s;
}, this.searchResult.resultCountProperty()));
this.launchSearch(newText, matchCountLabel);
} else {
this.searchResult.resetSearch();
matchCountLabel.setVisible(false);
}

});

//If we changed the interview and the panel is open we just relaunch the search on the new one
GlobalVariables.getGlobalVariables().getProject().selectedInterviewProperty().addListener(
(obs, oldProject, newProject) -> {
if (!findTextField.getText().isEmpty()) {
this.launchSearch(findTextField.getText(), matchCountLabel);
}
}
);

//Handle buttons disabled property listeners
this.searchResult.resultCountProperty().addListener((obs, oldCount, newCount) -> {
Expand Down Expand Up @@ -271,4 +354,17 @@ private void showFindDialog() {
dialog.getDialogPane().toFront();
}

private void launchSearch(String query, Label matchCountLabel) {
this.searchResult.countOccurrences(query, this.searchProperties);
matchCountLabel.setVisible(true);

matchCountLabel.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int resultCount = this.searchResult.getResultCount();
s += resultCount + " ";
s += Configuration.langBundle.getString("matches_found") + ".";
return s;
}, this.searchResult.resultCountProperty()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import application.configuration.Configuration;
import components.schemaTree.Cell.appCommands.SchemaTreeCommandFactory;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.util.Duration;
import models.ConcreteCategory;
Expand All @@ -25,11 +29,15 @@ public class SchemaTreeCategoryController extends SchemaTreeCellController {
private SchemaCategory category;
private SchemaTreeCommandFactory cmdFactory;
private GlobalVariables globalVariables = GlobalVariables.getGlobalVariables();
private int currentNavigationIndex = -1;
private SimpleIntegerProperty currentNavigationIndex = new SimpleIntegerProperty(-1);
@FXML
HBox navigationBox;
@FXML
BorderPane usesSection;
private Button leftNavigation;
private Button rightNavigation;
private Tooltip rightNavigationButtonTooltip;
private Tooltip leftNavigationButtonTooltip;

public SchemaTreeCategoryController(SchemaCategory model, SchemaTreeCommandFactory cmdFactory) {
super(model, cmdFactory);
Expand All @@ -47,11 +55,18 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
super.initialize(url, resourceBundle);
this.leftNavigation = new Button("<");
this.rightNavigation = new Button(">");
this.leftNavigation.setPadding(new Insets(1, 3, 1, 3));
this.rightNavigation.setPadding(new Insets(1, 3, 1, 3));
this.leftNavigation.setStyle("-fx-background-color:rgba(0, 0, 0, 0.1);-fx-background-size:0;");
this.rightNavigation.setStyle("-fx-background-color:rgba(0, 0, 0, 0.1);-fx-background-size:0;");
this.navigationBox.setSpacing(5);
this.navigationBox.getChildren().add(this.leftNavigation);
this.navigationBox.getChildren().add(this.rightNavigation);

this.navigationBox.setPadding(new Insets(7.5, 0, 0, 0));

this.complementaryInfoTooltip = new Tooltip(Configuration.langBundle.getString("complementary_info_toolbox"));
// this.complementaryInfoTooltip = new Tooltip("Navigate to nb : "+(Math.floorMod(this.currentNavigationIndex - 1, this.category.getCurrentInterviewUses())+1));

complementaryInfoTooltip.setShowDelay(new Duration(0));
this.complementaryInfo.setTooltip(complementaryInfoTooltip);
this.usesPerInterview.setTooltip(complementaryInfoTooltip);
Expand Down Expand Up @@ -109,30 +124,12 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
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());
//Navigation Buttons ToolTipSetup
this.setupNavigationToolTip();
this.setupNavigationHandlers();

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

});
}

private void addColorChange() {
Expand Down Expand Up @@ -240,12 +237,73 @@ public void updateCategoryIcon(String color) {

public Node getNavigationNode(int index) {
Moment navigationMoment = GlobalVariables.nodeViews.
getInstanceByCategory(this.category, this.currentNavigationIndex);
getInstanceByCategory(this.category, this.currentNavigationIndex.get());
for (ConcreteCategory category : navigationMoment.getCategories()) {
if (category.getSchemaCategory().equals(this.category)) {
return category.getController().getName();
}
}
return navigationMoment.getController().nameBox;
}

private int calculateLeftIndex(int currentIndex, int total) {
if (currentIndex == -1) {
return total - 1;
} else {
return Math.floorMod(currentIndex - 1, total);
}
}

private int calculateRightIndex(int currentIndex, int total) {

return Math.floorMod(currentIndex + 1, total);
}

private void setupNavigationToolTip() {
this.leftNavigationButtonTooltip = new Tooltip();
this.rightNavigationButtonTooltip = new Tooltip();
leftNavigationButtonTooltip.setShowDelay(new Duration(100));
rightNavigationButtonTooltip.setShowDelay(new Duration(100));
leftNavigationButtonTooltip.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int currentInterviewUses = this.category.getCurrentInterviewUses();
if (currentInterviewUses > 0) {
s = Configuration.langBundle.getString("navigation_tooltip") + (this.calculateLeftIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1);
}
return s;

}, this.currentNavigationIndex, this.category.currentInterviewUsesProperty()));
rightNavigationButtonTooltip.textProperty().bind(Bindings.createStringBinding(() -> {
String s = "";
int currentInterviewUses = this.category.getCurrentInterviewUses();
if (currentInterviewUses > 0) {
s = Configuration.langBundle.getString("navigation_tooltip") + (this.calculateRightIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()) + 1);
}
return s;

}, this.currentNavigationIndex, this.category.currentInterviewUsesProperty()));
this.leftNavigation.setTooltip(leftNavigationButtonTooltip);
this.rightNavigation.setTooltip(rightNavigationButtonTooltip);
}

private void setupNavigationHandlers() {
this.leftNavigation.setOnMouseClicked((e) -> {

this.currentNavigationIndex.set(this.calculateLeftIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()));

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

this.rightNavigation.setOnMouseClicked((e) -> {
this.currentNavigationIndex.set(this.calculateRightIndex(this.currentNavigationIndex.get(), this.category.getCurrentInterviewUses()));

GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneX(this.getNavigationNode(this.currentNavigationIndex.get()));
GlobalVariables.modelisationNavigator.
centerNodeInScrollPaneY(this.getNavigationNode(this.currentNavigationIndex.get()));
});
}
}
Loading

0 comments on commit f5d6d3a

Please sign in to comment.