-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from yprie/sprint4/feat-search-moment
Sprint4/feat search moment
- Loading branch information
Showing
16 changed files
with
699 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/components/modelisationSpace/search/MomentSearchHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package components.modelisationSpace.search; | ||
|
||
import components.interviewPanel.search.ButtonSearchType; | ||
import javafx.event.ActionEvent; | ||
import javafx.event.EventHandler; | ||
import javafx.geometry.Bounds; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Alert; | ||
import javafx.scene.control.ScrollPane; | ||
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 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) { | ||
this.type = type; | ||
this.searchResult = searchResult; | ||
this.scrollPane = scrollPane; | ||
this.anchorPane = anchorPane; | ||
this.modelisationNavigator = new ModelisationNavigator(this.scrollPane, this.anchorPane); | ||
} | ||
|
||
@Override | ||
public void handle(ActionEvent event) { | ||
if (this.searchResult.isEmpty()) { | ||
Alert alert = new Alert(Alert.AlertType.INFORMATION); | ||
alert.setTitle("Find"); | ||
alert.setHeaderText("Find"); | ||
alert.setContentText("No matches found."); | ||
alert.showAndWait(); | ||
event.consume(); // prevent the dialog from closing | ||
return; | ||
} | ||
if (previousNode != null) { | ||
this.removeHighlight(previousNode); | ||
} | ||
Node currentNode; | ||
if (this.type.equals(ButtonSearchType.NEXT)) { | ||
currentNode = this.searchResult.getNextResult(); | ||
} else { | ||
currentNode = this.searchResult.getPreviousResult(); | ||
} | ||
previousNode = currentNode; | ||
scrollPane.requestFocus(); | ||
this.modelisationNavigator.centerNodeInScrollPaneX(currentNode); | ||
this.modelisationNavigator.centerNodeInScrollPaneY(currentNode); | ||
|
||
String initialNodeStyle = currentNode.getStyle(); | ||
currentNode.setStyle(initialNodeStyle + HIGHLIGHT_STYLE); | ||
|
||
event.consume(); // prevent the dialog from closing | ||
} | ||
|
||
public void removeHighlight(Node node) { | ||
String nodeStyle = node.getStyle(); | ||
node.setStyle(nodeStyle.replace(HIGHLIGHT_STYLE, "")); | ||
} | ||
|
||
public void cleanSearchHighlight() { | ||
if (previousNode != null) { | ||
this.removeHighlight(previousNode); | ||
} | ||
} | ||
} |
Oops, something went wrong.