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

Adding text formatting for hits #9686

Merged
merged 6 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where custom field in the custom entry types could not be set to mulitline [#9609](https://github.com/JabRef/jabref/issues/9609)
- We fixed an issue where the Office XML exporter did not resolve BibTeX-Strings when exporting entries [forum#3741](https://discourse.jabref.org/t/exporting-bibtex-constant-strings-to-ms-office-2007-xml/3741)
- JabRef is now more relaxed when parsing field content: In case a field content ended with `\`, the combination `\}` was treated as plain `}`. [#9668](https://github.com/JabRef/jabref/issues/9668)
- We resolved an issue that cut off the number of group entries when it exceedet four digits. [#8797](https://github.com/JabRef/jabref/issues/8797)


### Removed
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/gui/groups/GroupTree.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
}

.numberColumn > .hits {
-fx-font-size: 85%;
-fx-font-size: 0.75em;
-fx-background-color: -jr-group-hits-bg;
-fx-padding: 0.4em 0.4em 0.4em 0.4em;
-fx-background-insets: 0;
-fx-background-radius: 0.8em;
-fx-background-radius: 0.7em;
}

.numberColumn > .hits .text {
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormat;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedList;
Expand All @@ -11,6 +12,7 @@
import java.util.stream.Collectors;

import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.css.PseudoClass;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -114,9 +116,9 @@ private void createNodes() {
mainColumn.setResizable(true);
numberColumn = new TreeTableColumn<>();
numberColumn.getStyleClass().add("numberColumn");
numberColumn.setMinWidth(40d);
numberColumn.setMaxWidth(40d);
numberColumn.setPrefWidth(40d);
numberColumn.setMinWidth(60d);
numberColumn.setMaxWidth(60d);
numberColumn.setPrefWidth(60d);
numberColumn.setResizable(false);
expansionNodeColumn = new TreeTableColumn<>();
expansionNodeColumn.getStyleClass().add("expansionNodeColumn");
Expand All @@ -131,7 +133,7 @@ private void createNodes() {
groupTree.getColumns().addAll(List.of(mainColumn, numberColumn, expansionNodeColumn));
this.setCenter(groupTree);

mainColumn.prefWidthProperty().bind(groupTree.widthProperty().subtract(60d).subtract(15));
mainColumn.prefWidthProperty().bind(groupTree.widthProperty().subtract(80d).subtract(15d));

addNewGroup = new Button(Localization.lang("Add group"));
addNewGroup.setId("addNewGroup");
Expand Down Expand Up @@ -217,6 +219,35 @@ private void initialize() {
}
});
text.getStyleClass().setAll("text");
text.textProperty().bind(Bindings.createStringBinding(() -> {
int hits = group.getHits().get();
if (hits >= 1000000) {
double millions = hits / 1000000.0;
return new DecimalFormat("#,##0.#").format(millions) + "m";
} else if (hits >= 1000) {
double thousands = hits / 1000.0;
return new DecimalFormat("#,##0.#").format(thousands) + "k";
} else {
return Integer.toString(hits);
}
}, group.getHits()));

text.styleProperty().bind(Bindings.createStringBinding(() -> {
double reducedFontSize;
double font_size = preferencesService.getAppearancePreferences().getMainFontSize();
// For each breaking point, the font size is reduced 0.20 em to fix issue 8797
if (font_size > 26.0) {
reducedFontSize = 0.25;
} else if (font_size > 22.0) {
reducedFontSize = 0.35;
} else if (font_size > 18.0) {
reducedFontSize = 0.55;
} else {
reducedFontSize = 0.75;
}
return String.format("-fx-font-size: %fem;", reducedFontSize);
}, preferencesService.getAppearancePreferences().mainFontSizeProperty()));

node.getChildren().add(text);
node.setMaxWidth(Control.USE_PREF_SIZE);
return node;
Expand Down