Skip to content

JournalAbbreviation search feature #7804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import javax.inject.Inject;

import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.transformation.FilteredList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
Expand All @@ -11,6 +19,8 @@
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.paint.Color;
import javafx.util.Duration;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.preferences.AbstractPreferenceTabView;
Expand Down Expand Up @@ -48,6 +58,10 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView<JournalAb
@Inject private TaskExecutor taskExecutor;
@Inject private JournalAbbreviationRepository abbreviationRepository;

private Timeline invalidateSearch;
private ObjectProperty<Color> flashingColor;
private StringProperty flashingColorStringProperty;

public JournalAbbreviationsTab() {
ViewLoader.view(this)
.root(this)
Expand All @@ -63,6 +77,7 @@ private void initialize() {
setButtonStyles();
setUpTable();
setBindings();
setAnimations();

searchBox.setPromptText(Localization.lang("Search") + "...");
searchBox.setLeft(IconTheme.JabRefIcons.SEARCH.getGraphicNode());
Expand Down Expand Up @@ -114,6 +129,20 @@ private void setBindings() {
});
}

private void setAnimations() {
flashingColor = new SimpleObjectProperty<>(Color.TRANSPARENT);
flashingColorStringProperty = createFlashingColorStringProperty(flashingColor);
searchBox.styleProperty().bind(
new SimpleStringProperty("-fx-background-color: ").concat(flashingColorStringProperty).concat(";")
);
invalidateSearch = new Timeline(
new KeyFrame(Duration.seconds(0), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR)),
new KeyFrame(Duration.seconds(0.25), new KeyValue(flashingColor, Color.RED, Interpolator.LINEAR)),
new KeyFrame(Duration.seconds(0.25), new KeyValue(searchBox.textProperty(), "", Interpolator.DISCRETE)),
new KeyFrame(Duration.seconds(0.5), new KeyValue(flashingColor, Color.TRANSPARENT, Interpolator.LINEAR))
);
}

@FXML
private void addList() {
viewModel.addNewFile();
Expand All @@ -132,11 +161,31 @@ private void removeList() {
@FXML
private void addAbbreviation() {
viewModel.addAbbreviation();
searchBox.textProperty().set("");
if (!searchBox.getText().isEmpty()) {
invalidateSearch.play();
}
selectNewAbbreviation();
editAbbreviation();
}

private static StringProperty createFlashingColorStringProperty(final ObjectProperty<Color> flashingColor) {
final StringProperty flashingColorStringProperty = new SimpleStringProperty();
setColorStringFromColor(flashingColorStringProperty, flashingColor);
flashingColor.addListener((observable, oldValue, newValue) -> setColorStringFromColor(flashingColorStringProperty, flashingColor));
return flashingColorStringProperty;
}

private static void setColorStringFromColor(StringProperty colorStringProperty, ObjectProperty<Color> color) {
colorStringProperty.set(
"rgba(" +
((int) (color.get().getRed() * 255)) + "," +
((int) (color.get().getGreen() * 255)) + "," +
((int) (color.get().getBlue() * 255)) + "," +
color.get().getOpacity() +
")"
);
}

@FXML
private void editAbbreviation() {
journalAbbreviationsTable.edit(
Expand Down