Skip to content
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

Fix/12351 area of preview hover #12355

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
34 changes: 30 additions & 4 deletions src/main/java/org/jabref/gui/maintable/MainTableTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

Expand All @@ -17,26 +18,51 @@ public class MainTableTooltip extends Tooltip {

private final PreviewViewer preview;
private final GuiPreferences preferences;
private final VBox tooltipContent = new VBox();
private final Label fieldValueLabel = new Label();
private final VBox tooltipContent = new VBox(); // A vertical box to hold the tooltip content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comments they are just describing the code itself

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private final Label fieldValueLabel = new Label(); // Label to show field value

public MainTableTooltip(DialogService dialogService, GuiPreferences preferences, ThemeManager themeManager, TaskExecutor taskExecutor) {
this.preferences = preferences;
this.preview = new PreviewViewer(dialogService, preferences, themeManager, taskExecutor);
this.setShowDelay(Duration.seconds(1));

this.setShowDelay(Duration.millis(100)); // 100ms delay
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you change the delay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grafik

This can be discussed.
How does the tooltip behave in other applications, word for instance?

this.setHideDelay(Duration.millis(500)); // Slight delay before hiding

// Add the field value label and preview area to the tooltip content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoce the comments everywhere here, they state the obvious. Use comments only when you want to why you did something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

this.tooltipContent.getChildren().addAll(fieldValueLabel, preview);

// Add some basic styling to the tooltip
tooltipContent.setStyle("-fx-padding: 10; -fx-background-color: white; -fx-border-color: gray; -fx-border-radius: 5;");
}

public Tooltip createTooltip(BibDatabaseContext databaseContext, BibEntry entry, String fieldValue) {
// Set the text for the field value label
fieldValueLabel.setText(fieldValue + "\n");

// Make sure the text wraps if it's too long
fieldValueLabel.setWrapText(true);
fieldValueLabel.setMaxWidth(400); // Set a limit for how wide the text can be

// Automatically size the tooltip content based on what's inside
tooltipContent.setPrefSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
tooltipContent.setMaxWidth(500); // Prevent the tooltip from being too wide
tooltipContent.setMaxHeight(400); // Prevent the tooltip from being too tall

// If the user has enabled preview in the preferences
if (preferences.getPreviewPreferences().shouldShowPreviewEntryTableTooltip()) {
// Set up the preview
preview.setLayout(preferences.getPreviewPreferences().getSelectedPreviewLayout());
preview.setDatabaseContext(databaseContext);
preview.setEntry(entry);

// Show both the field value and the preview
this.setGraphic(tooltipContent);
} else {
// If preview is disabled, only show the field value
this.setGraphic(fieldValueLabel);
}
return this;

return this; // Return the tooltip object
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ public List<IntegrityMessage> check(BibEntry entry) {
.ifPresent(val -> messages.add(new IntegrityMessage(Localization.lang("abbreviation detected"), entry, field)));
}
return messages;
}
}
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Siedlerchr i expected checkstyle to complain here, but it's green. Maybe we need to add a rule.

Loading