2
2
3
3
import javax .inject .Inject ;
4
4
5
+ import javafx .animation .Interpolator ;
6
+ import javafx .animation .KeyFrame ;
7
+ import javafx .animation .KeyValue ;
8
+ import javafx .animation .Timeline ;
9
+ import javafx .beans .property .ObjectProperty ;
10
+ import javafx .beans .property .SimpleObjectProperty ;
11
+ import javafx .beans .property .SimpleStringProperty ;
12
+ import javafx .beans .property .StringProperty ;
13
+ import javafx .collections .transformation .FilteredList ;
14
+ import javafx .event .ActionEvent ;
5
15
import javafx .fxml .FXML ;
6
16
import javafx .scene .control .Button ;
7
17
import javafx .scene .control .ComboBox ;
10
20
import javafx .scene .control .TableColumn ;
11
21
import javafx .scene .control .TableView ;
12
22
import javafx .scene .control .cell .TextFieldTableCell ;
23
+ import javafx .scene .paint .Color ;
24
+ import javafx .util .Duration ;
13
25
14
26
import org .jabref .gui .icon .IconTheme ;
15
27
import org .jabref .gui .preferences .AbstractPreferenceTabView ;
16
28
import org .jabref .gui .preferences .PreferencesTab ;
29
+ import org .jabref .gui .util .ColorUtil ;
17
30
import org .jabref .gui .util .TaskExecutor ;
18
31
import org .jabref .logic .journals .JournalAbbreviationRepository ;
19
32
import org .jabref .logic .l10n .Localization ;
20
33
21
34
import com .airhacks .afterburner .views .ViewLoader ;
22
35
import com .tobiasdiez .easybind .EasyBind ;
36
+ import org .controlsfx .control .textfield .CustomTextField ;
23
37
24
38
/**
25
39
* This class controls the user interface of the journal abbreviations dialog. The UI elements and their layout are
@@ -33,16 +47,23 @@ public class JournalAbbreviationsTab extends AbstractPreferenceTabView<JournalAb
33
47
@ FXML private TableColumn <AbbreviationViewModel , String > journalTableNameColumn ;
34
48
@ FXML private TableColumn <AbbreviationViewModel , String > journalTableAbbreviationColumn ;
35
49
@ FXML private TableColumn <AbbreviationViewModel , String > journalTableShortestUniqueAbbreviationColumn ;
50
+ private FilteredList <AbbreviationViewModel > filteredAbbreviations ;
36
51
@ FXML private ComboBox <AbbreviationsFileViewModel > journalFilesBox ;
37
52
@ FXML private Button addAbbreviationButton ;
38
53
@ FXML private Button removeAbbreviationButton ;
39
54
@ FXML private Button openAbbreviationListButton ;
40
55
@ FXML private Button addAbbreviationListButton ;
41
56
@ FXML private Button removeAbbreviationListButton ;
42
57
58
+ @ FXML private CustomTextField searchBox ;
59
+
43
60
@ Inject private TaskExecutor taskExecutor ;
44
61
@ Inject private JournalAbbreviationRepository abbreviationRepository ;
45
62
63
+ private Timeline invalidateSearch ;
64
+ private ObjectProperty <Color > flashingColor ;
65
+ private StringProperty flashingColorStringProperty ;
66
+
46
67
public JournalAbbreviationsTab () {
47
68
ViewLoader .view (this )
48
69
.root (this )
@@ -53,9 +74,15 @@ public JournalAbbreviationsTab() {
53
74
private void initialize () {
54
75
viewModel = new JournalAbbreviationsTabViewModel (preferencesService , dialogService , taskExecutor , abbreviationRepository );
55
76
77
+ filteredAbbreviations = new FilteredList <>(viewModel .abbreviationsProperty ());
78
+
56
79
setButtonStyles ();
57
80
setUpTable ();
58
81
setBindings ();
82
+ setAnimations ();
83
+
84
+ searchBox .setPromptText (Localization .lang ("Search" ) + "..." );
85
+ searchBox .setLeft (IconTheme .JabRefIcons .SEARCH .getGraphicNode ());
59
86
}
60
87
61
88
private void setButtonStyles () {
@@ -78,7 +105,7 @@ private void setUpTable() {
78
105
}
79
106
80
107
private void setBindings () {
81
- journalAbbreviationsTable .itemsProperty (). bindBidirectional ( viewModel . abbreviationsProperty () );
108
+ journalAbbreviationsTable .setItems ( filteredAbbreviations );
82
109
83
110
EasyBind .subscribe (journalAbbreviationsTable .getSelectionModel ().selectedItemProperty (), newValue ->
84
111
viewModel .currentAbbreviationProperty ().set (newValue ));
@@ -98,6 +125,27 @@ private void setBindings() {
98
125
99
126
loadingLabel .visibleProperty ().bind (viewModel .isLoadingProperty ());
100
127
progressIndicator .visibleProperty ().bind (viewModel .isLoadingProperty ());
128
+
129
+ searchBox .textProperty ().addListener ((observable , previousText , searchTerm ) -> {
130
+ filteredAbbreviations .setPredicate (abbreviation -> searchTerm .isEmpty () ? true : abbreviation .containsCaseIndependent (searchTerm ));
131
+ });
132
+ }
133
+
134
+ private void setAnimations () {
135
+ flashingColor = new SimpleObjectProperty <>(Color .TRANSPARENT );
136
+ flashingColorStringProperty = createFlashingColorStringProperty (flashingColor );
137
+ searchBox .styleProperty ().bind (
138
+ new SimpleStringProperty ("-fx-control-inner-background: " ).concat (flashingColorStringProperty ).concat (";" )
139
+ );
140
+ invalidateSearch = new Timeline (
141
+ new KeyFrame (Duration .seconds (0 ), new KeyValue (flashingColor , Color .TRANSPARENT , Interpolator .LINEAR )),
142
+ new KeyFrame (Duration .seconds (0.25 ), new KeyValue (flashingColor , Color .RED , Interpolator .LINEAR )),
143
+ new KeyFrame (Duration .seconds (0.25 ), new KeyValue (searchBox .textProperty (), "" , Interpolator .DISCRETE )),
144
+ new KeyFrame (Duration .seconds (0.25 ), (ActionEvent event ) -> {
145
+ addAbbreviationActions ();
146
+ }),
147
+ new KeyFrame (Duration .seconds (0.5 ), new KeyValue (flashingColor , Color .TRANSPARENT , Interpolator .LINEAR ))
148
+ );
101
149
}
102
150
103
151
@ FXML
@@ -117,11 +165,30 @@ private void removeList() {
117
165
118
166
@ FXML
119
167
private void addAbbreviation () {
168
+ if (!searchBox .getText ().isEmpty ()) {
169
+ invalidateSearch .play ();
170
+ } else {
171
+ addAbbreviationActions ();
172
+ }
173
+ }
174
+
175
+ private void addAbbreviationActions () {
120
176
viewModel .addAbbreviation ();
121
177
selectNewAbbreviation ();
122
178
editAbbreviation ();
123
179
}
124
180
181
+ private static StringProperty createFlashingColorStringProperty (final ObjectProperty <Color > flashingColor ) {
182
+ final StringProperty flashingColorStringProperty = new SimpleStringProperty ();
183
+ setColorStringFromColor (flashingColorStringProperty , flashingColor );
184
+ flashingColor .addListener ((observable , oldValue , newValue ) -> setColorStringFromColor (flashingColorStringProperty , flashingColor ));
185
+ return flashingColorStringProperty ;
186
+ }
187
+
188
+ private static void setColorStringFromColor (StringProperty colorStringProperty , ObjectProperty <Color > color ) {
189
+ colorStringProperty .set (ColorUtil .toRGBACode (color .get ()));
190
+ }
191
+
125
192
@ FXML
126
193
private void editAbbreviation () {
127
194
journalAbbreviationsTable .edit (
@@ -138,7 +205,7 @@ private void selectNewAbbreviation() {
138
205
int lastRow = viewModel .abbreviationsCountProperty ().get () - 1 ;
139
206
journalAbbreviationsTable .scrollTo (lastRow );
140
207
journalAbbreviationsTable .getSelectionModel ().select (lastRow );
141
- journalAbbreviationsTable .getFocusModel ().focus (lastRow );
208
+ journalAbbreviationsTable .getFocusModel ().focus (lastRow , journalTableNameColumn );
142
209
}
143
210
144
211
@ Override
0 commit comments