Skip to content

Commit

Permalink
Fix the UI issue
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu16095 committed Feb 22, 2025
1 parent 93250d0 commit abb4182
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import java.util.Map;
import java.util.stream.Collectors;

import javafx.geometry.Bounds;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.stage.Window;

import org.jabref.logic.citationkeypattern.CitationKeyPattern;
import org.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -57,9 +59,6 @@ public void updateItem(String item, boolean empty) {
}

static class CitationKeyPatternSuggestionTextField extends TextField {
// Maximum number of entries that can be displayed in the popup menu.
private static final int MAX_ENTRIES = 7;

private final List<String> citationKeyPatterns;
private final ContextMenu suggestionsList;

Expand Down Expand Up @@ -99,8 +98,13 @@ private void setListener() {
}

private void populatePopup(List<String> searchResult) {
int heightOfMenuItem = 30; // Height of menu item
List<CustomMenuItem> menuItems = new ArrayList<>();
int count = Math.min(searchResult.size(), MAX_ENTRIES);

double space = getAvailableSpaceBelow(this);
int maxItems = (int) (space / heightOfMenuItem) - 1;

int count = Math.min(searchResult.size(), maxItems);

for (int i = 0; i < count; i++) {
final String result = searchResult.get(i);
Expand Down Expand Up @@ -128,6 +132,23 @@ private void populatePopup(List<String> searchResult) {
}
}

public static double getAvailableSpaceBelow(TextField textField) {
if (textField.getScene() == null || textField.getScene().getWindow() == null) {
return 0;
}

Window window = textField.getScene().getWindow();
if (window == null) {
return 0;
}

Bounds bounds = textField.localToScreen(textField.getBoundsInLocal());
double screenHeight = window.getHeight();
double textFieldBottom = bounds.getMinY() + textField.getHeight();

return screenHeight - (textFieldBottom - window.getY());
}

private Menu createPatternsSubMenu() {
Menu patternsSubMenu = new Menu(Localization.lang("All patterns"));

Expand Down

0 comments on commit abb4182

Please # to comment.