From 2813be7085c234957caf57817bedf43da0e36881 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Tue, 7 Mar 2017 23:08:41 +0100 Subject: [PATCH 1/4] Code Formatting --- .../jabref/gui/keyboard/EmacsKeyBindings.java | 208 +++++++----------- .../org/jabref/gui/maintable/MainTable.java | 22 +- 2 files changed, 81 insertions(+), 149 deletions(-) diff --git a/src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java b/src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java index 3c2afe41a75..79928ae6f08 100644 --- a/src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java +++ b/src/main/java/org/jabref/gui/keyboard/EmacsKeyBindings.java @@ -34,8 +34,8 @@ * * The inner class actions can also be used independently. */ -public class EmacsKeyBindings -{ +public class EmacsKeyBindings { + private static final Log LOGGER = LogFactory.getLog(EmacsKeyBindings.class); private static final String KILL_LINE_ACTION = "emacs-kill-line"; @@ -61,40 +61,40 @@ public class EmacsKeyBindings private static final JTextComponent.KeyBinding[] EMACS_KEY_BINDINGS_BASE = { new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_E, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK), DefaultEditorKit.endLineAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_D, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK), DefaultEditorKit.deleteNextCharAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_N, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK), DefaultEditorKit.downAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_P, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK), DefaultEditorKit.upAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_B, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.ALT_MASK), DefaultEditorKit.previousWordAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, InputEvent.ALT_MASK), DefaultEditorKit.beginAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LESS, InputEvent.ALT_MASK + InputEvent.SHIFT_MASK), DefaultEditorKit.endAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_F, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.ALT_MASK), DefaultEditorKit.nextWordAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_B, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK), DefaultEditorKit.backwardAction), // CTRL+V and ALT+V are disabled as CTRL+V is also "paste" @@ -107,53 +107,53 @@ public class EmacsKeyBindings // InputEvent.ALT_MASK), // DefaultEditorKit.pageUpAction), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_D, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.ALT_MASK), EmacsKeyBindings.KILL_WORD_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, InputEvent.ALT_MASK), EmacsKeyBindings.BACKWARD_KILL_WORD_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), EmacsKeyBindings.SET_MARK_COMMAND_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_W, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.ALT_MASK), EmacsKeyBindings.KILL_RING_SAVE_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_W, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK), EmacsKeyBindings.KILL_REGION_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_K, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK), EmacsKeyBindings.KILL_LINE_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_Y, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK), EmacsKeyBindings.YANK_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_Y, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.ALT_MASK), EmacsKeyBindings.YANK_POP_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK), EmacsKeyBindings.CAPITALIZE_WORD_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_L, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.ALT_MASK), EmacsKeyBindings.DOWNCASE_WORD_ACTION), new JTextComponent. - KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_U, + KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.ALT_MASK), EmacsKeyBindings.UPCASE_WORD_ACTION), }; @@ -181,16 +181,13 @@ public class EmacsKeyBindings }; // components to modify - private static final JTextComponent[] JTCS = new JTextComponent[] { + private static final JTextComponent[] JTCS = new JTextComponent[]{ new JTextArea(), new JTextPane(), new JTextField(), new JEditorPane(), }; - private static final Log LOGGER = LogFactory.getLog(EmacsKeyBindings.class); - - /** * Loads the emacs keybindings for all common JTextComponents. * @@ -199,8 +196,7 @@ public class EmacsKeyBindings * * The original keybindings are stored in a backup array. */ - public static void load() - { + public static void load() { EmacsKeyBindings.createBackup(); EmacsKeyBindings.loadEmacsKeyBindings(); } @@ -230,10 +226,8 @@ private static void createBackup() { /** * Restores the original keybindings for the concrete subclasses of * {@link JTextComponent}. - * */ - public static void unload() - { + public static void unload() { for (int i = 0; i < EmacsKeyBindings.JTCS.length; i++) { Keymap backup = JTextComponent.getKeymap (EmacsKeyBindings.JTCS[i].getClass().getName()); @@ -259,8 +253,7 @@ public static void unload() * Activates Emacs keybindings for all text components extending {@link * JTextComponent}. */ - private static void loadEmacsKeyBindings() - { + private static void loadEmacsKeyBindings() { EmacsKeyBindings.LOGGER.debug("Loading emacs keybindings"); for (JTextComponent jtc : EmacsKeyBindings.JTCS) { @@ -314,17 +307,14 @@ private static void loadEmacsKeyBindings() * text component and adds it to the clipboard. */ @SuppressWarnings("serial") - public static class KillWordAction extends TextAction - { + public static class KillWordAction extends TextAction { - public KillWordAction(String nm) - { + public KillWordAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { JTextComponent jtc = getTextComponent(e); if (jtc != null) { try { @@ -351,17 +341,14 @@ public void actionPerformed(ActionEvent e) * active text component and adds it to the clipboard. */ @SuppressWarnings("serial") - public static class BackwardKillWordAction extends TextAction - { + public static class BackwardKillWordAction extends TextAction { - public BackwardKillWordAction(String nm) - { + public BackwardKillWordAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { JTextComponent jtc = getTextComponent(e); if (jtc != null) { try { @@ -385,17 +372,14 @@ public void actionPerformed(ActionEvent e) * This action copies the marked region and stores it in the killring. */ @SuppressWarnings("serial") - public static class KillRingSaveAction extends TextAction - { + public static class KillRingSaveAction extends TextAction { - public KillRingSaveAction(String nm) - { + public KillRingSaveAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { JTextComponent jtc = getTextComponent(e); EmacsKeyBindings.doCopyOrCut(jtc, true); } @@ -405,17 +389,14 @@ public void actionPerformed(ActionEvent e) * This action Kills the marked region and stores it in the killring. */ @SuppressWarnings("serial") - public static class KillRegionAction extends TextAction - { + public static class KillRegionAction extends TextAction { - public KillRegionAction(String nm) - { + public KillRegionAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { JTextComponent jtc = getTextComponent(e); EmacsKeyBindings.doCopyOrCut(jtc, false); } @@ -465,17 +446,14 @@ private static void doCopyOrCut(JTextComponent jtc, boolean copy) { * the killring. */ @SuppressWarnings("serial") - public static class KillLineAction extends TextAction - { + public static class KillLineAction extends TextAction { - public KillLineAction(String nm) - { + public KillLineAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { JTextComponent jtc = getTextComponent(e); if (jtc != null) { try { @@ -484,8 +462,7 @@ public void actionPerformed(ActionEvent e) if ((start == end) && jtc.isEditable()) { Document doc = jtc.getDocument(); doc.remove(end, 1); - } - else { + } else { jtc.setSelectionStart(start); jtc.setSelectionEnd(end); String selectedText = jtc.getSelectedText(); @@ -507,40 +484,34 @@ public void actionPerformed(ActionEvent e) * This action matchers a beginning mark for a selection. */ @SuppressWarnings("serial") - public static class SetMarkCommandAction extends TextAction - { + public static class SetMarkCommandAction extends TextAction { private static int position = -1; private static JTextComponent jtc; - public SetMarkCommandAction(String nm) - { + public SetMarkCommandAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent e) - { + public void actionPerformed(ActionEvent e) { SetMarkCommandAction.jtc = getTextComponent(e); if (SetMarkCommandAction.jtc != null) { SetMarkCommandAction.position = SetMarkCommandAction.jtc.getCaretPosition(); } } - public static boolean isMarked(JTextComponent jt) - { + public static boolean isMarked(JTextComponent jt) { return (SetMarkCommandAction.jtc == jt) && (SetMarkCommandAction.position != -1); } - public static void reset() - { + public static void reset() { SetMarkCommandAction.jtc = null; SetMarkCommandAction.position = -1; } - public static int getCaretPosition() - { + public static int getCaretPosition() { return SetMarkCommandAction.position; } } @@ -549,21 +520,18 @@ public static int getCaretPosition() * This action pastes text from the killring. */ @SuppressWarnings("serial") - public static class YankAction extends TextAction - { + public static class YankAction extends TextAction { public static int start = -1; public static int end = -1; - public YankAction(String nm) - { + public YankAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { JTextComponent jtc = getTextComponent(event); if (jtc != null) { @@ -584,17 +552,14 @@ public void actionPerformed(ActionEvent event) * This action pastes an element from the killring cycling through it. */ @SuppressWarnings("serial") - public static class YankPopAction extends TextAction - { + public static class YankPopAction extends TextAction { - public YankPopAction(String nm) - { + public YankPopAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { JTextComponent jtc = getTextComponent(event); boolean jtcNotNull = jtc != null; boolean jtcIsCurrentTextComponent = KillRing.getInstance().getCurrentTextComponent() == jtc; @@ -620,8 +585,7 @@ public void actionPerformed(ActionEvent event) *

* Also provides an unmodifiable copy of all cut pieces. */ - public static class KillRing - { + public static class KillRing { private JTextComponent jtc; private final LinkedList ring = new LinkedList<>(); @@ -630,18 +594,15 @@ public static class KillRing private static final KillRing INSTANCE = new KillRing(); - public static KillRing getInstance() - { + public static KillRing getInstance() { return KillRing.INSTANCE; } - public void setCurrentTextComponent(JTextComponent jtc) - { + public void setCurrentTextComponent(JTextComponent jtc) { this.jtc = jtc; } - public JTextComponent getCurrentTextComponent() - { + public JTextComponent getCurrentTextComponent() { return jtc; } @@ -651,8 +612,7 @@ public JTextComponent getCurrentTextComponent() * Deviating from the Emacs implementation we make sure the * exact same text is not somewhere else in the ring. */ - public void add(String text) - { + public void add(String text) { if (text.isEmpty()) { return; } @@ -670,31 +630,28 @@ public void add(String text) /** * Returns an unmodifiable version of the ring list which contains * the killed texts. + * * @return the content of the kill ring */ - public List getRing() - { + public List getRing() { return Collections.unmodifiableList(ring); } - public boolean isEmpty() - { + public boolean isEmpty() { return ring.isEmpty(); } /** * Returns the next text element which is to be yank-popped. + * * @return null if the ring is empty */ - public String next() - { + public String next() { if (ring.isEmpty()) { return null; - } - else if (iter.hasNext()) { + } else if (iter.hasNext()) { return iter.next(); - } - else { + } else { iter = ring.iterator(); // guaranteed to not throw an exception, since ring is not empty return iter.next(); @@ -706,11 +663,9 @@ else if (iter.hasNext()) { * This action capitalizes the next word on the right side of the caret. */ @SuppressWarnings("serial") - public static class CapitalizeWordAction extends TextAction - { + public static class CapitalizeWordAction extends TextAction { - public CapitalizeWordAction(String nm) - { + public CapitalizeWordAction(String nm) { super(nm); } @@ -720,8 +675,7 @@ public CapitalizeWordAction(String nm) * word is in lower case, then the first letter is capialized. */ @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { JTextComponent jtc = getTextComponent(event); if (jtc != null) { @@ -763,17 +717,14 @@ public void actionPerformed(ActionEvent event) * This action renders all characters of the next word to lowercase. */ @SuppressWarnings("serial") - public static class DowncaseWordAction extends TextAction - { + public static class DowncaseWordAction extends TextAction { - public DowncaseWordAction(String nm) - { + public DowncaseWordAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { JTextComponent jtc = getTextComponent(event); if (jtc != null) { @@ -796,17 +747,14 @@ public void actionPerformed(ActionEvent event) * This action renders all characters of the next word to upppercase. */ @SuppressWarnings("serial") - public static class UpcaseWordAction extends TextAction - { + public static class UpcaseWordAction extends TextAction { - public UpcaseWordAction(String nm) - { + public UpcaseWordAction(String nm) { super(nm); } @Override - public void actionPerformed(ActionEvent event) - { + public void actionPerformed(ActionEvent event) { JTextComponent jtc = getTextComponent(event); if (jtc != null) { @@ -827,16 +775,14 @@ public void actionPerformed(ActionEvent event) private static int getWordEnd(JTextComponent jtc, int start) - throws BadLocationException - { + throws BadLocationException { try { return Utilities.getNextWord(jtc, start); } catch (BadLocationException ble) { int end = jtc.getText().length(); if (start < end) { return end; - } - else { + } else { throw ble; } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 6dfb83bb691..23f299b9bec 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -63,7 +63,6 @@ import org.apache.commons.logging.LogFactory; public class MainTable extends JTable { - private static final Log LOGGER = LogFactory.getLog(MainTable.class); private final MainTableFormat tableFormat; @@ -102,12 +101,10 @@ private enum CellRendererMode { private static List markedNumberRenderers; - static { MainTable.updateRenderers(); } - public MainTable(MainTableFormat tableFormat, MainTableDataModel model, JabRefFrame frame, BasePanel panel) { super(); @@ -306,7 +303,6 @@ else if (column == 0) { } return renderer; - } private void setWidths() { @@ -530,7 +526,7 @@ public int findEntry(BibEntry entry) { } /** - * method to check whether a MainTableColumn at the modelIndex refers to the file field (either as a specific + * Method to check whether a MainTableColumn at the modelIndex refers to the file field (either as a specific * file extension filter or not) * * @param modelIndex model index of the column to check @@ -589,7 +585,7 @@ public void showFloatSearch() { } /** - * updateFont + * Repaints the table with the most recent font configuration */ public void updateFont() { setFont(GUIGlobals.currentFont); @@ -607,7 +603,6 @@ public void ensureVisible(int row) { && (model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT))) { scrollToCenter(row, 1); } - } public void scrollToCenter(int rowIndex, int vColIndex) { @@ -650,8 +645,6 @@ public void scrollToCenter(int rowIndex, int vColIndex) { repaint(); } - - public static void updateRenderers() { MainTable.defRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND), @@ -686,12 +679,10 @@ public static void updateRenderers() { } private static Color mixColors(Color one, Color two) { - return new Color((one.getRed() + two.getRed()) / 2, (one.getGreen() + two.getGreen()) / 2, - (one.getBlue() + two.getBlue()) / 2); + return new Color((one.getRed() + two.getRed()) / 2, (one.getGreen() + two.getGreen()) / 2, (one.getBlue() + two.getBlue()) / 2); } - private TableComparatorChooser createTableComparatorChooser(JTable table, SortedList list, - Object sortingStrategy) { + private TableComparatorChooser createTableComparatorChooser(JTable table, SortedList list, Object sortingStrategy) { return TableComparatorChooser.install(table, list, sortingStrategy); } @@ -707,7 +698,6 @@ public void setUI(TableUI newUI) { TransferHandler handler = getTransferHandler(); setTransferHandler(null); setTransferHandler(handler); - } /** @@ -724,10 +714,6 @@ public int getSortingColumn(int number) { } } - public PersistenceTableColumnListener getTableColumnListener() { - return tableColumnListener; - } - public MainTableColumn getMainTableColumn(int modelIndex) { return tableFormat.getTableColumn(modelIndex); } From 0587dfa327a8a8d27a20949f41154d1b6c9c3546 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Wed, 8 Mar 2017 13:49:11 +0100 Subject: [PATCH 2/4] Always display error message when file cannot be found --- src/main/java/org/jabref/gui/BasePanel.java | 2 +- .../ExternalFileMenuItem.java | 28 +++++++++++-------- .../maintable/MainTableSelectionListener.java | 5 +--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/BasePanel.java b/src/main/java/org/jabref/gui/BasePanel.java index 545a00a08b5..9b9243d7fac 100644 --- a/src/main/java/org/jabref/gui/BasePanel.java +++ b/src/main/java/org/jabref/gui/BasePanel.java @@ -934,7 +934,7 @@ private void openExternalFile() { FileListEntry flEntry = fileListTableModel.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(frame(), entry, "", flEntry.getLink(), flEntry.getType().get().getIcon(), bibDatabaseContext, flEntry.getType()); - item.openLink(); + item.doClick(); }); } diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index a283e0fe766..b20e07fb6e9 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -26,7 +26,6 @@ * to process the request if the user clicks this menu item. */ public class ExternalFileMenuItem extends JMenuItem implements ActionListener { - private static final Log LOGGER = LogFactory.getLog(ExternalFileMenuItem.class); private final BibEntry entry; @@ -62,19 +61,14 @@ public void actionPerformed(ActionEvent e) { } } - public boolean openLink() { + private boolean openLink() { frame.output(Localization.lang("External viewer called") + "."); try { Optional type = fileType; if (!this.fileType.isPresent()) { if (this.fieldName == null) { // We don't already know the file type, so we try to deduce it from the extension: - File file = new File(link); - // We try to check the extension for the file: - String name = file.getName(); - int pos = name.indexOf('.'); - String extension = (pos >= 0) && (pos < (name.length() - 1)) ? name.substring(pos + 1) - .trim().toLowerCase(Locale.ROOT) : null; + String extension = inferFileTypeFromExtension(link); // Now we know the extension, check if it is one we know about: type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension); fileType = type; @@ -91,13 +85,13 @@ public boolean openLink() { return JabRefDesktop.openExternalFileAnyFormat(databaseContext, link, type); } - } catch (IOException e1) { + } catch (IOException ex) { // See if we should show an error message concerning the application to open the // link with. We check if the file type is set, and if the file type has a non-empty // application link. If that link is referred by the error message, we can assume // that the problem is in the open-with-application setting: if ((fileType.isPresent()) && (!fileType.get().getOpenWithApplication().isEmpty()) - && e1.getMessage().contains(fileType.get().getOpenWithApplication())) { + && ex.getMessage().contains(fileType.get().getOpenWithApplication())) { JOptionPane.showMessageDialog(frame, Localization.lang("Unable to open link. " + "The application '%0' associated with the file type '%1' could not be called.", @@ -106,8 +100,20 @@ public boolean openLink() { return false; } - LOGGER.warn("Unable to open link", e1); + LOGGER.warn("Unable to open link", ex); } return false; } + + private String inferFileTypeFromExtension(String pathname) { + File file = new File(pathname); + String name = file.getName(); + int pos = name.indexOf('.'); + + if ((pos >= 0) && (pos < (name.length() - 1))) { + return name.substring(pos + 1).trim().toLowerCase(Locale.ROOT); + } else { + return null; + } + } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java b/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java index ace8d2fbf41..4ea660c03e3 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java +++ b/src/main/java/org/jabref/gui/maintable/MainTableSelectionListener.java @@ -294,10 +294,7 @@ public void mouseClicked(MouseEvent e) { ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().map(ExternalFileType::getIcon).orElse(null), panel.getBibDatabaseContext(), flEntry.getType()); - boolean success = item.openLink(); - if (!success) { - panel.output(Localization.lang("Unable to open link.")); - } + item.doClick(); } } else { try { From 50e231ac0f3f77bc377f13bc99eb8011ee843188 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Wed, 8 Mar 2017 14:38:54 +0100 Subject: [PATCH 3/4] Reuse extension util method --- .../org/jabref/gui/entryeditor/EntryEditor.java | 1 - .../externalfiletype/ExternalFileMenuItem.java | 17 +++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 65fb10fda4f..ec4b4fb051e 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -126,7 +126,6 @@ * update themselves if the change is made from somewhere else. */ public class EntryEditor extends JPanel implements EntryContainer { - private static final Log LOGGER = LogFactory.getLog(EntryEditor.class); /** diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index b20e07fb6e9..2c95b83eba0 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -14,6 +14,7 @@ import org.jabref.gui.JabRefFrame; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.logic.l10n.Localization; +import org.jabref.logic.util.io.FileUtil; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; @@ -68,9 +69,9 @@ private boolean openLink() { if (!this.fileType.isPresent()) { if (this.fieldName == null) { // We don't already know the file type, so we try to deduce it from the extension: - String extension = inferFileTypeFromExtension(link); + Optional extension = FileUtil.getFileExtension(link); // Now we know the extension, check if it is one we know about: - type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension); + type = ExternalFileTypes.getInstance().getExternalFileTypeByExt(extension.orElse(null)); fileType = type; } else { JabRefDesktop.openExternalViewer(databaseContext, link, fieldName); @@ -104,16 +105,4 @@ private boolean openLink() { } return false; } - - private String inferFileTypeFromExtension(String pathname) { - File file = new File(pathname); - String name = file.getName(); - int pos = name.indexOf('.'); - - if ((pos >= 0) && (pos < (name.length() - 1))) { - return name.substring(pos + 1).trim().toLowerCase(Locale.ROOT); - } else { - return null; - } - } } From 50f7e68897c76e47895d05fb5fcda0cea294e896 Mon Sep 17 00:00:00 2001 From: Stefan Kolb Date: Wed, 8 Mar 2017 14:50:48 +0100 Subject: [PATCH 4/4] Imports --- .../org/jabref/gui/externalfiletype/ExternalFileMenuItem.java | 2 -- src/main/java/org/jabref/gui/fieldeditors/FileListEditor.java | 1 - 2 files changed, 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java index 2c95b83eba0..52d9a796423 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileMenuItem.java @@ -2,9 +2,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.io.File; import java.io.IOException; -import java.util.Locale; import java.util.Optional; import javax.swing.Icon; diff --git a/src/main/java/org/jabref/gui/fieldeditors/FileListEditor.java b/src/main/java/org/jabref/gui/fieldeditors/FileListEditor.java index e3317403d19..2f0297458e1 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FileListEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FileListEditor.java @@ -61,7 +61,6 @@ import org.apache.commons.logging.LogFactory; public class FileListEditor extends JTable implements FieldEditor, DownloadExternalFile.DownloadCallback { - private static final Log LOGGER = LogFactory.getLog(FileListEditor.class); private final FieldNameLabel label;