-
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.
- Loading branch information
Showing
12 changed files
with
390 additions
and
97 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
6 changes: 6 additions & 0 deletions
6
src/main/java/components/interviewPanel/search/ButtonSearchType.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,6 @@ | ||
package components.interviewPanel.search; | ||
|
||
public enum ButtonSearchType { | ||
PREVIOUS, | ||
NEXT | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/components/interviewPanel/search/SearchButtonHandler.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,45 @@ | ||
package components.interviewPanel.search; | ||
|
||
import javafx.event.ActionEvent; | ||
import javafx.event.EventHandler; | ||
import javafx.scene.control.Alert; | ||
import models.SearchResult; | ||
import org.fxmisc.richtext.InlineCssTextArea; | ||
|
||
public class SearchButtonHandler implements EventHandler<ActionEvent> { | ||
|
||
private ButtonSearchType type; | ||
private SearchResult searchResult; | ||
private InlineCssTextArea richTextArea; | ||
|
||
public SearchButtonHandler(ButtonSearchType type, SearchResult searchResult, InlineCssTextArea richTextArea) { | ||
this.type = type; | ||
this.searchResult = searchResult; | ||
this.richTextArea = richTextArea; | ||
} | ||
|
||
@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; | ||
} | ||
int currentPosition; | ||
|
||
if (this.type.equals(ButtonSearchType.NEXT)) { | ||
currentPosition = this.searchResult.getNextResult(); | ||
} else { | ||
currentPosition = this.searchResult.getPreviousResult(); | ||
} | ||
richTextArea.requestFocus(); | ||
richTextArea.moveTo(currentPosition); | ||
richTextArea.requestFollowCaret(); | ||
richTextArea.selectRange(currentPosition, currentPosition + this.searchResult.getCurrentSearchWord().length()); | ||
event.consume(); // prevent the dialog from closing | ||
} | ||
} |
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
Oops, something went wrong.