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

Reimplement special field and file columns #3647

Merged
merged 5 commits into from
Jan 29, 2018
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
17 changes: 9 additions & 8 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public class BasePanel extends StackPane implements ClipboardOwner {
// The undo manager.
private final UndoAction undoAction = new UndoAction();
private final RedoAction redoAction = new RedoAction();
private final CountingUndoManager undoManager = new CountingUndoManager();
private final CountingUndoManager undoManager;
private final List<BibEntry> previousEntries = new ArrayList<>();
private final List<BibEntry> nextEntries = new ArrayList<>();
// Keeps track of the string dialog if it is open.
Expand Down Expand Up @@ -202,6 +202,7 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
this.frame = Objects.requireNonNull(frame);
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
this.externalFileTypes = Objects.requireNonNull(externalFileTypes);
this.undoManager = frame.getUndoManager();

bibDatabaseContext.getDatabase().registerListener(this);
bibDatabaseContext.getMetaData().registerListener(this);
Expand Down Expand Up @@ -638,26 +639,26 @@ public void update() {

// Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected
actions.put(new SpecialFieldValueViewModel(SpecialField.RELEVANCE.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.RELEVANCE).getSpecialFieldAction(
new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager).getSpecialFieldAction(
SpecialField.RELEVANCE.getValues().get(0), frame));
actions.put(new SpecialFieldValueViewModel(SpecialField.QUALITY.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.QUALITY)
new SpecialFieldViewModel(SpecialField.QUALITY, undoManager)
.getSpecialFieldAction(SpecialField.QUALITY.getValues().get(0), frame));
actions.put(new SpecialFieldValueViewModel(SpecialField.PRINTED.getValues().get(0)).getCommand(),
new SpecialFieldViewModel(SpecialField.PRINTED).getSpecialFieldAction(
new SpecialFieldViewModel(SpecialField.PRINTED, undoManager).getSpecialFieldAction(
SpecialField.PRINTED.getValues().get(0), frame));

for (SpecialFieldValue prio : SpecialField.PRIORITY.getValues()) {
actions.put(new SpecialFieldValueViewModel(prio).getCommand(),
new SpecialFieldViewModel(SpecialField.PRIORITY).getSpecialFieldAction(prio, this.frame));
new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager).getSpecialFieldAction(prio, this.frame));
}
for (SpecialFieldValue rank : SpecialField.RANKING.getValues()) {
actions.put(new SpecialFieldValueViewModel(rank).getCommand(),
new SpecialFieldViewModel(SpecialField.RANKING).getSpecialFieldAction(rank, this.frame));
new SpecialFieldViewModel(SpecialField.RANKING, undoManager).getSpecialFieldAction(rank, this.frame));
}
for (SpecialFieldValue status : SpecialField.READ_STATUS.getValues()) {
actions.put(new SpecialFieldValueViewModel(status).getCommand(),
new SpecialFieldViewModel(SpecialField.READ_STATUS).getSpecialFieldAction(status, this.frame));
new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager).getSpecialFieldAction(status, this.frame));
}

actions.put(Actions.TOGGLE_PREVIEW, (BaseAction) () -> {
Expand Down Expand Up @@ -1211,7 +1212,7 @@ public void updateTableFont() {
private void createMainTable() {
bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.getInstance());

mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext.getDatabase(), preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs());
mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext, preferences.getTablePreferences(), externalFileTypes, Globals.getKeyPrefs());

mainTable.updateFont();

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import org.jabref.gui.util.ColorUtil;
import org.jabref.logic.groups.DefaultGroupsFactory;
import org.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -71,7 +72,7 @@ private static InputStream getMaterialDesignIconsStream() {
}

public static javafx.scene.paint.Color getDefaultColor() {
return javafx.scene.paint.Color.rgb(DEFAULT_COLOR.getRed(), DEFAULT_COLOR.getGreen(), DEFAULT_COLOR.getBlue(), DEFAULT_COLOR.getAlpha() / 255.0);
return ColorUtil.toFX(DEFAULT_COLOR);
}

/**
Expand Down Expand Up @@ -277,7 +278,7 @@ public enum JabRefIcons implements JabRefIcon {
private final JabRefIcon icon;

JabRefIcons(MaterialDesignIcon... icons) {
this(IconTheme.DEFAULT_COLOR, icons);
icon = new InternalMaterialDesignIcon(icons);
}

JabRefIcons(Color color, MaterialDesignIcon... icons) {
Expand Down
40 changes: 19 additions & 21 deletions src/main/java/org/jabref/gui/InternalMaterialDesignIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,69 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.swing.Icon;

import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;

import org.jabref.gui.util.ColorUtil;
import org.jabref.preferences.JabRefPreferences;

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

public class InternalMaterialDesignIcon implements JabRefIcon {
private final List<MaterialDesignIcon> icons;
private final Color color;
private Optional<Color> color;
private final String unicode;

public InternalMaterialDesignIcon(java.awt.Color color, MaterialDesignIcon... icons) {
this(toFX(color), Arrays.asList(icons));
this(ColorUtil.toFX(color), Arrays.asList(icons));
}

public InternalMaterialDesignIcon(Color color, MaterialDesignIcon... icons) {
this(color, Arrays.asList(icons));
}

InternalMaterialDesignIcon(Color color, List<MaterialDesignIcon> icons) {
this.icons = icons;
this.color = color;
this.unicode = icons.stream().map(MaterialDesignIcon::unicode).collect(Collectors.joining());
this(icons);
this.color = Optional.of(color);
}

public static java.awt.Color toAWT(Color color) {
return new java.awt.Color((float) color.getRed(),
(float) color.getGreen(),
(float) color.getBlue(),
(float) color.getOpacity());
public InternalMaterialDesignIcon(MaterialDesignIcon... icons) {
this(Arrays.asList(icons));
}

public static Color toFX(java.awt.Color awtColor) {
int r = awtColor.getRed();
int g = awtColor.getGreen();
int b = awtColor.getBlue();
int a = awtColor.getAlpha();
double opacity = a / 255.0;
return javafx.scene.paint.Color.rgb(r, g, b, opacity);
public InternalMaterialDesignIcon(List<MaterialDesignIcon> icons) {
this.icons = icons;
this.unicode = icons.stream().map(MaterialDesignIcon::unicode).collect(Collectors.joining());
this.color = Optional.empty();
}

@Override
public Icon getIcon() {
return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color));
return new IconTheme.FontBasedIcon(this.unicode, ColorUtil.toAWT(this.color.orElse(IconTheme.getDefaultColor())));
}

@Override
public Icon getSmallIcon() {
return new IconTheme.FontBasedIcon(this.unicode, toAWT(this.color), JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL));
return new IconTheme.FontBasedIcon(this.unicode, ColorUtil.toAWT(this.color.orElse(IconTheme.getDefaultColor())), JabRefPreferences.getInstance().getInt(JabRefPreferences.ICON_SIZE_SMALL));
}

@Override
public Node getGraphicNode() {
return MaterialDesignIconFactory.get().createIcon(this.icons.get(0));
Text icon = MaterialDesignIconFactory.get().createIcon(icons.get(0));
color.ifPresent(color -> icon.setStyle(icon.getStyle() + String.format("-fx-fill: %s;", ColorUtil.toRGBCode(color))));
return icon;
}

@Override
public JabRefIcon disabled() {
return new InternalMaterialDesignIcon(toFX(IconTheme.DEFAULT_DISABLED_COLOR), icons);
return new InternalMaterialDesignIcon(ColorUtil.toFX(IconTheme.DEFAULT_DISABLED_COLOR), icons);
}

public String getCode() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
import org.jabref.gui.search.GlobalSearchBar;
import org.jabref.gui.specialfields.SpecialFieldDropDown;
import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.WindowLocation;
import org.jabref.gui.worker.MarkEntriesAction;
Expand Down Expand Up @@ -467,6 +468,7 @@ public void actionPerformed(ActionEvent e) {
private OpenOfficePanel openOfficePanel;
private GroupSidePane groupSidePane;
private JMenu newSpec;
private final CountingUndoManager undoManager = new CountingUndoManager();

public JabRefFrame() {
init();
Expand Down Expand Up @@ -1972,6 +1974,10 @@ public GlobalSearchBar getGlobalSearchBar() {
return globalSearchBar;
}

public CountingUndoManager getUndoManager() {
return undoManager;
}

private static class MyGlassPane extends JPanel {
public MyGlassPane() {
addKeyListener(new KeyAdapter() {
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/org/jabref/gui/desktop/JabRefDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,16 @@ private static void openDoi(String doi) throws IOException {
*/
public static boolean openExternalFileAnyFormat(final BibDatabaseContext databaseContext, String link,
final Optional<ExternalFileType> type) throws IOException {
boolean httpLink = false;

if (REMOTE_LINK_PATTERN.matcher(link.toLowerCase(Locale.ROOT)).matches()) {
httpLink = true;
}

// For other platforms we'll try to find the file type:
Path file = null;
if (!httpLink) {
Optional<Path> tmp = FileHelper.expandFilename(databaseContext, link,
Globals.prefs.getFileDirectoryPreferences());
if (tmp.isPresent()) {
file = tmp.get();
}
openExternalFilePlatformIndependent(type, link);
return true;
}

// Check if we have arrived at a file type, and either an http link or an existing file:
if (httpLink || ((file != null) && Files.exists(file) && (type.isPresent()))) {
Optional<Path> file = FileHelper.expandFilename(databaseContext, link, Globals.prefs.getFileDirectoryPreferences());
if (file.isPresent() && Files.exists(file.get()) && (type.isPresent())) {
// Open the file:
String filePath = httpLink ? link : file.toString();
String filePath = file.get().toString();
openExternalFilePlatformIndependent(type, filePath);
return true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void bindToEntry(BibEntry entry) {
if (newValue != null) {
String oldValue = entry.getField(fieldName).orElse(null);
entry.setField(fieldName, newValue);
UndoManager undoManager = JabRefGUI.getMainFrame().getCurrentBasePanel().getUndoManager();
UndoManager undoManager = JabRefGUI.getMainFrame().getUndoManager();
undoManager.addEdit(new UndoableFieldChange(entry, fieldName, oldValue, newValue));
}
});
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.DialogService;
import org.jabref.gui.FXDialogService;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefIcon;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand All @@ -38,9 +40,8 @@
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.strings.StringUtil;

import de.jensd.fx.glyphs.GlyphIcons;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down Expand Up @@ -100,6 +101,14 @@ public String getDescription() {
return linkedFile.getDescription();
}

public String getDescriptionAndLink() {
if (StringUtil.isBlank(linkedFile.getDescription())) {
return linkedFile.getLink();
} else {
return linkedFile.getDescription() + " (" + linkedFile.getLink() + ")";
}
}

public Optional<Path> findIn(List<Path> directories) {
return linkedFile.findIn(directories);
}
Expand All @@ -108,8 +117,8 @@ public Optional<Path> findIn(List<Path> directories) {
* TODO: Be a bit smarter and try to infer correct icon, for example using {@link
* org.jabref.gui.externalfiletype.ExternalFileTypes#getExternalFileTypeByName(String)}
*/
public GlyphIcons getTypeIcon() {
return MaterialDesignIcon.FILE_PDF;
public JabRefIcon getTypeIcon() {
return IconTheme.JabRefIcons.PDF_FILE;
}

public void markAsAutomaticallyFound() {
Expand All @@ -131,9 +140,14 @@ public Observable[] getObservables() {
public void open() {
try {
Optional<ExternalFileType> type = ExternalFileTypes.getInstance().fromLinkedFile(linkedFile, true);
JabRefDesktop.openExternalFileAnyFormat(databaseContext, linkedFile.getLink(), type);
boolean successful = JabRefDesktop.openExternalFileAnyFormat(databaseContext, linkedFile.getLink(), type);
if (!successful) {
dialogService.showErrorDialogAndWait(
Localization.lang("File not found"),
Localization.lang("Could not find file '%0'.", linkedFile.getLink()));
}
} catch (IOException e) {
LOGGER.warn("Cannot open selected file.", e);
dialogService.showErrorDialogAndWait(Localization.lang("Error opening file '%0'.", getLink()), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private void handleOnDragDropped(LinkedFileViewModel originalItem, DragEvent eve
}

private static Node createFileDisplay(LinkedFileViewModel linkedFile) {
Text icon = MaterialDesignIconFactory.get().createIcon(linkedFile.getTypeIcon());
Node icon = linkedFile.getTypeIcon().getGraphicNode();
icon.setOnMouseClicked(event -> linkedFile.open());
Text link = new Text(linkedFile.getLink());
Text desc = new Text(linkedFile.getDescription());
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/jabref/gui/maintable/CellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.HashMap;
import java.util.Map;

import javax.swing.undo.UndoManager;

import javafx.scene.Node;

import org.jabref.gui.IconTheme;
Expand All @@ -16,7 +18,7 @@ public class CellFactory {

private final Map<String, Node> TABLE_ICONS = new HashMap<>();

public CellFactory(ExternalFileTypes externalFileTypes) {
public CellFactory(ExternalFileTypes externalFileTypes, UndoManager undoManager) {
Node label;
label = IconTheme.JabRefIcons.PDF_FILE.getGraphicNode();
//label.setToo(Localization.lang("Open") + " PDF");
Expand Down Expand Up @@ -56,36 +58,36 @@ public CellFactory(ExternalFileTypes externalFileTypes) {
TABLE_ICONS.put(fileType.getName(), label);
}

SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE);
SpecialFieldViewModel relevanceViewModel = new SpecialFieldViewModel(SpecialField.RELEVANCE, undoManager);
label = relevanceViewModel.getIcon().getGraphicNode();
//label.setToolTipText(relevanceViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.RELEVANCE.getFieldName(), label);

SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY);
SpecialFieldViewModel qualityViewModel = new SpecialFieldViewModel(SpecialField.QUALITY, undoManager);
label = qualityViewModel.getIcon().getGraphicNode();
//label.setToolTipText(qualityViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.QUALITY.getFieldName(), label);

// Ranking item in the menu uses one star
SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING);
SpecialFieldViewModel rankViewModel = new SpecialFieldViewModel(SpecialField.RANKING, undoManager);
label = rankViewModel.getIcon().getGraphicNode();
//label.setToolTipText(rankViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.RANKING.getFieldName(), label);

// Priority icon used for the menu
SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY);
SpecialFieldViewModel priorityViewModel = new SpecialFieldViewModel(SpecialField.PRIORITY, undoManager);
label = priorityViewModel.getIcon().getGraphicNode();
//label.setToolTipText(priorityViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.PRIORITY.getFieldName(), label);

// Read icon used for menu
SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS);
SpecialFieldViewModel readViewModel = new SpecialFieldViewModel(SpecialField.READ_STATUS, undoManager);
label = readViewModel.getIcon().getGraphicNode();
//label.setToolTipText(readViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.READ_STATUS.getFieldName(), label);

// Print icon used for menu
SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED);
SpecialFieldViewModel printedViewModel = new SpecialFieldViewModel(SpecialField.PRINTED, undoManager);
label = printedViewModel.getIcon().getGraphicNode();
//label.setToolTipText(printedViewModel.getLocalization());
TABLE_ICONS.put(SpecialField.PRINTED.getFieldName(), label);
Expand Down
Loading