Skip to content

Commit

Permalink
capsulated all usages of MaterialDesignIcon in gui/icons and removed …
Browse files Browse the repository at this point in the history
…IconFactory again
  • Loading branch information
r0light committed Aug 29, 2019
1 parent 8aaa3c9 commit 2b760cd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 94 deletions.
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.JabRefMaterialDesignIconFactory;
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;

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 = JabRefMaterialDesignIconFactory.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,7 +30,7 @@
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.autocompleter.AutoCompleteSuggestionProvider;
import org.jabref.gui.copyfiles.CopySingleFileAction;
import org.jabref.gui.icon.JabRefMaterialDesignIconFactory;
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 @@ -43,7 +43,6 @@
import org.jabref.preferences.JabRefPreferences;

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

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 = JabRefMaterialDesignIconFactory.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 = JabRefMaterialDesignIconFactory.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
6 changes: 2 additions & 4 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 @@ -265,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 Expand Up @@ -294,8 +293,7 @@ public enum JabRefIcons implements JabRefIcon {
LATEX_FILE(MaterialDesignIcon.FILE_OUTLINE),
LATEX_COMMENT(MaterialDesignIcon.COMMENT_TEXT_OUTLINE),
LATEX_LINE(MaterialDesignIcon.FORMAT_LINE_SPACING),
PASSWORD_REVEALED(MaterialDesignIcon.EYE),
ALL_ENTRIES_GROUP_DEFAULT_ICON(MaterialDesignIcon.DATABASE);
PASSWORD_REVEALED(MaterialDesignIcon.EYE);

private final JabRefIcon icon;

Expand Down

This file was deleted.

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.JabRefMaterialDesignIconFactory;
import org.jabref.gui.icon.JabRefIcon;
import org.jabref.model.strings.StringUtil;

import de.jensd.fx.glyphs.GlyphIcons;

/**
* 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 JabRefMaterialDesignIconFactory.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 = JabRefMaterialDesignIconFactory.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
@@ -1,20 +1,17 @@
package org.jabref.logic.groups;

import org.jabref.gui.icon.IconTheme;
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 DefaultGroupsFactory() {
}

public static AllEntriesGroup getAllEntriesGroup() {
AllEntriesGroup group = new AllEntriesGroup(Localization.lang("All entries"));
group.setIconName(ALL_ENTRIES_GROUP_DEFAULT_ICON.name());
group.setIconName(IconTheme.JabRefIcons.ALL_ENTRIES_GROUP_ICON.name());
return group;
}
}

0 comments on commit 2b760cd

Please sign in to comment.