use of org.jabref.gui.util.comparator.IconComparator in project jabref by JabRef.
the class MainTable method setupComparatorChooser.
/**
* This method sets up what Comparators are used for the various table columns.
* The ComparatorChooser enables and disables such Comparators as the user clicks
* columns, but this is where the Comparators are defined. Also, the ComparatorChooser
* is initialized with the sort order defined in Preferences.
*/
private void setupComparatorChooser() {
// First column:
List<Comparator> comparators = comparatorChooser.getComparatorsForColumn(0);
comparators.clear();
comparators.add(new FirstColumnComparator(panel.getBibDatabaseContext()));
for (int i = 1; i < tableFormat.getColumnCount(); i++) {
MainTableColumn tableColumn = tableFormat.getTableColumn(i);
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
if (SpecialField.RANKING.getFieldName().equals(tableColumn.getColumnName())) {
comparators.add(new RankingFieldComparator());
} else if (tableColumn.isIconColumn()) {
comparators.add(new IconComparator(tableColumn.getBibtexFields()));
} else {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
comparators.add(new FieldComparator(tableFormat.getColumnName(i).toLowerCase(Locale.ROOT)));
}
}
// Set initial sort columns:
// Default sort order:
String[] sortFields = new String[] { Globals.prefs.get(JabRefPreferences.TABLE_PRIMARY_SORT_FIELD), Globals.prefs.get(JabRefPreferences.TABLE_SECONDARY_SORT_FIELD), Globals.prefs.get(JabRefPreferences.TABLE_TERTIARY_SORT_FIELD) };
boolean[] sortDirections = new boolean[] { Globals.prefs.getBoolean(JabRefPreferences.TABLE_PRIMARY_SORT_DESCENDING), Globals.prefs.getBoolean(JabRefPreferences.TABLE_SECONDARY_SORT_DESCENDING), Globals.prefs.getBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING) };
// descending
model.getSortedForUserDefinedTableColumnSorting().getReadWriteLock().writeLock().lock();
try {
for (int i = 0; i < sortFields.length; i++) {
int index = -1;
// if (!sortFields[i].startsWith(MainTableFormat.ICON_COLUMN_PREFIX))
if (sortFields[i].startsWith("iconcol:")) {
for (int j = 0; j < tableFormat.getColumnCount(); j++) {
if (sortFields[i].equals(tableFormat.getColumnName(j))) {
index = j;
break;
}
}
} else {
index = tableFormat.getColumnIndex(sortFields[i]);
}
if (index >= 0) {
comparatorChooser.appendComparator(index, 0, sortDirections[i]);
}
}
} finally {
model.getSortedForUserDefinedTableColumnSorting().getReadWriteLock().writeLock().unlock();
}
// Add action listener so we can remember the sort order:
comparatorChooser.addSortActionListener(e -> {
List<String> fields = getCurrentSortFields();
List<Boolean> order = getCurrentSortOrder();
int count = Math.min(fields.size(), order.size());
if (count >= 1) {
Globals.prefs.put(JabRefPreferences.TABLE_PRIMARY_SORT_FIELD, fields.get(0));
Globals.prefs.putBoolean(JabRefPreferences.TABLE_PRIMARY_SORT_DESCENDING, order.get(0));
}
if (count >= 2) {
Globals.prefs.put(JabRefPreferences.TABLE_SECONDARY_SORT_FIELD, fields.get(1));
Globals.prefs.putBoolean(JabRefPreferences.TABLE_SECONDARY_SORT_DESCENDING, order.get(1));
} else {
Globals.prefs.put(JabRefPreferences.TABLE_SECONDARY_SORT_FIELD, "");
Globals.prefs.putBoolean(JabRefPreferences.TABLE_SECONDARY_SORT_DESCENDING, false);
}
if (count >= 3) {
Globals.prefs.put(JabRefPreferences.TABLE_TERTIARY_SORT_FIELD, fields.get(2));
Globals.prefs.putBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING, order.get(2));
} else {
Globals.prefs.put(JabRefPreferences.TABLE_TERTIARY_SORT_FIELD, "");
Globals.prefs.putBoolean(JabRefPreferences.TABLE_TERTIARY_SORT_DESCENDING, false);
}
});
}
use of org.jabref.gui.util.comparator.IconComparator in project jabref by JabRef.
the class ImportInspectionDialog method setupComparatorChooser.
private void setupComparatorChooser() {
// First column:
List<Comparator> comparators = comparatorChooser.getComparatorsForColumn(0);
comparators.clear();
comparators = comparatorChooser.getComparatorsForColumn(1);
comparators.clear();
// Icon columns:
for (int i = 2; i < PAD; i++) {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
if (i == FILE_COL) {
comparators.add(new IconComparator(Collections.singletonList(FieldName.FILE)));
} else if (i == URL_COL) {
comparators.add(new IconComparator(Collections.singletonList(FieldName.URL)));
}
}
// Remaining columns:
for (int i = PAD; i < (PAD + INSPECTION_FIELDS.size()); i++) {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
comparators.add(new FieldComparator(INSPECTION_FIELDS.get(i - PAD)));
}
sortedList.getReadWriteLock().writeLock().lock();
try {
comparatorChooser.appendComparator(PAD, 0, false);
} finally {
sortedList.getReadWriteLock().writeLock().unlock();
}
}
use of org.jabref.gui.util.comparator.IconComparator in project jabref by JabRef.
the class SearchResultFrame method setupComparatorChooser.
/**
* Set up the comparators for each column, so the user can modify sort order
* by clicking the column labels.
* @param comparatorChooser The comparator chooser controlling the sort order.
*/
private void setupComparatorChooser(TableComparatorChooser<BibEntry> comparatorChooser) {
List<Comparator> comparators;
// Icon columns:
for (int i = 0; i < PAD; i++) {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
if (i == FILE_COL) {
comparators.add(new IconComparator(Collections.singletonList(FieldName.FILE)));
} else if (i == URL_COL) {
comparators.add(new IconComparator(Collections.singletonList(FieldName.URL)));
} else if (i == DATABASE_COL) {
comparators.add((entry1, entry2) -> {
String databaseTitle1 = entryHome.get(entry1).getTabTitle();
String databaseTitle2 = entryHome.get(entry2).getTabTitle();
return databaseTitle1.compareTo(databaseTitle2);
});
}
}
// Remaining columns:
for (int i = PAD; i < (PAD + FIELDS.length); i++) {
comparators = comparatorChooser.getComparatorsForColumn(i);
comparators.clear();
comparators.add(new FieldComparator(FIELDS[i - PAD]));
}
sortedEntries.getReadWriteLock().writeLock().lock();
comparatorChooser.appendComparator(PAD, 0, false);
sortedEntries.getReadWriteLock().writeLock().unlock();
}
Aggregations