Skip to content

Commit

Permalink
Merge pull request #5259 from r0light/mdiconfactoryworkaround
Browse files Browse the repository at this point in the history
Avoid erroneous MaterialDesignIconFactory
  • Loading branch information
Siedlerchr authored Sep 2, 2019
2 parents 853c4fd + 047cbef commit 89ebaf7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,4 @@ lib/ojdbc.jar
!/buildSrc/src/main/groovy/org/jabref/build

# do not ignore JabRef icons (they are ignored by the macos setting above)
!gui/icon/**/*
!src/main/java/org/jabref/gui/icon
21 changes: 9 additions & 12 deletions src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.ValueTableCellFactory;
import org.jabref.logic.l10n.Localization;

import com.airhacks.afterburner.views.ViewLoader;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory;

public class CopyFilesDialogView extends BaseDialog<Void> {

@FXML private TableView<CopyFilesResultItemViewModel> tvResult;
@FXML private TableColumn<CopyFilesResultItemViewModel, MaterialDesignIcon> colStatus;
@FXML private TableColumn<CopyFilesResultItemViewModel, JabRefIcon> colStatus;
@FXML private TableColumn<CopyFilesResultItemViewModel, String> colMessage;
@FXML private TableColumn<CopyFilesResultItemViewModel, String> colFile;
private final CopyFilesDialogViewModel viewModel;
Expand Down Expand Up @@ -46,16 +45,14 @@ private void setupTable() {
colStatus.setCellValueFactory(cellData -> cellData.getValue().getIcon());

colFile.setCellFactory(new ValueTableCellFactory<CopyFilesResultItemViewModel, String>().withText(item -> item).withTooltip(item -> item));
colStatus.setCellFactory(new ValueTableCellFactory<CopyFilesResultItemViewModel, MaterialDesignIcon>().withGraphic(item -> {

Text icon = MaterialDesignIconFactory.get().createIcon(item);
if (item == MaterialDesignIcon.CHECK) {
icon.setFill(Color.GREEN);
colStatus.setCellFactory(new ValueTableCellFactory<CopyFilesResultItemViewModel, JabRefIcon>().withGraphic(item -> {
if (item == IconTheme.JabRefIcons.CHECK) {
item = item.withColor(Color.GREEN);
}
if (item == MaterialDesignIcon.ALERT) {
icon.setFill(Color.RED);
if (item == IconTheme.JabRefIcons.WARNING) {
item = item.withColor(Color.RED);
}
return icon;
return item.getGraphicNode();
}));

tvResult.setItems(viewModel.copyFilesResultListProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.icon.JabRefIcon;

public class CopyFilesResultItemViewModel {

private final StringProperty file = new SimpleStringProperty("");
private final ObjectProperty<MaterialDesignIcon> icon = new SimpleObjectProperty<>(MaterialDesignIcon.ALERT);
private final ObjectProperty<JabRefIcon> icon = new SimpleObjectProperty<>(IconTheme.JabRefIcons.WARNING);
private final StringProperty message = new SimpleStringProperty("");

public CopyFilesResultItemViewModel(Path file, boolean success, String message) {
this.file.setValue(file.toString());
this.message.setValue(message);
if (success) {
this.icon.setValue(MaterialDesignIcon.CHECK);
this.icon.setValue(IconTheme.JabRefIcons.CHECK);
}
}

Expand All @@ -31,7 +32,7 @@ public StringProperty getMessage() {
return message;
}

public ObjectProperty<MaterialDesignIcon> getIcon() {
public ObjectProperty<JabRefIcon> getIcon() {
return icon;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider;
import org.jabref.gui.copyfiles.CopySingleFileAction;
import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand All @@ -42,8 +43,6 @@
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory;

public class LinkedFilesEditor extends HBox implements FieldEditorFX {

Expand Down Expand Up @@ -142,13 +141,13 @@ private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
info.setStyle("-fx-padding: 0.5em 0 0.5em 0;"); // To align with buttons below which also have 0.5em padding
info.getChildren().setAll(icon, link, desc, progressIndicator);

Button acceptAutoLinkedFile = MaterialDesignIconFactory.get().createIconButton(MaterialDesignIcon.BRIEFCASE_CHECK);
Button acceptAutoLinkedFile = IconTheme.JabRefIcons.AUTO_LINKED_FILE.asButton();
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.setOnAction(event -> linkedFile.acceptAsLinked());
acceptAutoLinkedFile.getStyleClass().setAll("icon-button");

Button writeXMPMetadata = MaterialDesignIconFactory.get().createIconButton(MaterialDesignIcon.IMPORT);
Button writeXMPMetadata = IconTheme.JabRefIcons.IMPORT.asButton();
writeXMPMetadata.setTooltip(new Tooltip(Localization.lang("Write BibTeXEntry as XMP-metadata to PDF.")));
writeXMPMetadata.visibleProperty().bind(linkedFile.canWriteXMPMetadataProperty());
writeXMPMetadata.setOnAction(event -> linkedFile.writeXMPMetadata());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.jabref.model.strings.StringUtil;

import com.google.common.base.Enums;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import org.fxmisc.easybind.EasyBind;

public class GroupNodeViewModel {
Expand Down Expand Up @@ -200,7 +199,7 @@ private JabRefIcon createDefaultIcon() {
}

private Optional<JabRefIcon> parseIcon(String iconCode) {
return Enums.getIfPresent(MaterialDesignIcon.class, iconCode.toUpperCase(Locale.ENGLISH))
return Enums.getIfPresent(IconTheme.JabRefIcons.class, iconCode.toUpperCase(Locale.ENGLISH))
.toJavaUtil()
.map(icon -> new InternalMaterialDesignIcon(getColor(), icon));
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import javafx.scene.image.Image;
import javafx.scene.paint.Color;

import org.jabref.logic.groups.DefaultGroupsFactory;
import org.jabref.preferences.JabRefPreferences;

import de.jensd.fx.glyphs.GlyphIcons;
Expand Down Expand Up @@ -209,6 +208,7 @@ public enum JabRefIcons implements JabRefIcon {
EXPORT_TO_CLIPBOARD(MaterialDesignIcon.CLIPBOARD_ARROW_LEFT) /*css: clipboard-arrow-left */,
ATTACH_FILE(MaterialDesignIcon.PAPERCLIP) /*css: paperclip*/,
AUTO_FILE_LINK(MaterialDesignIcon.FILE_FIND) /*css: file-find */,
AUTO_LINKED_FILE(MaterialDesignIcon.BRIEFCASE_CHECK) /*css: briefcase-check */,
QUALITY_ASSURED(MaterialDesignIcon.CERTIFICATE), /*css: certificate */
QUALITY(MaterialDesignIcon.CERTIFICATE), /*css: certificate */
OPEN(MaterialDesignIcon.FOLDER_OUTLINE) /*css: folder */,
Expand Down Expand Up @@ -251,6 +251,7 @@ public enum JabRefIcons implements JabRefIcon {
FIND_DUPLICATES(MaterialDesignIcon.CODE_EQUAL), /*css: code-equal */
CONNECT_DB(MaterialDesignIcon.CLOUD_UPLOAD), /*cloud-upload*/
SUCCESS(MaterialDesignIcon.CHECK_CIRCLE),
CHECK(MaterialDesignIcon.CHECK) /*css: check */,
WARNING(MaterialDesignIcon.ALERT),
ERROR(MaterialDesignIcon.ALERT_CIRCLE),
CASE_SENSITIVE(MaterialDesignIcon.ALPHABETICAL), /* css: mdi-alphabetical */
Expand All @@ -263,7 +264,7 @@ public enum JabRefIcons implements JabRefIcon {
DATE_PICKER(MaterialDesignIcon.CALENDAR), /* css: calendar */
DEFAULT_GROUP_ICON_COLORED(MaterialDesignIcon.PLAY),
DEFAULT_GROUP_ICON(MaterialDesignIcon.LABEL_OUTLINE),
ALL_ENTRIES_GROUP_ICON(DefaultGroupsFactory.ALL_ENTRIES_GROUP_DEFAULT_ICON),
ALL_ENTRIES_GROUP_ICON(MaterialDesignIcon.DATABASE),
IMPORT(MaterialDesignIcon.CALL_RECEIVED),
EXPORT(MaterialDesignIcon.CALL_MADE),
PREVIOUS_LEFT(MaterialDesignIcon.CHEVRON_LEFT),
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/jabref/gui/util/ViewModelListCellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
import javafx.scene.control.Tooltip;
import javafx.scene.input.DragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;
import javafx.util.Callback;

import org.jabref.gui.icon.JabRefIcon;
import org.jabref.model.strings.StringUtil;

import de.jensd.fx.glyphs.GlyphIcons;
import de.jensd.fx.glyphs.materialdesignicons.utils.MaterialDesignIconFactory;

/**
* Constructs a {@link ListCell} based on the view model of the row and a bunch of specified converter methods.
*
Expand Down Expand Up @@ -53,22 +50,21 @@ public ViewModelListCellFactory<T> withGraphic(Callback<T, Node> toGraphic) {
return this;
}

public ViewModelListCellFactory<T> withIcon(Callback<T, GlyphIcons> toIcon) {
public ViewModelListCellFactory<T> withIcon(Callback<T, JabRefIcon> toIcon) {
this.toGraphic = viewModel -> {
GlyphIcons icon = toIcon.call(viewModel);
JabRefIcon icon = toIcon.call(viewModel);
if (icon != null) {
return MaterialDesignIconFactory.get().createIcon(icon);
return icon.getGraphicNode();
}
return null;
};
return this;
}

public ViewModelListCellFactory<T> withIcon(Callback<T, GlyphIcons> toIcon, Callback<T, Paint> toColor) {
public ViewModelListCellFactory<T> withIcon(Callback<T, JabRefIcon> toIcon, Callback<T, Color> toColor) {
this.toGraphic = viewModel -> {
Text graphic = MaterialDesignIconFactory.get().createIcon(toIcon.call(viewModel));
graphic.setFill(toColor.call(viewModel));
return graphic;

return toIcon.call(viewModel).withColor(toColor.call(viewModel)).getGraphicNode();
};
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.groups.AllEntriesGroup;

import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;

public class DefaultGroupsFactory {

public static MaterialDesignIcon ALL_ENTRIES_GROUP_DEFAULT_ICON = MaterialDesignIcon.DATABASE;
private static String ALL_ENTRIES_GROUP_DEFAULT_ICON = "ALL_ENTRIES_GROUP_ICON";

private DefaultGroupsFactory() {
}

public static AllEntriesGroup getAllEntriesGroup() {
AllEntriesGroup group = new AllEntriesGroup(Localization.lang("All entries"));
group.setIconName(ALL_ENTRIES_GROUP_DEFAULT_ICON.name());
group.setIconName(ALL_ENTRIES_GROUP_DEFAULT_ICON);
return group;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public static void doNotUseJGoodies(JavaClasses classes) {
public static void doNotUseGlazedLists(JavaClasses classes) {
noClasses().should().accessClassesThat().resideInAPackage("ca.odell.glazedlists..").check(classes);
}


@ArchTest
public static void doNotUseGlyphsDirectly(JavaClasses classes) {
noClasses().that().resideOutsideOfPackage("org.jabref.gui.icon").should().accessClassesThat().resideInAnyPackage("de.jensd.fx.glyphs", "de.jensd.fx.glyphs.materialdesignicons").check(classes);
}

//"Currently disabled as there is no alternative for the rest of classes who need awt"
@ArchIgnore
@ArchTest
Expand Down

0 comments on commit 89ebaf7

Please sign in to comment.