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

Revise maintable #452

Merged
merged 27 commits into from
Dec 15, 2015
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
592fbb0
Allow dragging of special fields
matthiasgeiger Dec 2, 2015
84389b3
move maintable related classes to new package
matthiasgeiger Dec 3, 2015
cba3e64
add class for tableColumns in MainTable
matthiasgeiger Dec 3, 2015
45ca5d3
first running version with MainTableColumn without any contents
matthiasgeiger Dec 3, 2015
02c5336
MainTable is showing right contents again
matthiasgeiger Dec 3, 2015
3bfeece
Add flag to identify iconColumns
matthiasgeiger Dec 3, 2015
6f2d871
reenable setting of width
matthiasgeiger Dec 3, 2015
8809b4e
remove unused method
matthiasgeiger Dec 3, 2015
63e67cc
reenable comparators in maintable
matthiasgeiger Dec 3, 2015
6f83c0f
improve formatting
matthiasgeiger Dec 3, 2015
daf80eb
reenable right-click menus
matthiasgeiger Dec 3, 2015
5993ca2
finalize fields
matthiasgeiger Dec 3, 2015
6d91ad4
use list instead of array for MainTableColumn and IconComparator
matthiasgeiger Dec 4, 2015
01a14e0
left-click menus are working again - exception file type filtering co…
matthiasgeiger Dec 4, 2015
ca8972b
file filter columns are working again
matthiasgeiger Dec 4, 2015
e2a195d
remove PDF/PS column and its configuration from maintable
matthiasgeiger Dec 4, 2015
29df5a6
showing tooltip for main table header fields
matthiasgeiger Dec 4, 2015
18ac857
show icons in header for iconColumns
matthiasgeiger Dec 5, 2015
a3631a9
Remove obsolete option "Show one letter heading for special columns"
matthiasgeiger Dec 5, 2015
e98a231
Show tooltip for columns which are not fully displayed
matthiasgeiger Dec 5, 2015
5642c3d
removing some unused methods
matthiasgeiger Dec 11, 2015
e4ff917
cleanup
matthiasgeiger Dec 11, 2015
7c28c19
improvements based on review comments
matthiasgeiger Dec 14, 2015
e262daa
fix missing header for numberCol
matthiasgeiger Dec 14, 2015
bc55dcf
change default order for maintable
matthiasgeiger Dec 14, 2015
9f5e3fb
add CHANGELOG information
matthiasgeiger Dec 14, 2015
2f9e9f8
minor changes
matthiasgeiger Dec 14, 2015
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -21,6 +21,9 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Move Bibtex and Biblatex mode switcher to File menu
- Display active edit mode (BibTeX or Biblatex) at window title
- Implements #444: The search is cleared by either clicking the clear-button or by pressing ESC with having focus in the search field.
- Icons are shown as Header for icon columns in the entry table (#315)
- Tooltips are shown for header columns and contents which are too wide to be displayed in the entry table (#384)
- Default order in entry table: # | all file based icons (file, URL/DOI, ...) | all bibtex field based icons (bibtexkey, entrytype, author, title, ...) | all activated special field icons (ranking, quality, ...)

### Fixed
- Fixed #434: Revert to old 'JabRef' installation folder name instead of 'jabref'
@@ -32,11 +35,14 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Fixes #412: Biblatex preserves capital letters, checking whether letters may be converted to lowercase within the Integrity Check action is obsolete.
- Fixed #437: The toolbar after the search field is now correctly wrapped when using a small window size for JabRef
- Fixed #438: Cut, Copy and Paste are now translated correctly in the menu
- Fixed #443/#445: Fixed sorting and moving special field columns
- Fixed #498: non-working legacy PDF/PS column removed

### Removed
- Removed file history size preference (never available from the UI)
- Removed jstorImporter because it's hardly ever used, even Jstor.org doesn't support/export said format anymore

- Removed option "Show one letter heading for icon columns" which is obsolete with the fix of #315/384
- Removed table column "PDF/PS" which refers to legacy fields "ps" resp. "pdf" which are no longer supported (see also fix #498)



6 changes: 1 addition & 5 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import net.sf.jabref.gui.actions.CleanUpAction;
import net.sf.jabref.gui.entryeditor.EntryEditorTabList;
import net.sf.jabref.gui.keyboard.KeyBinds;
import net.sf.jabref.gui.maintable.PersistenceTableColumnListener;
import net.sf.jabref.gui.preftabs.ImportSettingsTab;
import net.sf.jabref.importer.fileformat.ImportFormat;
import net.sf.jabref.logic.autocompleter.AutoCompletePreferences;
@@ -192,7 +193,6 @@ public class JabRefPreferences {
public static final String FILE_COLUMN = "fileColumn";
public static final String PREFER_URL_DOI = "preferUrlDoi";
public static final String URL_COLUMN = "urlColumn";
public static final String PDF_COLUMN = "pdfColumn";
public static final String DISABLE_ON_MULTIPLE_SELECTION = "disableOnMultipleSelection";
public static final String CTRL_CLICK = "ctrlClick";
public static final String INCOMPLETE_ENTRY_BACKGROUND = "incompleteEntryBackground";
@@ -231,7 +231,6 @@ public class JabRefPreferences {
public static final String TOOLBAR_VISIBLE = "toolbarVisible";
public static final String HIGHLIGHT_GROUPS_MATCHING_ALL = "highlightGroupsMatchingAll";
public static final String HIGHLIGHT_GROUPS_MATCHING_ANY = "highlightGroupsMatchingAny";
public static final String SHOW_ONE_LETTER_HEADING_FOR_ICON_COLUMNS = "showOneLetterHeadingForIconColumns";
public static final String UPDATE_TIMESTAMP = "updateTimestamp";
public static final String TIME_STAMP_FIELD = "timeStampField";
public static final String TIME_STAMP_FORMAT = "timeStampFormat";
@@ -617,7 +616,6 @@ private JabRefPreferences() {

defaults.put(CTRL_CLICK, Boolean.FALSE);
defaults.put(DISABLE_ON_MULTIPLE_SELECTION, Boolean.FALSE);
defaults.put(PDF_COLUMN, Boolean.FALSE);
defaults.put(URL_COLUMN, Boolean.TRUE);
defaults.put(PREFER_URL_DOI, Boolean.FALSE);
defaults.put(FILE_COLUMN, Boolean.TRUE);
@@ -636,8 +634,6 @@ private JabRefPreferences() {
defaults.put(SpecialFieldsUtils.PREF_AUTOSYNCSPECIALFIELDSTOKEYWORDS, SpecialFieldsUtils.PREF_AUTOSYNCSPECIALFIELDSTOKEYWORDS_DEFAULT);
defaults.put(SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS, SpecialFieldsUtils.PREF_SERIALIZESPECIALFIELDS_DEFAULT);

defaults.put(SHOW_ONE_LETTER_HEADING_FOR_ICON_COLUMNS, Boolean.FALSE);

defaults.put(USE_OWNER, Boolean.FALSE);
defaults.put(OVERWRITE_OWNER, Boolean.FALSE);
defaults.put(ALLOW_TABLE_EDITING, Boolean.FALSE);
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
package net.sf.jabref.bibtex.comparator;

import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.gui.MainTableFormat;
import net.sf.jabref.gui.maintable.MainTableFormat;
import net.sf.jabref.model.entry.AuthorList;
import net.sf.jabref.model.entry.MonthUtil;
import net.sf.jabref.model.entry.YearUtil;
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

import net.sf.jabref.*;
import net.sf.jabref.gui.*;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.gui.undo.UndoableInsertEntry;
17 changes: 5 additions & 12 deletions src/main/java/net/sf/jabref/groups/EntryTableTransferHandler.java
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@
import net.sf.jabref.external.DroppedFileHandler;
import net.sf.jabref.external.ExternalFileType;
import net.sf.jabref.external.TransferableFileLinkSelection;
import net.sf.jabref.gui.MainTable;
import net.sf.jabref.gui.MainTableFormat;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.maintable.MainTableFormat;
import net.sf.jabref.importer.ImportMenuItem;
import net.sf.jabref.importer.OpenDatabaseAction;
import net.sf.jabref.pdfimport.PdfImporter;
@@ -187,17 +187,10 @@ public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {

@Override
public void exportAsDrag(JComponent comp, InputEvent e, int action) {
/* TODO: add support for dragging file link from table icon into other apps */
if (e instanceof MouseEvent) {
MouseEvent me = (MouseEvent) e;
int col = entryTable.columnAtPoint(me.getPoint());
String[] res = entryTable.getIconTypeForColumn(col);
if (res == null) {
super.exportAsDrag(comp, e, DnDConstants.ACTION_LINK);
return;
}
// We have an icon column:
if (res == MainTableFormat.FILE) {
int columnIndex = entryTable.columnAtPoint(((MouseEvent) e).getPoint());
int modelIndex = entryTable.getColumnModel().getColumn(columnIndex).getModelIndex();
if(entryTable.isFileColumn(modelIndex)) {
LOGGER.info("Dragging file");
draggingFile = true;
}
5 changes: 4 additions & 1 deletion src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
@@ -45,6 +45,9 @@
import net.sf.jabref.gui.journals.AbbreviateAction;
import net.sf.jabref.gui.journals.UnabbreviateAction;
import net.sf.jabref.gui.labelPattern.SearchFixDuplicateLabels;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.maintable.MainTableFormat;
import net.sf.jabref.gui.maintable.MainTableSelectionListener;
import net.sf.jabref.gui.mergeentries.MergeEntriesDialog;
import net.sf.jabref.gui.mergeentries.MergeEntryDOIDialog;
import net.sf.jabref.gui.search.SearchBar;
@@ -1505,7 +1508,7 @@ private void createMainTable() {
if (filterSearchToggle != null) {
filterSearchToggle.updateFilterList(searchFilterList);
}
tableFormat = new MainTableFormat(this);
tableFormat = new MainTableFormat(database);
tableFormat.updateTableFormat();
mainTable = new MainTable(tableFormat, searchFilterList, frame, this);

2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/gui/GUIGlobals.java
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ public class GUIGlobals {

public static final int WIDTH_ICON_COL_RANKING = 80; // Width of Ranking Icon Column

public static final int WIDTH_ICON_COL = 19;
public static final int WIDTH_ICON_COL = 26;

// Column widths for export customization dialog table:
public static final int EXPORT_DIALOG_COL_0_WIDTH = 50;
15 changes: 4 additions & 11 deletions src/main/java/net/sf/jabref/gui/ImportInspectionDialog.java
Original file line number Diff line number Diff line change
@@ -26,14 +26,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
@@ -417,7 +410,7 @@ public void addEntries(Collection<BibtexEntry> entriesToAdd) {
* Checks if there are duplicates to the given entry in the Collection. Does
* not report the entry as duplicate of itself if it is in the Collection.
*
* @param entries A Collection of BibtexEntry instances.
* @param entriesDupe A Collection of BibtexEntry instances.
* @param entry The entry to search for duplicates of.
* @return A possible duplicate, if any, or null if none were found.
*/
@@ -1391,9 +1384,9 @@ private void setupComparatorChooser() {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
if (i == FILE_COL) {
comparators.add(new IconComparator(new String[]{Globals.FILE_FIELD}));
comparators.add(new IconComparator(Collections.singletonList(Globals.FILE_FIELD)));
} else if (i == URL_COL) {
comparators.add(new IconComparator(new String[]{"url"}));
comparators.add(new IconComparator(Collections.singletonList("url")));
}

}
450 changes: 0 additions & 450 deletions src/main/java/net/sf/jabref/gui/MainTableFormat.java

This file was deleted.

179 changes: 0 additions & 179 deletions src/main/java/net/sf/jabref/gui/PreventDraggingJTableHeader.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -13,13 +13,12 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui;
package net.sf.jabref.gui.maintable;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.Comparator;
import java.util.List;
import java.util.ArrayList;
@@ -37,6 +36,10 @@
import javax.swing.table.TableColumnModel;

import net.sf.jabref.groups.GroupMatcher;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.EntryMarker;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.renderer.CompleteRenderer;
import net.sf.jabref.gui.renderer.GeneralRenderer;
import net.sf.jabref.gui.renderer.IncompleteRenderer;
@@ -104,7 +107,6 @@ public class MainTable extends JTable {
public static final int OPT_STRING = 3;
private static final int OTHER = 3;
private static final int BOOLEAN = 4;
public static final int ICON_COL = 8; // Constant to indicate that an icon cell renderer should be used.

static {
MainTable.updateRenderers();
@@ -149,13 +151,12 @@ public MainTable(MainTableFormat tableFormat, EventList<BibtexEntry> list, JabRe
setGridColor(Globals.prefs.getColor(JabRefPreferences.GRID_COLOR));
if (Globals.prefs.getBoolean(JabRefPreferences.TABLE_SHOW_GRID)) {
setShowGrid(true);
} else
{
} else {
setShowGrid(false);
setIntercellSpacing(new Dimension(0, 0));
}

this.setTableHeader(new PreventDraggingJTableHeader(this.getColumnModel()));
this.setTableHeader(new PreventDraggingJTableHeader(this, tableFormat));

comparatorChooser = this.createTableComparatorChooser(this, sortedForTable,
TableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
@@ -206,7 +207,6 @@ public void refreshSorting() {

/**
* Adds a sorting rule that floats hits to the top, and causes non-hits to be grayed out:
* @param m The Matcher that determines if an entry is a hit or not.
*/
public void showFloatSearch() {
if(!isFloatSearchActive) {
@@ -239,7 +239,6 @@ public boolean isFloatSearchActive() {

/**
* Adds a sorting rule that floats group hits to the top, and causes non-hits to be grayed out:
* @param m The Matcher that determines if an entry is a in the current group selection or not.
*/
public void showFloatGrouping() {
if(!isFloatGroupingActive) {
@@ -281,6 +280,25 @@ public JScrollPane getPane() {
return pane;
}

@Override
public String getToolTipText(MouseEvent e) {

// Set tooltip text for all columns which are not fully displayed

String toolTipText = null;
Point p = e.getPoint();
int col = columnAtPoint(p);
int row = rowAtPoint(p);
Component comp = prepareRenderer(getCellRenderer(row, col), row, col);

Rectangle bounds = getCellRect(row, col, false);

if (comp.getPreferredSize().width > bounds.width && getValueAt(row, col) != null) {
toolTipText = getValueAt(row, col).toString();
}
return toolTipText;
}

@Override
public TableCellRenderer getCellRenderer(int row, int column) {

@@ -357,35 +375,35 @@ else if (tableColorCodes) {
private void setWidths() {
// Setting column widths:
int ncWidth = Globals.prefs.getInt(JabRefPreferences.NUMBER_COL_WIDTH);
String[] widths = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_WIDTHS);
String[] widthsFromPreferences = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_WIDTHS);
TableColumnModel cm = getColumnModel();
cm.getColumn(0).setPreferredWidth(ncWidth);
for (int i = 1; i < tableFormat.padleft; i++) {

// Check if the Column is an extended RankingColumn (and not a compact-ranking column)
// If this is the case, set a certain Column-width,
// because the RankingIconColumn needs some more width
if (tableFormat.isRankingColumn(i)) {
// Lock the width of ranking icon column.
for(int i=1; i<cm.getColumnCount(); i++) {
MainTableColumn mainTableColumn = tableFormat.getTableColumn(cm.getColumn(i).getModelIndex());
if(SpecialFieldsUtils.FIELDNAME_RANKING.equals(mainTableColumn.getColumnName())) {
cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL_RANKING);
cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING);
cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING);
} else {
// Lock the width of icon columns.
} else if(mainTableColumn.isIconColumn()) {
cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL);
cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL);
cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL);
} else {
String[] allColumns = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_NAMES);
// find index of current mainTableColumn in allColumns
for(int j=0; j<allColumns.length; j++) {
if(allColumns[j].equalsIgnoreCase(mainTableColumn.getDisplayName())) {
try {
// set preferred width by using found index j in the width array
cm.getColumn(i).setPreferredWidth(Integer.parseInt(widthsFromPreferences[j]));
} catch (NumberFormatException e) {
LOGGER.info("Exception while setting column widths. Choosing default.", e);
cm.getColumn(i).setPreferredWidth(GUIGlobals.DEFAULT_FIELD_LENGTH);
}
break;
}
}
}

}
for (int i = tableFormat.padleft; i < getModel().getColumnCount(); i++) {
try {
cm.getColumn(i).setPreferredWidth(Integer.parseInt(widths[i - tableFormat.padleft]));
} catch (Throwable ex) {
LOGGER.info("Exception while setting column widths. Choosing default.", ex);
cm.getColumn(i).setPreferredWidth(GUIGlobals.DEFAULT_FIELD_LENGTH);
}

}
}

@@ -414,7 +432,10 @@ private List<String> getCurrentSortFields() {
List<Integer> sortCols = comparatorChooser.getSortingColumns();
List<String> fields = new ArrayList<>();
for (Integer i : sortCols) {
String name = tableFormat.getColumnType(i);
// TODO check whether this really works
String name = tableFormat.getColumnName(i);
//TODO OLD
// String name = tableFormat.getColumnType(i);
if (name != null) {
fields.add(name.toLowerCase());
}
@@ -434,24 +455,22 @@ private void setupComparatorChooser() {
comparators.clear();
comparators.add(new FirstColumnComparator(panel.database()));

// Icon columns:
for (int i = 1; i < tableFormat.padleft; i++) {
for (int i = 1; i < tableFormat.getColumnCount(); i++) {
MainTableColumn tableColumn = tableFormat.getTableColumn(i);

comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
String[] iconField = tableFormat.getIconTypeForColumn(i);

if (iconField[0].equals(SpecialFieldsUtils.FIELDNAME_RANKING)) {
if (SpecialFieldsUtils.FIELDNAME_RANKING.equals(tableColumn.getColumnName())) {
comparators.add(new RankingFieldComparator());
} else if (tableColumn.isIconColumn()) {
comparators.add(new IconComparator(tableColumn.getBibtexFields()));
} else {
comparators.add(new IconComparator(iconField));
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
comparators.add(new FieldComparator(tableFormat.getColumnName(i).toLowerCase()));
}
}
// Remaining columns:
for (int i = tableFormat.padleft; i < tableFormat.getColumnCount(); i++) {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
comparators.add(new FieldComparator(tableFormat.getColumnName(i).toLowerCase()));
}

// Set initial sort columns:

@@ -471,11 +490,14 @@ private void setupComparatorChooser() {
try {
for (int i = 0; i < sortFields.length; i++) {
int index = -1;
if (!sortFields[i].startsWith(MainTableFormat.ICON_COLUMN_PREFIX)) {

// TODO where is this prefix set?
// if (!sortFields[i].startsWith(MainTableFormat.ICON_COLUMN_PREFIX))
if (!sortFields[i].startsWith("iconcol:")) {
index = tableFormat.getColumnIndex(sortFields[i]);
} else {
for (int j = 0; j < tableFormat.getColumnCount(); j++) {
if (sortFields[i].equals(tableFormat.getColumnType(j))) {
if (sortFields[i].equals(tableFormat.getColumnName(j))) {
index = j;
break;
}
@@ -574,8 +596,16 @@ public int findEntry(BibtexEntry entry) {
return sortedForGrouping.indexOf(entry);
}

public String[] getIconTypeForColumn(int column) {
return tableFormat.getIconTypeForColumn(column);
/**
* 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
* @return true if the column shows the "file" field; false otherwise
*/
public boolean isFileColumn(int modelIndex) {
return tableFormat.getTableColumn(modelIndex) != null && tableFormat.getTableColumn(modelIndex)
.getBibtexFields().contains(Globals.FILE_FIELD);
}

private boolean matches(int row, Matcher<BibtexEntry> m) {
@@ -718,14 +748,10 @@ private static Color mixColors(Color one, Color two) {
private TableComparatorChooser<BibtexEntry> createTableComparatorChooser(JTable table, SortedList<BibtexEntry> list,
Object sortingStrategy) {
final TableComparatorChooser<BibtexEntry> result = TableComparatorChooser.install(table, list, sortingStrategy);
result.addSortActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// We need to reset the stack of sorted list each time sorting order
// changes, or the sorting breaks down:
refreshSorting();
}
result.addSortActionListener(e -> {
// We need to reset the stack of sorted list each time sorting order
// changes, or the sorting breaks down:
refreshSorting();
});
return result;
}
@@ -783,4 +809,8 @@ public PersistenceTableColumnListener getTableColumnListener() {
public SortedList<BibtexEntry> getSortedForTable() {
return sortedForTable;
}

public MainTableColumn getMainTableColumn(int modelIndex) {
return tableFormat.getTableColumn(modelIndex);
}
}
129 changes: 129 additions & 0 deletions src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package net.sf.jabref.gui.maintable;

import net.sf.jabref.gui.BibtexFields;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.model.entry.EntryUtil;

import javax.swing.*;
import java.util.*;

public class MainTableColumn {

private final String columnName;

private final List<String> bibtexFields;

private final boolean isIconColumn;

private final Optional<JLabel> iconLabel;

private final Optional<BibtexDatabase> database;

public MainTableColumn(String columnName) {
this.columnName = columnName;
this.bibtexFields = Collections.emptyList();
this.isIconColumn = false;
this.iconLabel = Optional.empty();
this.database = Optional.empty();
}

public MainTableColumn(String columnName, String[] bibtexFields, BibtexDatabase database) {
this.columnName = columnName;
this.bibtexFields = Collections.unmodifiableList(Arrays.asList(bibtexFields));
this.isIconColumn = false;
this.iconLabel = Optional.empty();
this.database = Optional.of(database);
}

public MainTableColumn(String columnName, String[] bibtexFields, JLabel iconLabel) {
this.columnName = columnName;
this.bibtexFields = Collections.unmodifiableList(Arrays.asList(bibtexFields));
this.isIconColumn = true;
this.iconLabel = Optional.of(iconLabel);
this.database = Optional.empty();
}

/**
* Get the table column name to be displayed in the UI
*
* @return name to be displayed
*/
public String getDisplayName() {
if (bibtexFields.isEmpty()) {
return null;
}

StringJoiner joiner = new StringJoiner(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR);
for(String field : bibtexFields) {
String fieldDisplayName = BibtexFields.getFieldDisplayName(field);
if (fieldDisplayName != null) {
joiner.add(fieldDisplayName);
} else {
joiner.add(EntryUtil.capitalizeFirst(field));
}
}
return joiner.toString();
}

/**
* Checks whether the column should display names
* Relevant as name value format can be formatted.
*
* @return true if the bibtex fields contains author or editor
*/
public boolean isNameColumn() {
return bibtexFields.contains("author") || bibtexFields.contains("editor");
}

public String getColumnName() {
return columnName;
}

public List<String> getBibtexFields() {
return bibtexFields;
}

public boolean isIconColumn() {
return isIconColumn;
}

public boolean isFileFilter() {
return false; // Overridden in SpecialMainTableColumns for file filter columns
}

public Object getColumnValue(BibtexEntry entry) {
if(bibtexFields.isEmpty()) {
return null;
}

String content = null;
for (String field : bibtexFields) {
if (field.equals(BibtexEntry.TYPE_HEADER)) {
content = entry.getType().getName();
} else {
content = entry.getFieldOrAlias(field);
if (database.isPresent() && "Author".equalsIgnoreCase(columnName) && (content != null)) {
content = database.get().resolveForStrings(content);
}
}
if (content != null) {
break;
}
}

if (isNameColumn()) {
return MainTableNameFormatter.formatName(content);
}
return content;

}

public JLabel getHeaderLabel() {
if(isIconColumn) {
return iconLabel.get();
} else {
return new JLabel(getDisplayName());
}
}
}
174 changes: 174 additions & 0 deletions src/main/java/net/sf/jabref/gui/maintable/MainTableFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/* Copyright (C) 2003-2012 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui.maintable;

import java.util.ArrayList;
import java.util.List;

import net.sf.jabref.gui.*;
import net.sf.jabref.model.database.BibtexDatabase;
import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.specialfields.SpecialFieldsUtils;
import ca.odell.glazedlists.gui.TableFormat;

import javax.swing.JLabel;

/**
* Class defining the contents and column headers of the main table.
*/
public class MainTableFormat implements TableFormat<BibtexEntry> {
// Character separating field names that are to be used in sequence as
// fallbacks for a single column (e.g. "author/editor" to use editor where
// author is not set):
public static final String COL_DEFINITION_FIELD_SEPARATOR = "/";

// Values to gather iconImages for those columns
// These values are also used to put a heading into the table; see getColumnName(int)
private static final String[] URL_FIRST = {"url", "doi"};
private static final String[] DOI_FIRST = {"doi", "url"};
private static final String[] ARXIV = {"eprint"};
public static final String[] FILE = {Globals.FILE_FIELD};

private final BibtexDatabase database;

private final List<MainTableColumn> tableColumns = new ArrayList<>();

public MainTableFormat(BibtexDatabase database) {
this.database = database;
}

@Override
public int getColumnCount() {
return tableColumns.size();
}

/**
* @return the string that should be put in the column header
*/
@Override
public String getColumnName(int col) {

return tableColumns.get(col).getDisplayName();

}

public MainTableColumn getTableColumn(int index) {
return tableColumns.get(index);
}

/**
* Finds the column index for the given column name.
*
* @param colName The column name
* @return The column index if any, or -1 if no column has that name.
*/
public int getColumnIndex(String colName) {

for (MainTableColumn tableColumn : tableColumns) {
if (tableColumn.getColumnName().equalsIgnoreCase(colName)) {
return tableColumns.lastIndexOf(tableColumn);
}
}

return -1;
}

@Override
public Object getColumnValue(BibtexEntry be, int col) {

return tableColumns.get(col).getColumnValue(be);

}

public void updateTableFormat() {
// clear existing column configuration
tableColumns.clear();

// Add numbering column to tableColumns
tableColumns.add(SpecialMainTableColumns.NUMBER_COL);

// Add all file based columns
if (Globals.prefs.getBoolean(JabRefPreferences.FILE_COLUMN)) {
tableColumns.add(SpecialMainTableColumns.FILE_COLUMN);
}

if (Globals.prefs.getBoolean(JabRefPreferences.URL_COLUMN)) {
if (Globals.prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI)) {
tableColumns.add(SpecialMainTableColumns
.createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.DOI_FIRST,
new JLabel(IconTheme.JabRefIcon.DOI.getSmallIcon())));
} else {
tableColumns.add(SpecialMainTableColumns
.createIconColumn(JabRefPreferences.URL_COLUMN, MainTableFormat.URL_FIRST,
new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon())));
}

}

if (Globals.prefs.getBoolean(JabRefPreferences.ARXIV_COLUMN)) {
tableColumns.add(SpecialMainTableColumns
.createIconColumn(JabRefPreferences.ARXIV_COLUMN, MainTableFormat.ARXIV,
new JLabel(IconTheme.JabRefIcon.WWW.getSmallIcon())));
}

if (Globals.prefs.getBoolean(JabRefPreferences.EXTRA_FILE_COLUMNS)) {
String[] desiredColumns = Globals.prefs.getStringArray(JabRefPreferences.LIST_OF_FILE_COLUMNS);
for (String desiredColumn : desiredColumns) {
tableColumns.add(SpecialMainTableColumns.createFileIconColumn(desiredColumn));
}
}

// Add 'normal' bibtex fields as configured in the preferences
// Read table columns from prefs:
String[] colSettings = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_NAMES);

for (String columnName : colSettings) {
// stored column name will be used as columnName
// There might be more than one field to display, e.g., "author/editor" or "date/year" - so split
// at MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR
String[] fields = columnName.split(MainTableFormat.COL_DEFINITION_FIELD_SEPARATOR);
tableColumns.add(new MainTableColumn(columnName, fields, database));
}


// Add the "special" icon columns (e.g., ranking, file, ...) that are enabled in preferences.
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SPECIALFIELDSENABLED)) {
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RANKING)) {
tableColumns.add(SpecialMainTableColumns.RANKING_COLUMN);
}
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_RELEVANCE)) {
tableColumns.add(SpecialMainTableColumns.RELEVANCE_COLUMN);
}
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_QUALITY)) {
tableColumns.add(SpecialMainTableColumns.QUALITY_COLUMN);
}
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRIORITY)) {
tableColumns.add(SpecialMainTableColumns.PRIORITY_COLUMN);
}
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_PRINTED)) {
tableColumns.add(SpecialMainTableColumns.PRINTED_COLUMN);
}
if (Globals.prefs.getBoolean(SpecialFieldsUtils.PREF_SHOWCOLUMN_READ)) {
tableColumns.add(SpecialMainTableColumns.READ_STATUS_COLUMN);
}
}


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.sf.jabref.gui.maintable;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.model.entry.AuthorList;

public class MainTableNameFormatter {

/**
* Format a name field for the table, according to user preferences.
*
* @param nameToFormat The contents of the name field.
* @return The formatted name field.
*/
public static String formatName(String nameToFormat) {
if (nameToFormat == null) {
return null;
}

// Read name format options:
boolean namesNatbib = Globals.prefs.getBoolean(JabRefPreferences.NAMES_NATBIB); //MK:
boolean namesLastOnly = Globals.prefs.getBoolean(JabRefPreferences.NAMES_LAST_ONLY);
boolean namesAsIs = Globals.prefs.getBoolean(JabRefPreferences.NAMES_AS_IS);
boolean abbr_names = Globals.prefs.getBoolean(JabRefPreferences.ABBR_AUTHOR_NAMES); //MK:
boolean namesFf = Globals.prefs.getBoolean(JabRefPreferences.NAMES_FIRST_LAST);
boolean namesLf = !(namesAsIs || namesFf || namesNatbib || namesLastOnly); // None of the above.

if (namesAsIs) {
return nameToFormat;
} else if (namesNatbib) {
nameToFormat = AuthorList.fixAuthor_Natbib(nameToFormat);
} else if (namesLastOnly) {
nameToFormat = AuthorList.fixAuthor_lastNameOnlyCommas(nameToFormat, false);
} else if (namesFf) {
nameToFormat = AuthorList.fixAuthor_firstNameFirstCommas(nameToFormat, abbr_names, false);
} else if (namesLf) {
nameToFormat = AuthorList.fixAuthor_lastNameFirstCommas(nameToFormat, abbr_names, false);
}
return nameToFormat;
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui;
package net.sf.jabref.gui.maintable;

import java.util.Vector;

@@ -24,6 +24,7 @@

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.gui.GUIGlobals;

/**
* Listens for TableColumnModelEvents to keep track of changes made to the
@@ -39,13 +40,11 @@
*/
public class PersistenceTableColumnListener implements TableColumnModelListener {

public static final String ACTIVATE_PREF_KEY =
"ActivatePersistenceTableColumnListener";
public static final String ACTIVATE_PREF_KEY = "ActivatePersistenceTableColumnListener";

public static final boolean DEFAULT_ENABLED = true;

private static final String simpleClassName =
PersistenceTableColumnListener.class.getSimpleName();
private static final String simpleClassName = PersistenceTableColumnListener.class.getSimpleName();

// needed to get column names / indices mapped from view to model
// and to access the table model
@@ -71,13 +70,11 @@ private void updateColumnPrefs() {
for (int i = 0; i < columnCount; i++) {
final String name = mainTable.getColumnName(i);
if ((name != null) && !name.isEmpty()) {
if ("#".equals(name)) { // TODO: get "#" from prefs?
if (GUIGlobals.NUMBER_COL.equals(name)) {
ncWidth = mainTable.getColumnModel().getColumn(i).getWidth();
} else {
storedColumns.add(name.toLowerCase());
columnsWidths.add(String.valueOf(mainTable.getColumnModel().getColumn(
i).getWidth()));

columnsWidths.add(String.valueOf(mainTable.getColumnModel().getColumn(i).getWidth()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/* Copyright (C) 2003-2015 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui.maintable;

import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Enumeration;

/**
* Related to <code>MainTable</code> class. <br/>
* Prevents dragging of the first header column ("#") and shows icons in the table header if an icon has to be set.
*
* This might not be the best way to solve this problem. Overriding
* <code>getDraggedColumn</code> produces some ugly gui dragging artifacts if a
* user attempts to drag something before the first columns.
*
* @author Daniel Waeber
* @author Fabian Bieker
* @since 12/2008
*/
class PreventDraggingJTableHeader extends JTableHeader implements TableCellRenderer {

private final MainTableFormat tableFormat;

private final TableCellRenderer delegate;

public PreventDraggingJTableHeader(JTable table, MainTableFormat tableFormat) {
super(table.getColumnModel());
this.setTable(table);
this.tableFormat = tableFormat;
this.delegate = table.getTableHeader().getDefaultRenderer();
setupTableHeaderIcons();
}

private void setupTableHeaderIcons() {

Enumeration<TableColumn> columns = columnModel.getColumns();
while(columns.hasMoreElements()) {
TableColumn column = columns.nextElement();
column.setHeaderRenderer(this);
MainTableColumn mainTableColumn = tableFormat.getTableColumn(column.getModelIndex());
column.setHeaderValue(mainTableColumn.getHeaderLabel());
}

}

@Override
public String getToolTipText(MouseEvent event) {
int index = columnModel.getColumnIndexAtX(event.getX());
int realIndex = columnModel.getColumn(index).getModelIndex();
MainTableColumn column = tableFormat.getTableColumn(realIndex);
return column.getDisplayName();
}

/**
* Overridden to prevent dragging of first column ("#")
*/
@Override
public void setDraggedColumn(TableColumn column) {

if (column != null) {
// prevent dragging of "#"
if (column.getModelIndex() == 0) {
return;
}
}
super.setDraggedColumn(column);
}

/**
* Overridden to prevent dragging of an other column before the first column ("#").
*/
@Override
public TableColumn getDraggedColumn() {
TableColumn column = super.getDraggedColumn();
if (column != null) {
PreventDraggingJTableHeader.preventDragBeforeNumberColumn(this.getTable(), column.getModelIndex());
}

return column;
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {

// delegate to previously used TableCellRenderer which styles the component
Component resultFromDelegate = delegate.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

// Changing style is only possible if both value and resultFromDelegate are JLabels
if (value instanceof JLabel && resultFromDelegate instanceof JLabel) {
String text = ((JLabel) value).getText();
Icon icon = ((JLabel) value).getIcon();
if (icon != null) {
((JLabel) resultFromDelegate).setIcon(icon);
((JLabel) resultFromDelegate).setText(null);
} else {
((JLabel) resultFromDelegate).setText(text);
}
}

return resultFromDelegate;
}

/**
* Transform model index <code>modelIndex</code> to a view based index and
* prevent dragging before model index <code>toIndex</code> (inclusive).
*/
private static void preventDragBeforeNumberColumn(JTable table, int modelIndex) {

for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {

TableColumn col = table.getColumnModel().getColumn(columnIndex);

// found the element in the view ...
// ... and check if it should not be dragged
if ((col.getModelIndex() == modelIndex) && (columnIndex < 1)) {
// prevent dragging (move it back ...)
table.getColumnModel().moveColumn(columnIndex, 1);
return; // we are done now
}

}
}
}
193 changes: 193 additions & 0 deletions src/main/java/net/sf/jabref/gui/maintable/SpecialMainTableColumns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
package net.sf.jabref.gui.maintable;

import net.sf.jabref.Globals;
import net.sf.jabref.external.ExternalFileType;
import net.sf.jabref.gui.FileListTableModel;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.model.entry.BibtexEntry;
import net.sf.jabref.model.entry.EntryUtil;
import net.sf.jabref.specialfields.*;

import javax.swing.*;

public class SpecialMainTableColumns {

public static final MainTableColumn NUMBER_COL = new MainTableColumn(GUIGlobals.NUMBER_COL) {

@Override
public Object getColumnValue(BibtexEntry entry) {
return "#";
}

@Override
public String getDisplayName() {
return "#";
}
};

public static final MainTableColumn RANKING_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_RANKING,
new String[] {SpecialFieldsUtils.FIELDNAME_RANKING},
new JLabel(EntryUtil.capitalizeFirst(SpecialFieldsUtils.FIELDNAME_RANKING))) {

@Override
public Object getColumnValue(BibtexEntry entry) {
SpecialFieldValue rank = Rank.getInstance().parse(entry.getField(SpecialFieldsUtils.FIELDNAME_RANKING));
if (rank != null) {
return rank.createLabel();
} else {
return null;
}
}
};

public static final MainTableColumn PRIORITY_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_PRIORITY,
new String[] {SpecialFieldsUtils.FIELDNAME_PRIORITY},
new JLabel(Priority.getInstance().getRepresentingIcon())) {

@Override
public Object getColumnValue(BibtexEntry entry) {

SpecialFieldValue prio = Priority.getInstance()
.parse(entry.getField(SpecialFieldsUtils.FIELDNAME_PRIORITY));
if (prio != null) {
return prio.createLabel();
} else {
return null;
}
}
};

public static final MainTableColumn READ_STATUS_COLUMN = new MainTableColumn(SpecialFieldsUtils.FIELDNAME_READ,
new String[] {SpecialFieldsUtils.FIELDNAME_READ},
new JLabel(ReadStatus.getInstance().getRepresentingIcon())) {

@Override
public Object getColumnValue(BibtexEntry entry) {

SpecialFieldValue status = ReadStatus.getInstance()
.parse(entry.getField(SpecialFieldsUtils.FIELDNAME_READ));
if (status != null) {
return status.createLabel();
} else {
return null;
}
}
};

public static final MainTableColumn RELEVANCE_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_RELEVANCE,
new String[] {SpecialFieldsUtils.FIELDNAME_RELEVANCE},
new JLabel(Relevance.getInstance().getRepresentingIcon()));

public static final MainTableColumn PRINTED_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_PRINTED,
new String[] {SpecialFieldsUtils.FIELDNAME_PRINTED},
new JLabel(Printed.getInstance().getRepresentingIcon()));

public static final MainTableColumn QUALITY_COLUMN = createIconColumn(SpecialFieldsUtils.FIELDNAME_QUALITY,
new String[] {SpecialFieldsUtils.FIELDNAME_QUALITY},
new JLabel(Quality.getInstance().getRepresentingIcon()));


public static final MainTableColumn FILE_COLUMN = new MainTableColumn(Globals.FILE_FIELD,
new String[] {Globals.FILE_FIELD}, new JLabel(IconTheme.JabRefIcon.FILE.getSmallIcon())) {

@Override
public Object getColumnValue(BibtexEntry entry) {
// We use a FileListTableModel to parse the field content:
FileListTableModel fileList = new FileListTableModel();
fileList.setContent(entry.getField(Globals.FILE_FIELD));
if (fileList.getRowCount() > 1) {
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
} else if (fileList.getRowCount() == 1) {
ExternalFileType type = fileList.getEntry(0).getType();
if (type != null) {
return type.getIconLabel();
}
}

return null;
}
};

/**
* Creates a MainTableColumn which shows an icon instead textual content
*
* @param columnName the name of the column
* @param fields the entry fields which should be shown
* @return the crated MainTableColumn
*/
public static MainTableColumn createIconColumn(String columnName, String[] fields, JLabel iconLabel) {
return new MainTableColumn(columnName, fields, iconLabel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method every called with more than one field? Could it be simplified to just passing one field? (I don't like arrays :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for "DOI/URL" resp. "URL/DOI".


@Override
public Object getColumnValue(BibtexEntry entry) {
JLabel iconLabel = null;
boolean iconFound = false;

// check for each field whether content is available
for (String field : fields) {
if (entry.getField(field) != null) {
if (iconFound) {
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
} else {
iconLabel = GUIGlobals.getTableIcon(field);
iconFound = true;
}

}
}
return iconLabel;
}
};
}

/**
* create a MainTableColumn for specific file types.
*
* Shows the icon for the given type (or the FILE_MULTIPLE icon)
*
* @param externalFileTypeName the name of the externalFileType
*
* @return the created MainTableColumn
*/
public static MainTableColumn createFileIconColumn(String externalFileTypeName) {



return new MainTableColumn(externalFileTypeName, new String[] {Globals.FILE_FIELD}, new JLabel()) {

@Override
public boolean isFileFilter() {
return true;
}

@Override
public String getDisplayName() {
return externalFileTypeName;
}

@Override
public Object getColumnValue(BibtexEntry entry) {

boolean iconFound = false;
JLabel iconLabel = null;
FileListTableModel fileList = new FileListTableModel();
fileList.setContent(entry.getField(Globals.FILE_FIELD));
for (int i = 0; i < fileList.getRowCount(); i++) {
if (fileList.getEntry(i).getType() != null) {
if (externalFileTypeName.equalsIgnoreCase(fileList.getEntry(i).getType().getName())) {
if (iconFound) {
// already found another file of the desired type - show FILE_MULTIPLE Icon
return new JLabel(IconTheme.JabRefIcon.FILE_MULTIPLE.getSmallIcon());
} else {
iconLabel = fileList.getEntry(i).getType().getIconLabel();
iconFound = true;
}
}
}
}
return iconLabel;
}
};
}
}
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.GUIGlobals;
import net.sf.jabref.gui.MainTable;
import net.sf.jabref.gui.maintable.MainTable;

import com.jgoodies.forms.builder.ButtonBarBuilder;
import net.sf.jabref.logic.CustomEntryTypesManager;
29 changes: 7 additions & 22 deletions src/main/java/net/sf/jabref/gui/preftabs/TableColumnsTab.java
Original file line number Diff line number Diff line change
@@ -55,7 +55,6 @@ class TableColumnsTab extends JPanel implements PrefsTab {
private final Vector<TableRow> tableRows = new Vector<>(10);
private final JabRefFrame frame;

private final JCheckBox pdfColumn;
private final JCheckBox urlColumn;
private final JCheckBox fileColumn;
private final JCheckBox arxivColumn;
@@ -66,8 +65,6 @@ class TableColumnsTab extends JPanel implements PrefsTab {
private final JRadioButton preferUrl;
private final JRadioButton preferDoi;

private final JCheckBox showOneLetterHeadingForIconColumns;

/*** begin: special fields ***/
private final JCheckBox specialFieldsEnabled;
private JCheckBox rankingColumn;
@@ -243,10 +240,7 @@ public void setValueAt(Object value, int row, int col) {
toolBar.add(moveDown);
tabPanel.add(toolBar, BorderLayout.EAST);

showOneLetterHeadingForIconColumns = new JCheckBox(Localization.lang("Show one letter heading for icon columns"));

fileColumn = new JCheckBox(Localization.lang("Show file column"));
pdfColumn = new JCheckBox(Localization.lang("Show PDF/PS column"));
urlColumn = new JCheckBox(Localization.lang("Show URL/DOI column"));
preferUrl = new JRadioButton(Localization.lang("Show URL first"));
preferDoi = new JRadioButton(Localization.lang("Show DOI first"));
@@ -334,18 +328,16 @@ public void stateChanged(ChangeEvent event) {
specialTableColumnsBuilder.add(readStatusColumn, cc.xyw(2, 7, 2));
specialTableColumnsBuilder.add(syncKeywords, cc.xyw(2, 10, 2));
specialTableColumnsBuilder.add(writeSpecialFields, cc.xyw(2, 11, 2));
specialTableColumnsBuilder.add(showOneLetterHeadingForIconColumns, cc.xyw(1, 12, 4));
specialTableColumnsBuilder.add(helpButton, cc.xyw(1, 13, 2));
specialTableColumnsBuilder.add(helpButton, cc.xyw(1, 12, 2));

specialTableColumnsBuilder.add(fileColumn, cc.xyw(5, 1, 2));
specialTableColumnsBuilder.add(pdfColumn, cc.xyw(5, 2, 2));
specialTableColumnsBuilder.add(urlColumn, cc.xyw(5, 3, 2));
specialTableColumnsBuilder.add(preferUrl, cc.xy(6, 4));
specialTableColumnsBuilder.add(preferDoi, cc.xy(6, 5));
specialTableColumnsBuilder.add(arxivColumn, cc.xyw(5, 6, 2));
specialTableColumnsBuilder.add(urlColumn, cc.xyw(5, 2, 2));
specialTableColumnsBuilder.add(preferUrl, cc.xy(6, 3));
specialTableColumnsBuilder.add(preferDoi, cc.xy(6, 4));
specialTableColumnsBuilder.add(arxivColumn, cc.xyw(5, 5, 2));

specialTableColumnsBuilder.add(extraFileColumns, cc.xyw(5, 7, 2));
specialTableColumnsBuilder.add(listOfFileColumnsScrollPane, cc.xywh(5, 8, 2, 5));
specialTableColumnsBuilder.add(extraFileColumns, cc.xyw(5, 6, 2));
specialTableColumnsBuilder.add(listOfFileColumnsScrollPane, cc.xywh(5, 7, 2, 6));

builder.append(specialTableColumnsBuilder.getPanel());
builder.nextLine();
@@ -375,7 +367,6 @@ public void stateChanged(ChangeEvent event) {
@Override
public void setValues() {
fileColumn.setSelected(prefs.getBoolean(JabRefPreferences.FILE_COLUMN));
pdfColumn.setSelected(prefs.getBoolean(JabRefPreferences.PDF_COLUMN));
urlColumn.setSelected(prefs.getBoolean(JabRefPreferences.URL_COLUMN));
preferUrl.setSelected(!prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI));
preferDoi.setSelected(prefs.getBoolean(JabRefPreferences.PREFER_URL_DOI));
@@ -435,9 +426,6 @@ public void setValues() {

/*** end: special fields ***/

boolean oldShowOneLetterHeadingForIconColumns = prefs.getBoolean(JabRefPreferences.SHOW_ONE_LETTER_HEADING_FOR_ICON_COLUMNS);
showOneLetterHeadingForIconColumns.setSelected(oldShowOneLetterHeadingForIconColumns);

tableRows.clear();
String[] names = prefs.getStringArray(JabRefPreferences.COLUMN_NAMES);
String[] lengths = prefs.getStringArray(JabRefPreferences.COLUMN_WIDTHS);
@@ -691,7 +679,6 @@ public void actionPerformed(ActionEvent e) {
@Override
public void storeSettings() {
prefs.putBoolean(JabRefPreferences.FILE_COLUMN, fileColumn.isSelected());
prefs.putBoolean(JabRefPreferences.PDF_COLUMN, pdfColumn.isSelected());
prefs.putBoolean(JabRefPreferences.URL_COLUMN, urlColumn.isSelected());
prefs.putBoolean(JabRefPreferences.PREFER_URL_DOI, preferDoi.isSelected());
prefs.putBoolean(JabRefPreferences.ARXIV_COLUMN, arxivColumn.isSelected());
@@ -709,8 +696,6 @@ public void storeSettings() {
prefs.putStringArray(JabRefPreferences.LIST_OF_FILE_COLUMNS, new String[]{});
}

prefs.putBoolean(JabRefPreferences.SHOW_ONE_LETTER_HEADING_FOR_ICON_COLUMNS, showOneLetterHeadingForIconColumns.isSelected());

/*** begin: special fields ***/

boolean newSpecialFieldsEnabled = specialFieldsEnabled.isSelected();
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Objects;
@@ -52,6 +53,7 @@
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.PreviewPanel;
import net.sf.jabref.gui.TransferableBibtexEntry;
import net.sf.jabref.gui.maintable.MainTableNameFormatter;
import net.sf.jabref.gui.renderer.GeneralRenderer;
import net.sf.jabref.gui.util.IconComparator;
import net.sf.jabref.model.entry.BibtexEntry;
@@ -238,9 +240,9 @@ private void setupComparatorChooser(TableComparatorChooser<BibtexEntry> comparat
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
if (i == FILE_COL) {
comparators.add(new IconComparator(new String[] {Globals.FILE_FIELD}));
comparators.add(new IconComparator(Arrays.asList(Globals.FILE_FIELD)));
} else if (i == URL_COL) {
comparators.add(new IconComparator(new String[] {"url"}));
comparators.add(new IconComparator(Arrays.asList("url")));
}

}
@@ -498,8 +500,7 @@ public Object getColumnValue(BibtexEntry entry, int column) {
// For name fields, tap into a MainTableFormat instance and use
// the same name formatting as is used in the entry table:
if (frame.getCurrentBasePanel() != null) {
return frame.getCurrentBasePanel().tableFormat.formatName
(entry.getField(field));
return MainTableNameFormatter.formatName(entry.getField(field));
}
}
return entry.getField(field);
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/gui/util/IconComparator.java
Original file line number Diff line number Diff line change
@@ -18,16 +18,17 @@
import net.sf.jabref.model.entry.BibtexEntry;

import java.util.Comparator;
import java.util.List;

/**
* Comparator that handles icon columns.
*/
public class IconComparator implements Comparator<BibtexEntry> {

private final String[] fields;
private final List<String> fields;


public IconComparator(String[] fields) {
public IconComparator(List<String> fields) {
this.fields = fields;
}

Original file line number Diff line number Diff line change
@@ -195,14 +195,12 @@ private void makeChanges(BasePanel panel, ParserResult pr, boolean upgradePrefs,

if (upgradePrefs) {
// Exchange table columns:
Globals.prefs.putBoolean(JabRefPreferences.PDF_COLUMN, Boolean.FALSE);
Globals.prefs.putBoolean(JabRefPreferences.FILE_COLUMN, Boolean.TRUE);

// Modify General fields if necessary:
// If we don't find the file field, insert it at the bottom of the first tab:
if (!showsFileInGenFields()) {
String gfs = Globals.prefs.get(JabRefPreferences.CUSTOM_TAB_FIELDS + "0");
//System.out.println(gfs);
StringBuilder sb = new StringBuilder(gfs);
if (!gfs.isEmpty()) {
sb.append(";");
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/pdfimport/PdfImporter.java
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
import net.sf.jabref.gui.FileListEntry;
import net.sf.jabref.gui.FileListTableModel;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.MainTable;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.entryeditor.EntryEditor;
import net.sf.jabref.gui.preftabs.ImportSettingsTab;
import net.sf.jabref.gui.undo.UndoableInsertEntry;
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/specialfields/Priority.java
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public class Priority extends SpecialField {

private static Priority INSTANCE;

private final Icon icon = IconTheme.JabRefIcon.PRIORITY.getIcon();
private final Icon icon = IconTheme.JabRefIcon.PRIORITY.getSmallIcon();


private Priority() {
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/specialfields/ReadStatus.java
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ public class ReadStatus extends SpecialField {

private static ReadStatus INSTANCE;

private final Icon icon = IconTheme.JabRefIcon.READ_STATUS.getIcon();
private final Icon icon = IconTheme.JabRefIcon.READ_STATUS.getSmallIcon();


private ReadStatus() {
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@
import net.sf.jabref.JabRef;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.MainTable;
import net.sf.jabref.gui.maintable.MainTable;
import net.sf.jabref.gui.keyboard.KeyBinds;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.wizard.auximport.AuxSubGenerator;