Skip to content

Commit

Permalink
Merge 82e0260 into d6c5faf
Browse files Browse the repository at this point in the history
  • Loading branch information
JeridiOmar authored Apr 24, 2023
2 parents d6c5faf + 82e0260 commit b90955a
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,37 @@
import components.interviewPanel.ContextMenus.ContextMenuFactory;
import components.interviewPanel.ToolBar.ToolBarController;
import components.interviewPanel.ToolBar.tools.AnnotationTool;
import components.interviewPanel.ToolBar.tools.Controllers.AnnotationToolController;
import components.interviewPanel.ToolBar.tools.Controllers.EraserToolController;
import components.interviewPanel.ToolBar.tools.Controllers.SelectionToolController;
import components.interviewPanel.ToolBar.tools.Controllers.ToolController;
import components.interviewPanel.ToolBar.tools.Controllers.*;
import components.interviewPanel.ToolBar.tools.EraserTool;
import components.interviewPanel.ToolBar.tools.SelectionTool;
import components.interviewPanel.appCommands.InterviewTextCommandFactory;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.IndexRange;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import models.AnnotationColor;
import models.Descripteme;
import models.Interview;
Expand All @@ -39,12 +49,16 @@

public class InterviewTextController implements Initializable {

@FXML private HBox hboxAnnotation;
@FXML private StackPane stackPaneInterview;
@FXML
private HBox hboxAnnotation;
@FXML
private StackPane stackPaneInterview;
private InterviewTextCommandFactory interviewTextCommandFactory;
private RichTextAreaController richTextAreaController;
private SearchToolController searchToolController;
private final Interview interview;
private Pane paneDragText;
private SimpleBooleanProperty isSearchClicked;

private InterviewTextController(Interview interview) {
this.interview = interview;
Expand Down Expand Up @@ -72,8 +86,8 @@ public void initialize(URL location, ResourceBundle resources) {
annotationColorList.add(new AnnotationColor("red", "#FF9797"));
annotationColorList.add(new AnnotationColor("blue", "#7084B0"));
annotationColorList.add(new AnnotationColor("green", "#7BCF7B"));

richTextAreaController = new RichTextAreaController(interview.getInterviewText(), annotationColorList);
this.isSearchClicked = new SimpleBooleanProperty(false);
richTextAreaController = new RichTextAreaController(interview.getInterviewText(), annotationColorList, isSearchClicked);

stackPaneInterview.getChildren().add(richTextAreaController.getNode());

Expand All @@ -94,12 +108,13 @@ public void initialize(URL location, ResourceBundle resources) {
toolBarController.addSeparator();
ToolController selectionToolController = new SelectionToolController(
"selection",
new SelectionTool( "#fff", interview.getInterviewText(), interviewTextCommandFactory), true);
new SelectionTool("#fff", interview.getInterviewText(), interviewTextCommandFactory), true);
toolBarController.addTool(selectionToolController);
toolBarController.addTool(new EraserToolController("eraser",
new EraserTool("#8b8b8b", interview.getInterviewText(), interviewTextCommandFactory)));
toolBarController.setSelectedToolProperty(selectionToolController);
hboxAnnotation.getChildren().add(toolBarController);
searchToolController = new SearchToolController(hboxAnnotation.getChildren(), isSearchClicked);

// On click release on text area: add a pane over the text area
richTextAreaController.getUserSelection().addListener((change) -> toolBarController.getSelectedToolProperty().get()
Expand All @@ -125,7 +140,7 @@ private void setupDragAndDrop() {
// On click on the added pane, remove the pane
paneDragText.setOnMouseClicked(arg0 -> hideDnDPane());
paneDragText.setOnMousePressed(event -> {
if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()){
if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
hideDnDPane();
richTextAreaController.updateContextMenu();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import components.interviewPanel.search.SearchButtonHandler;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.HBox;
import javafx.stage.Popup;
Expand All @@ -25,6 +25,7 @@
import org.fxmisc.richtext.InlineCssTextArea;
import org.fxmisc.richtext.LineNumberFactory;
import org.fxmisc.richtext.event.MouseOverTextEvent;
import utils.SearchResult;

import java.time.Duration;
import java.util.ArrayList;
Expand All @@ -44,10 +45,12 @@ public class RichTextAreaController {
private ContextMenuFactory contextMenuFactory;
private final List<AnnotationColor> annotationColorList;
private SearchResult searchResult;
private SimpleBooleanProperty isSearchClicked;

public RichTextAreaController(InterviewText interviewText, List<AnnotationColor> annotationColorList) {
public RichTextAreaController(InterviewText interviewText, List<AnnotationColor> annotationColorList, SimpleBooleanProperty isSearchClicked) {
this.interviewText = interviewText;
this.annotationColorList = annotationColorList;
this.isSearchClicked = isSearchClicked;
userSelection = new SimpleObjectProperty<>();
area = new InlineCssTextArea();
area.setWrapText(true);
Expand All @@ -65,9 +68,15 @@ public RichTextAreaController(InterviewText interviewText, List<AnnotationColor>
.addListener(newValue -> this.updateDescripteme());

applyStyleInitialize();

//Add ctrl+F Listener to launch the research
area.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
if (e.getCode() == KeyCode.F && e.isControlDown()) {
if (e.getCode() == KeyCode.F && e.isShortcutDown()) {
isSearchClicked.set(true);
}
});
this.isSearchClicked.addListener((obs, oldValue, newValue) -> {
if (newValue) {
showFindDialog(area);
}
});
Expand All @@ -86,7 +95,8 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
// Set up the buttons
ButtonType findPreviousButtonType = new ButtonType(Configuration.langBundle.getString("previous"), ButtonBar.ButtonData.OK_DONE);
ButtonType findNextButtonType = new ButtonType(Configuration.langBundle.getString("next"), ButtonBar.ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(findNextButtonType, findPreviousButtonType, ButtonType.CLOSE);
ButtonType closeButtonType = ButtonType.CLOSE;
dialog.getDialogPane().getButtonTypes().addAll(findNextButtonType, findPreviousButtonType, closeButtonType);

// Set up the text field and label
TextField findTextField = new TextField();
Expand All @@ -108,6 +118,7 @@ private void showFindDialog(InlineCssTextArea richTextArea) {

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);
Expand Down Expand Up @@ -152,7 +163,9 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
ButtonSearchType.NEXT, searchResult, richTextArea));
findPreviousButton.addEventFilter(ActionEvent.ACTION, new SearchButtonHandler(
ButtonSearchType.PREVIOUS, searchResult, richTextArea));

closeButton.addEventFilter(ActionEvent.ACTION, (e) -> {
this.isSearchClicked.set(false);
});
// Show the dialog and reset the search result
dialog.setOnCloseRequest(e -> {
this.searchResult.resetSearch();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package components.interviewPanel.ToolBar.tools.Controllers;

import application.configuration.Configuration;
import components.interviewPanel.ToolBar.tools.Tool;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

public class SearchToolController {
final String iconPath = "/images/book.png";
private Label label;
private VBox vbox;
private Canvas canvas;
private GraphicsContext gc;
private SimpleBooleanProperty isSearchClicked;
private ObservableList<Node> hboxChildrens;

public SearchToolController(ObservableList<Node> hboxChildrens, SimpleBooleanProperty isSearchClicked) {
this.hboxChildrens = hboxChildrens;
label = new Label();
vbox = new VBox();
canvas = new Canvas(20, 20);
this.isSearchClicked = isSearchClicked;
this.initGraphic();
}

public void initGraphic() {
vbox.setAlignment(Pos.CENTER);
vbox.setPadding(new Insets(3));
label.setText(Configuration.langBundle.getString("find"));
gc = canvas.getGraphicsContext2D();
vbox.getChildren().add(canvas);
vbox.getChildren().add(label);
gc.setFill(Color.TRANSPARENT);
gc.fillRect(0, 0, 20, 20);
gc.drawImage(new Image(iconPath), 0, 0, 20, 20);
vbox.setOnMouseClicked((e) ->
{
isSearchClicked.set(true);
});
hboxChildrens.add(vbox);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import models.SearchResult;
import utils.SearchResult;
import org.fxmisc.richtext.InlineCssTextArea;

public class SearchButtonHandler implements EventHandler<ActionEvent> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package models;
package utils;

import javafx.beans.property.SimpleIntegerProperty;

Expand Down
Binary file added src/main/resources/images/book.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b90955a

Please sign in to comment.