diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java index feedccbb192..601d1157cb5 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.java @@ -42,9 +42,7 @@ public void initContextMenu(final Supplier> items) { setOnContextMenuRequested(event -> { contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(this, Globals.getKeyPrefs())); contextMenu.getItems().addAll(0, items.get()); - contextMenu.show(this, event.getScreenX(), event.getScreenY()); - // TextInputControlBehavior.showContextMenu(this, contextMenu, event); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java index 648d92b51ea..7215916a22d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTextField.java @@ -38,9 +38,7 @@ public void initContextMenu(final Supplier> items) { setOnContextMenuRequested(event -> { contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(this, Globals.getKeyPrefs())); contextMenu.getItems().addAll(0, items.get()); - contextMenu.show(this, event.getScreenX(), event.getScreenY()); - // TextInputControlBehavior.showContextMenu(this, contextMenu, event); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java index 1907f6a5d2d..707f0a2661f 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java @@ -36,7 +36,7 @@ public OptionEditor(OptionEditorViewModel viewModel) { comboBox.getEditor().setOnContextMenuRequested(event -> { ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(comboBox.getEditor(), Globals.getKeyPrefs())); - TextInputControlBehavior.showContextMenu(comboBox.getEditor(), contextMenu, event); + contextMenu.show(comboBox, event.getScreenX(), event.getScreenY()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java b/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java deleted file mode 100644 index 31a45bc8c68..00000000000 --- a/src/main/java/org/jabref/gui/fieldeditors/TextInputControlBehavior.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.jabref.gui.fieldeditors; - -import javafx.geometry.Point2D; -import javafx.geometry.Rectangle2D; -import javafx.scene.Scene; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.TextArea; -import javafx.scene.control.TextField; -import javafx.scene.control.skin.TextAreaSkin; -import javafx.scene.control.skin.TextFieldSkin; -import javafx.scene.input.ContextMenuEvent; -import javafx.stage.Screen; -import javafx.stage.Window; - -import com.sun.javafx.scene.control.Properties; - -/** - * This class contains some code taken from {@link com.sun.javafx.scene.control.behavior.TextInputControlBehavior}, - * witch is not accessible and thus we have no other choice. - * TODO: remove this ugly workaround as soon as control behavior is made public - * reported at https://github.com/javafxports/openjdk-jfx/issues/583 - */ -public class TextInputControlBehavior { - - /** - * taken from {@link com.sun.javafx.scene.control.behavior.TextFieldBehavior#contextMenuRequested(javafx.scene.input.ContextMenuEvent)} - */ - public static void showContextMenu(TextField textField, ContextMenu contextMenu, ContextMenuEvent e) { - double screenX = e.getScreenX(); - double screenY = e.getScreenY(); - double sceneX = e.getSceneX(); - - TextFieldSkin skin = (TextFieldSkin) textField.getSkin(); - - if (Properties.IS_TOUCH_SUPPORTED) { - Point2D menuPos; - if (textField.getSelection().getLength() == 0) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } else { - menuPos = skin.getMenuPosition(); - if (menuPos != null && (menuPos.getX() <= 0 || menuPos.getY() <= 0)) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } - } - - if (menuPos != null) { - Point2D p = textField.localToScene(menuPos); - Scene scene = textField.getScene(); - Window window = scene.getWindow(); - Point2D location = new Point2D(window.getX() + scene.getX() + p.getX(), - window.getY() + scene.getY() + p.getY()); - screenX = location.getX(); - sceneX = p.getX(); - screenY = location.getY(); - } - } - - double menuWidth = contextMenu.prefWidth(-1); - double menuX = screenX - (Properties.IS_TOUCH_SUPPORTED ? (menuWidth / 2) : 0); - Screen currentScreen = Screen.getPrimary(); - Rectangle2D bounds = currentScreen.getBounds(); - - if (menuX < bounds.getMinX()) { - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textField, bounds.getMinX(), screenY); - } else if (screenX + menuWidth > bounds.getMaxX()) { - double leftOver = menuWidth - (bounds.getMaxX() - screenX); - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textField, screenX - leftOver, screenY); - } else { - textField.getProperties().put("CONTEXT_MENU_SCREEN_X", 0); - textField.getProperties().put("CONTEXT_MENU_SCENE_X", 0); - contextMenu.show(textField, menuX, screenY); - } - - e.consume(); - } - - /** - * taken from {@link com.sun.javafx.scene.control.behavior.TextAreaBehavior#contextMenuRequested(javafx.scene.input.ContextMenuEvent)} - */ - public static void showContextMenu(TextArea textArea, ContextMenu contextMenu, ContextMenuEvent e) { - double screenX = e.getScreenX(); - double screenY = e.getScreenY(); - double sceneX = e.getSceneX(); - - TextAreaSkin skin = (TextAreaSkin) textArea.getSkin(); - - if (Properties.IS_TOUCH_SUPPORTED) { - Point2D menuPos; - if (textArea.getSelection().getLength() == 0) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } else { - menuPos = skin.getMenuPosition(); - if (menuPos != null && (menuPos.getX() <= 0 || menuPos.getY() <= 0)) { - skin.positionCaret(skin.getIndex(e.getX(), e.getY()), false); - menuPos = skin.getMenuPosition(); - } - } - - if (menuPos != null) { - Point2D p = textArea.localToScene(menuPos); - Scene scene = textArea.getScene(); - Window window = scene.getWindow(); - Point2D location = new Point2D(window.getX() + scene.getX() + p.getX(), - window.getY() + scene.getY() + p.getY()); - screenX = location.getX(); - sceneX = p.getX(); - screenY = location.getY(); - } - } - - double menuWidth = contextMenu.prefWidth(-1); - double menuX = screenX - (Properties.IS_TOUCH_SUPPORTED ? (menuWidth / 2) : 0); - Screen currentScreen = Screen.getPrimary(); - Rectangle2D bounds = currentScreen.getBounds(); - - if (menuX < bounds.getMinX()) { - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textArea, bounds.getMinX(), screenY); - } else if (screenX + menuWidth > bounds.getMaxX()) { - double leftOver = menuWidth - (bounds.getMaxX() - screenX); - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", screenX); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", sceneX); - contextMenu.show(textArea, screenX - leftOver, screenY); - } else { - textArea.getProperties().put("CONTEXT_MENU_SCREEN_X", 0); - textArea.getProperties().put("CONTEXT_MENU_SCENE_X", 0); - contextMenu.show(textArea, menuX, screenY); - } - - e.consume(); - } -} diff --git a/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java b/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java index 2ca9cf1e407..bf3272d6d28 100644 --- a/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java +++ b/src/main/java/org/jabref/gui/util/component/TemporalAccessorPicker.java @@ -19,7 +19,6 @@ import javafx.util.StringConverter; import org.jabref.gui.Globals; -import org.jabref.gui.fieldeditors.TextInputControlBehavior; import org.jabref.gui.fieldeditors.contextmenu.EditorContextAction; import org.jabref.gui.util.BindingsHelper; import org.jabref.model.entry.Date; @@ -28,18 +27,18 @@ /** * A date picker with configurable datetime format where both date and time can be changed via the text field and the * date can additionally be changed via the JavaFX default date picker. Also supports incomplete dates. - * + *

* First recall how the date picker normally works: - The user selects a date in the popup, which sets {@link * #valueProperty()} to the selected date. - The converter ({@link #converterProperty()}) is used to transform the date * to a string representation and display it in the text field. - * + *

* The idea is now to intercept the process and add an additional step: - The user selects a date in the popup, which * sets {@link #valueProperty()} to the selected date. - The date is converted to a {@link TemporalAccessor} (i.e, * enriched by a time component) using {@link #addCurrentTime(LocalDate)} - The string converter ({@link * #stringConverterProperty()}) is used to transform the temporal accessor to a string representation and display it in * the text field. - * - * Inspiration taken from https://github.com/edvin/tornadofx-controls/blob/master/src/main/java/tornadofx/control/DateTimePicker.java + *

+ * Inspiration taken from Controlsfx DateTimePicker */ public class TemporalAccessorPicker extends DatePicker { private final ObjectProperty temporalAccessorValue = new SimpleObjectProperty<>(null); @@ -58,7 +57,7 @@ public TemporalAccessorPicker() { getEditor().setOnContextMenuRequested(event -> { ContextMenu contextMenu = new ContextMenu(); contextMenu.getItems().setAll(EditorContextAction.getDefaultContextMenuItems(getEditor(), Globals.getKeyPrefs())); - TextInputControlBehavior.showContextMenu(getEditor(), contextMenu, event); + contextMenu.show(this, event.getScreenX(), event.getScreenY()); }); }