Skip to content

Commit

Permalink
Merge pull request #135 from yprie/sprint4/feat-search-moment
Browse files Browse the repository at this point in the history
Sprint4/feat search moment
  • Loading branch information
JeridiOmar authored May 12, 2023
2 parents 14507af + bb9a816 commit 1582380
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javafx.beans.InvalidationListener;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -56,9 +57,12 @@ public class InterviewTextController implements Initializable {
private InterviewTextCommandFactory interviewTextCommandFactory;
private RichTextAreaController richTextAreaController;
private SearchToolController searchToolController;
private PoliceSizeController increaseSizeController;
private PoliceSizeController decreaseSizeController;
private final Interview interview;
private Pane paneDragText;
private SimpleBooleanProperty isSearchClicked;
private SimpleIntegerProperty fontSize;

private InterviewTextController(Interview interview) {
this.interview = interview;
Expand Down Expand Up @@ -87,7 +91,9 @@ public void initialize(URL location, ResourceBundle resources) {
annotationColorList.add(new AnnotationColor("blue", "#7084B0"));
annotationColorList.add(new AnnotationColor("green", "#7BCF7B"));
this.isSearchClicked = new SimpleBooleanProperty(false);
richTextAreaController = new RichTextAreaController(interview.getInterviewText(), annotationColorList, isSearchClicked);
this.fontSize = new SimpleIntegerProperty(1);
richTextAreaController = new RichTextAreaController(interview.getInterviewText(), annotationColorList,
isSearchClicked, fontSize);

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

Expand Down Expand Up @@ -115,6 +121,10 @@ public void initialize(URL location, ResourceBundle resources) {
toolBarController.setSelectedToolProperty(selectionToolController);
hboxAnnotation.getChildren().add(toolBarController);
searchToolController = new SearchToolController(hboxAnnotation.getChildren(), isSearchClicked);
this.increaseSizeController = new PoliceSizeController(
hboxAnnotation.getChildren(), fontSize, PoliceSizeController.FontAction.INCREASE);
this.increaseSizeController = new PoliceSizeController(
hboxAnnotation.getChildren(), fontSize, PoliceSizeController.FontAction.DECREASE);

// On click release on text area: add a pane over the text area
richTextAreaController.getUserSelection().addListener((change) -> toolBarController.getSelectedToolProperty().get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import application.configuration.Configuration;
import components.interviewPanel.ContextMenus.ContextMenuFactory;
import components.interviewPanel.ToolBar.tools.Controllers.PoliceSizeController;
import components.interviewPanel.search.ButtonSearchType;
import components.interviewPanel.search.SearchButtonHandler;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.collections.ListChangeListener;
Expand All @@ -32,6 +34,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static utils.GlobalVariables.getGlobalVariables;

Expand All @@ -46,12 +50,16 @@ public class RichTextAreaController {
private final List<AnnotationColor> annotationColorList;
private SearchResult searchResult;
private SimpleBooleanProperty isSearchClicked;
private SimpleIntegerProperty fontSize;

public RichTextAreaController(InterviewText interviewText, List<AnnotationColor> annotationColorList, SimpleBooleanProperty isSearchClicked) {

public RichTextAreaController(InterviewText interviewText, List<AnnotationColor> annotationColorList,
SimpleBooleanProperty isSearchClicked, SimpleIntegerProperty fontSize) {
this.interviewText = interviewText;
this.annotationColorList = annotationColorList;
this.isSearchClicked = isSearchClicked;
userSelection = new SimpleObjectProperty<>();
this.fontSize = fontSize;
area = new InlineCssTextArea();
area.setWrapText(true);
area.setEditable(false);
Expand Down Expand Up @@ -80,6 +88,23 @@ public RichTextAreaController(InterviewText interviewText, List<AnnotationColor>
showFindDialog(area);
}
});
this.fontSize.addListener((obs, oldValue, newValue) -> {
String currentStyle = this.area.getStyle();

// Extract the font size from the style using regular expressions
Pattern pattern = Pattern.compile("-fx-font-size: (\\d+)em;");
Matcher matcher = pattern.matcher(currentStyle);
if (matcher.find()) {
// Extract the font size as an integer
int currentFontSize = newValue.intValue();
// Update the style with the new font size
String newStyle = currentStyle.replaceAll("-fx-font-size: \\d+em;", "-fx-font-size: " + currentFontSize + "em;");
this.area.setStyle(newStyle);
} else {
// If the pattern doesn't match, set the font size to the default value (12 px in this example)
this.area.setStyle(currentStyle+"\n-fx-font-size: "+this.fontSize.get()+"em;\n");
}
});

}

Expand Down Expand Up @@ -140,7 +165,7 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
s += resultCount + " ";
s += Configuration.langBundle.getString("matches_found");
return s;
}, this.searchResult.resultCountProperty(),this.searchResult.getCurrentSearchIndexProperty()));
}, this.searchResult.resultCountProperty(), this.searchResult.getCurrentSearchIndexProperty()));
} else {
this.searchResult.resetSearch();
matchCountLabel.setVisible(false);
Expand Down Expand Up @@ -176,6 +201,7 @@ private void showFindDialog(InlineCssTextArea richTextArea) {
this.searchResult.resetSearch();
});
dialog.show();
findTextField.requestFocus();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package components.interviewPanel.ToolBar.tools.Controllers;

import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
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.image.Image;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

public class PoliceSizeController {
final String increaseIcon = "/images/increase-font.png";
final String decreaseIcon = "/images/decrease-font.png";
final String increaseIconDisabled = "/images/increase-font-disabled.png";
final String decreaseIconDisabled = "/images/decrease-font-disabled.png";
private VBox vbox;
private Canvas canvas;
private GraphicsContext gc;
private SimpleIntegerProperty fontSize;
private ObservableList<Node> hboxChildrens;
private FontAction fontAction;

public enum FontAction {
INCREASE,
DECREASE
}

public PoliceSizeController(ObservableList<Node> hboxChildrens, SimpleIntegerProperty fontSize, FontAction fontAction) {
this.hboxChildrens = hboxChildrens;
vbox = new VBox();
canvas = new Canvas(35, 35);
this.fontAction = fontAction;
this.fontSize = fontSize;
this.initGraphic();
}

public void initGraphic() {
vbox.setAlignment(Pos.CENTER);
vbox.setPadding(new Insets(3));
gc = canvas.getGraphicsContext2D();
vbox.getChildren().add(canvas);
gc.setFill(Color.TRANSPARENT);
gc.fillRect(0, 0, 35, 35);
if (this.fontAction.equals(FontAction.INCREASE)) {
gc.drawImage(new Image(increaseIcon), 0, 0, 35, 35);
} else {
gc.drawImage(new Image(decreaseIconDisabled), 0, 0, 35, 35);
}

vbox.setOnMouseClicked(
(e) -> {
if (this.fontAction.equals(FontAction.INCREASE)) {
fontSize.set(fontSize.get() + 1);
} else {
if (fontSize.get() > 1) {
fontSize.set(fontSize.get() - 1);
}

}
});
this.fontSize.addListener((obs, oldValue, newValue) -> {
if (this.fontAction.equals(FontAction.DECREASE)) {
if (newValue.intValue() <= 1) {
this.gc.drawImage(new Image(decreaseIconDisabled), 0, 0, 35, 35);
}else{
this.gc.drawImage(new Image(decreaseIcon), 0, 0, 35, 35);
}
}
});
hboxChildrens.add(vbox);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ public class ConcreteCategoryController extends ListViewController<ConcreteCateg
private JustificationController justificationController;
private ListView<ConcreteProperty, ConcretePropertyController> properties;

@FXML private BorderPane container;
@FXML private Label name;
@FXML private MenuButton menuButton;
@FXML private VBox propertiesContainer;
@FXML
private BorderPane container;
@FXML
private Label name;
@FXML
private MenuButton menuButton;
@FXML
private VBox propertiesContainer;

//Listeners
private ChangeListener<Boolean> onSchemaTreeRemoving = (ChangeListener<Boolean>) (observableValue, aBoolean, t1) -> {
if(!t1) {
if (!t1) {
cmdFactory.removeConcreteCategoryCommand(category, false).execute();
}
};
Expand All @@ -72,7 +76,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
category.getSchemaCategory().addToControllers(this);
category.setController(this);
name.textProperty().bind(category.nameProperty());
VBox justif = (VBox)JustificationController.createJustificationArea(justificationController);
VBox justif = (VBox) JustificationController.createJustificationArea(justificationController);
justif.setPadding(new Insets(0, 0, 0, 10));
container.setCenter(justif);
updateColor();
Expand All @@ -85,7 +89,11 @@ public void initialize(URL url, ResourceBundle resourceBundle) {

properties = new ListView<>(
category.propertiesProperty(),
(property) -> { return new ConcretePropertyController(cmdFactory.getHookNotifier(), property); },
(property) -> {
ConcretePropertyController controller = new ConcretePropertyController(cmdFactory.getHookNotifier(), property);
property.setController(controller);
return controller;
},
ConcretePropertyController::create,
propertiesContainer
);
Expand Down Expand Up @@ -127,23 +135,22 @@ private void setupDragAndDrop() {

container.setOnDragOver(dragEvent -> {
container.setStyle("-fx-opacity: 1;");
if(
!dragEvent.isAccepted()
&& DragStore.getDraggable().getDataFormat() == Descripteme.format
){
if(justificationController.acceptDescripteme(DragStore.getDraggable())) {
if (
!dragEvent.isAccepted()
&& DragStore.getDraggable().getDataFormat() == Descripteme.format
) {
if (justificationController.acceptDescripteme(DragStore.getDraggable())) {
container.setStyle("-fx-opacity: 0.5;");
dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
}
else {
} else {
dragEvent.acceptTransferModes(TransferMode.NONE);
}
}
});

container.setOnDragDropped(dragEvent -> {
if(DragStore.getDraggable().getDataFormat() == Descripteme.format) {
if(justificationController.acceptDescripteme(DragStore.getDraggable())) {
if (DragStore.getDraggable().getDataFormat() == Descripteme.format) {
if (justificationController.acceptDescripteme(DragStore.getDraggable())) {
justificationController.addDescripteme(DragStore.getDraggable());
dragEvent.setDropCompleted(true);
dragEvent.consume();
Expand Down Expand Up @@ -174,7 +181,9 @@ public ConcreteCategory getModel() {
@Override
public void onMount() {
Timeline viewFocus = new Timeline(new KeyFrame(Duration.seconds(0.1),
(EventHandler<ActionEvent>) event -> { paneCommandFactory.scrollToNode(container).execute(); }));
(EventHandler<ActionEvent>) event -> {
paneCommandFactory.scrollToNode(container).execute();
}));
viewFocus.play();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ private void showFindDialog() {
this.searchResult.resetSearch();
});
dialog.show();
findTextField.requestFocus();
dialog.getDialogPane().toFront();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,11 @@ private void exitRenamingMode(int indexOfValue, boolean canceled) {
renamingMode = false;
}

public Label getName() {
return name;
}

public Label getValue() {
return value;
}
}
45 changes: 37 additions & 8 deletions src/main/java/models/ConcreteProperty.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package models;

import components.modelisationSpace.category.controllers.ConcreteCategoryController;
import components.modelisationSpace.property.controllers.ConcretePropertyController;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableStringValue;
Expand All @@ -9,6 +11,7 @@ public class ConcreteProperty {
private SchemaProperty property;
private Justification justification;
private StringProperty value;
private ConcretePropertyController controller;

public ConcreteProperty(SchemaProperty p) {
this.property = p;
Expand All @@ -22,17 +25,43 @@ public ConcreteProperty(SchemaProperty p, Justification j) {
this.justification = j;
}

public final SchemaProperty getSchemaProperty() { return property; }
public final SchemaProperty getSchemaProperty() {
return property;
}

public String getName() {
return property.getName();
}

public ObservableStringValue nameProperty() {
return property.nameProperty();
}

public String getValue() {
return value.get();
}

public String getName() { return property.getName(); }
public ObservableStringValue nameProperty() { return property.nameProperty(); }
public ObservableStringValue valueProperty() {
return value;
}

public String getValue() { return value.get(); }
public ObservableStringValue valueProperty() { return value; }
public void setValue(String s) { value.set(s); }
public void setValue(String s) {
value.set(s);
}

public Justification getJustification() { return justification; }
public Justification getJustification() {
return justification;
}

public boolean isSchemaProperty(SchemaProperty sp) { return sp == property; }
public boolean isSchemaProperty(SchemaProperty sp) {
return sp == property;
}

public ConcretePropertyController getController() {
return controller;
}

public void setController(ConcretePropertyController controller) {
this.controller = controller;
}
}
Loading

0 comments on commit 1582380

Please sign in to comment.