Skip to content

Commit

Permalink
refactor JabRef#3607
Browse files Browse the repository at this point in the history
- opacity is now set through a css pseudoclass instead of a property
  • Loading branch information
LukasGutenberg committed Mar 8, 2021
1 parent cb1cb5e commit aa5eea2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@
-fx-fill: -jr-search-text;
}

.file-row-text:opacity{
-fx-fill: derive(-jr-search-text, 70%);
}

.combo-box-base {
-fx-background-color: -fx-outer-border, -fx-control-inner-background;
-fx-background-insets: 0, 1;
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class LinkedFileViewModel extends AbstractViewModel {
private final XmpPreferences xmpPreferences;
private final LinkedFileHandler linkedFileHandler;
private final ExternalFileTypes externalFileTypes;
private final DoubleProperty opacityProperty = new SimpleDoubleProperty(1.0);

private final Validator fileExistsValidator;

Expand Down Expand Up @@ -177,12 +176,10 @@ public JabRefIcon getTypeIcon() {

public void markAsAutomaticallyFound() {
isAutomaticallyFound.setValue(true);
opacityProperty.setValue(0.7);
}

public void acceptAsLinked() {
isAutomaticallyFound.setValue(false);
opacityProperty.setValue(1.0);
}

public Observable[] getObservables() {
Expand Down Expand Up @@ -511,12 +508,4 @@ public LinkedFile getFile() {
public ValidationStatus fileExistsValidationStatus() {
return fileExistsValidator.getValidationStatus();
}

public DoubleProperty opacityProperty() {
return opacityProperty;
}

public void setOpacityProperty(double v) {
opacityProperty.setValue(v);
}
}
12 changes: 10 additions & 2 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javafx.beans.binding.Bindings;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.Parent;
Expand Down Expand Up @@ -137,12 +138,16 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve
}

private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
PseudoClass opacity = PseudoClass.getPseudoClass("opacity");

Node icon = linkedFile.getTypeIcon().getGraphicNode();
icon.setOnMouseClicked(event -> linkedFile.open());

Text link = new Text();
link.opacityProperty().bind(linkedFile.opacityProperty());
link.textProperty().bind(linkedFile.linkProperty());
link.getStyleClass().setAll("file-row-text");
link.pseudoClassStateChanged(opacity, linkedFile.isAutomaticallyFound());

Text desc = new Text();
desc.textProperty().bind(linkedFile.descriptionProperty());
desc.getStyleClass().setAll("file-row-text");
Expand All @@ -159,7 +164,10 @@ private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
acceptAutoLinkedFile.setTooltip(new Tooltip(Localization.lang("This file was found automatically. Do you want to link it to this entry?")));
acceptAutoLinkedFile.visibleProperty().bind(linkedFile.isAutomaticallyFoundProperty());
acceptAutoLinkedFile.managedProperty().bind(linkedFile.isAutomaticallyFoundProperty());
acceptAutoLinkedFile.setOnAction(event -> linkedFile.acceptAsLinked());
acceptAutoLinkedFile.setOnAction(event -> {
linkedFile.acceptAsLinked();
link.pseudoClassStateChanged(opacity, linkedFile.isAutomaticallyFound());
});
acceptAutoLinkedFile.getStyleClass().setAll("icon-button");

Button writeXMPMetadata = IconTheme.JabRefIcons.IMPORT.asButton();
Expand Down

0 comments on commit aa5eea2

Please sign in to comment.