4646import javafx .scene .control .SpinnerValueFactory ;
4747import javafx .scene .control .TextArea ;
4848import javafx .scene .input .KeyCode ;
49+ import javafx .scene .input .KeyCodeCombination ;
4950import javafx .scene .input .KeyEvent ;
5051import javafx .scene .layout .GridPane ;
5152import javafx .scene .paint .Color ;
@@ -202,6 +203,8 @@ public Project fromString(final String string) {
202203
203204 );
204205
206+ enableStrgA_combo ();
207+
205208 projectComboBox .getEditor ().textProperty ().addListener (new ChangeListener <String >() {
206209
207210 boolean isValidProject = true ;
@@ -257,19 +260,6 @@ public void changed(final ObservableValue<? extends String> observable, final St
257260
258261 });
259262
260- // strg+a Behaviour bug hack
261- // https://stackoverflow.com/questions/51943654/javafx-combobox-make-control-a-select-all-in-text-box-while-dropdown-is-visi
262- projectComboBox .setOnShown (e -> {
263- final ComboBoxListViewSkin <?> skin = (ComboBoxListViewSkin <?>) projectComboBox .getSkin ();
264- final ListView <?> list = (ListView <?>) skin .getPopupContent ();
265- list .addEventFilter (KeyEvent .KEY_PRESSED , keyEvent -> {
266- if (keyEvent .isControlDown () && keyEvent .getCode () == KeyCode .A ) {
267- projectComboBox .getEditor ().selectAll ();
268- }
269- });
270- projectComboBox .setOnShown (null );
271- });
272-
273263 // on
274264 projectComboBox .setOnKeyReleased (ke -> {
275265 if (ke .getCode () == KeyCode .ENTER && projectComboBox .getSelectionModel ().isEmpty ()) {
@@ -300,7 +290,29 @@ public void initializeWith(final Work work) {
300290 setColor (projectComboBox .getEditor (), model .hoverBackgroundColor .get ());
301291
302292 setTextColor (projectComboBox .getEditor (), model .hoverFontColor .get ());
293+ }
294+
295+ public Work getWorkFromUserInput () {
296+ return new Work (startDatePicker .getValue (),
297+ LocalDateTime .of (startDatePicker .getValue (), startTimeSpinner .getValue ()),
298+ LocalDateTime .of (endDatePicker .getValue (), endTimeSpinner .getValue ()), selectedProject ,
299+ noteTextArea .getText ());
300+ }
303301
302+ private void enableStrgA_combo () {
303+ // strg+a Behaviour bug hack
304+ // https://stackoverflow.com/questions/51943654/javafx-combobox-make-control-a-select-all-in-text-box-while-dropdown-is-visi
305+ projectComboBox .setOnShown (e -> {
306+ final ComboBoxListViewSkin <?> skin = (ComboBoxListViewSkin <?>) projectComboBox .getSkin ();
307+ final ListView <?> list = (ListView <?>) skin .getPopupContent ();
308+ final KeyCodeCombination ctrlA = new KeyCodeCombination (KeyCode .A , KeyCodeCombination .CONTROL_DOWN );
309+ list .addEventFilter (KeyEvent .KEY_PRESSED , keyEvent -> {
310+ if (ctrlA .match (keyEvent )) {
311+ projectComboBox .getEditor ().selectAll ();
312+ }
313+ });
314+ projectComboBox .setOnShown (null );
315+ });
304316 }
305317
306318 private void setColor (final Node object , final Color color ) {
@@ -315,12 +327,4 @@ private void setTextColor(final Node object, final Color color) {
315327 object .setStyle (style );
316328 }
317329
318- public Work getWorkFromUserInput () {
319-
320- return new Work (startDatePicker .getValue (),
321- LocalDateTime .of (startDatePicker .getValue (), startTimeSpinner .getValue ()),
322- LocalDateTime .of (endDatePicker .getValue (), endTimeSpinner .getValue ()), selectedProject ,
323- noteTextArea .getText ());
324- }
325-
326330}
0 commit comments