Skip to content

Commit

Permalink
Added special background color for resolved fields
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Aug 15, 2016
1 parent f0b9c25 commit afc8d8f
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Added filter to not show selected integrity checks
- The contents of `crossref` and `related` will be automatically updated if a linked entry changes key
- The information shown in the main table now resolves crossrefs and strings
- The information shown in the main table now resolves crossrefs and strings and can be shown which fields are resolved in this way (Preferences -> Appearance -> Color codes for resolved fields)
- Enhance the entry customization dialog to give better visual feedback
- It is now possible to generate a new BIB database from the citations in an OpenOffice/LibreOffice document
- The arXiv fetcher now also supports free-text search queries
Expand Down
24 changes: 18 additions & 6 deletions src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class MainTable extends JTable {
private final BasePanel panel;

private final boolean tableColorCodes;
private final boolean tableResolvedColorCodes;
private final DefaultEventSelectionModel<BibEntry> localSelectionModel;
private final TableComparatorChooser<BibEntry> comparatorChooser;
private final JScrollPane pane;
Expand All @@ -103,12 +104,14 @@ public class MainTable extends JTable {
// Enum used to define how a cell should be rendered.
private enum CellRendererMode {
REQUIRED,
RESOLVED,
OPTIONAL,
OTHER
}
private static GeneralRenderer defRenderer;
private static GeneralRenderer reqRenderer;
private static GeneralRenderer optRenderer;
private static GeneralRenderer resolvedRenderer;
private static GeneralRenderer grayedOutRenderer;
private static GeneralRenderer veryGrayedOutRenderer;

Expand Down Expand Up @@ -143,6 +146,7 @@ public MainTable(MainTableFormat tableFormat, MainTableDataModel model, JabRefFr
.eventTableModelWithThreadProxyList(model.getTableRows(), tableFormat));

tableColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON);
tableResolvedColorCodes = Globals.prefs.getBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON);
localSelectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing
.eventSelectionModelWithThreadProxyList(model.getTableRows());
setSelectionModel(localSelectionModel);
Expand Down Expand Up @@ -221,8 +225,6 @@ public TableCellRenderer getCellRenderer(int row, int column) {
int score = -3;
DefaultTableCellRenderer renderer = MainTable.defRenderer;

CellRendererMode status = getCellStatus(row, column);

if ((model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT)
|| matches(row, SearchMatcher.INSTANCE)) {
score++;
Expand Down Expand Up @@ -268,11 +270,15 @@ else if (column == 0) {
renderer = MainTable.incRenderer;
}
renderer.setHorizontalAlignment(JLabel.CENTER);
} else if (tableColorCodes) {
if (status == CellRendererMode.REQUIRED) {
} else if (tableColorCodes || tableResolvedColorCodes) {
CellRendererMode status = getCellStatus(row, column);

if (tableColorCodes && (status == CellRendererMode.REQUIRED)) {
renderer = MainTable.reqRenderer;
} else if (status == CellRendererMode.OPTIONAL) {
} else if (tableColorCodes && (status == CellRendererMode.OPTIONAL)) {
renderer = MainTable.optRenderer;
} else if (tableResolvedColorCodes && (status == CellRendererMode.RESOLVED)) {
renderer = MainTable.resolvedRenderer;
}
}

Expand Down Expand Up @@ -457,8 +463,11 @@ private void setupComparatorChooser() {
private CellRendererMode getCellStatus(int row, int col) {
try {
BibEntry be = getEntryAt(row);
if (tableFormat.getTableColumn(col).isResolved(be)) {
return CellRendererMode.RESOLVED;
}
Optional<EntryType> type = EntryTypes.getType(be.getType(), panel.getBibDatabaseContext().getMode());
if(type.isPresent()) {
if (type.isPresent()) {
String columnName = getColumnName(col).toLowerCase();
if (columnName.equals(BibEntry.KEY_FIELD) || type.get().getRequiredFieldsFlat().contains(columnName)) {
return CellRendererMode.REQUIRED;
Expand Down Expand Up @@ -615,6 +624,9 @@ public static void updateRenderers() {
(new JTable(), "", true, false, 0, 0).getBackground();
MainTable.reqRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_REQ_FIELD_BACKGROUND), Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT));
MainTable.optRenderer = new GeneralRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_OPT_FIELD_BACKGROUND), Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT));
MainTable.resolvedRenderer = new GeneralRenderer(
Globals.prefs.getColor(JabRefPreferences.TABLE_RESOLVED_FIELD_BACKGROUND),
Globals.prefs.getColor(JabRefPreferences.TABLE_TEXT));
MainTable.incRenderer = new IncompleteRenderer();
MainTable.compRenderer = new CompleteRenderer(Globals.prefs.getColor(JabRefPreferences.TABLE_BACKGROUND));
MainTable.grayedOutNumberRenderer = new CompleteRenderer(Globals.prefs.getColor(JabRefPreferences.GRAYED_OUT_BACKGROUND));
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

import javax.swing.JLabel;

import net.sf.jabref.logic.TypedBibEntry;
import net.sf.jabref.logic.layout.LayoutFormatter;
import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.FieldProperties;
Expand Down Expand Up @@ -108,32 +106,21 @@ public Object getColumnValue(BibEntry entry) {
return null;
}

String content = null;
Optional<String> content = Optional.empty();
for (String field : bibtexFields) {
if (field.equals(BibEntry.TYPE_HEADER)) {
// Fancy typesetting
TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBLATEX);
content = typedEntry.getTypeForDisplay();
} else {
if (database.isPresent()) {
content = BibDatabase.getResolvedField(field, entry, database.get()).orElse(null);
} else {
content = entry.getFieldOrAlias(field).orElse(null);
}
}
if (content != null) {
content = BibDatabase.getResolvedField(field, entry, database.orElse(null));
if (content.isPresent()) {
break;
}
}

if (content != null) {
content = toUnicode.format(content);
}
String result = content.map(toUnicode::format).orElse(null);

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

return result;

}

Expand All @@ -144,4 +131,26 @@ public JLabel getHeaderLabel() {
return new JLabel(getDisplayName());
}
}

public boolean isResolved(BibEntry entry) {
if (bibtexFields.isEmpty()) {
return false;
}

Optional<String> content = Optional.empty();
Optional<String> entryContent = Optional.empty();
for (String field : bibtexFields) {
if (BibEntry.TYPE_HEADER.equals(field) || "bibtextype".equals(field)) {
return false;
} else {
entryContent = entry.getFieldOptional(field);
content = BibDatabase.getResolvedField(field, entry, database.orElse(null));
}

if (content.isPresent()) {
break;
}
}
return (!content.equals(entryContent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AppearancePrefsTab extends JPanel implements PrefsTab {
private final JabRefPreferences prefs;

private final JCheckBox colorCodes;
private final JCheckBox resolvedColorCodes;
private final JCheckBox overrideFonts;
private final JCheckBox showGrid;
private final ColorSetupPanel colorPanel = new ColorSetupPanel();
Expand Down Expand Up @@ -103,6 +104,8 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
colorCodes = new JCheckBox(
Localization.lang("Color codes for required and optional fields"));

resolvedColorCodes = new JCheckBox(Localization.lang("Color codes for resolved fields"));

overrideFonts = new JCheckBox(Localization.lang("Override default font settings"));

showGrid = new JCheckBox(Localization.lang("Show gridlines"));
Expand Down Expand Up @@ -169,6 +172,8 @@ public AppearancePrefsTab(JabRefPreferences prefs) {
builder.nextLine();
builder.append(colorCodes);
builder.nextLine();
builder.append(resolvedColorCodes);
builder.nextLine();
builder.append(showGrid);
builder.nextLine();
JButton fontButton = new JButton(Localization.lang("Set table font"));
Expand Down Expand Up @@ -207,6 +212,7 @@ public void setValues() {
classNamesLAF.setEnabled(!useDefaultLAF);

colorCodes.setSelected(prefs.getBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON));
resolvedColorCodes.setSelected(prefs.getBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON));
fontSize.setText(String.valueOf(prefs.getInt(JabRefPreferences.MENU_FONT_SIZE)));
rowPadding.setText(String.valueOf(prefs.getInt(JabRefPreferences.TABLE_ROW_PADDING)));
oldMenuFontSize = prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
Expand All @@ -222,14 +228,15 @@ public void storeSettings() {
// L&F
prefs.putBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL, !customLAF.isSelected());
prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, classNamesLAF.getSelectedItem().toString());
if (customLAF.isSelected() == useDefaultLAF || !currentLAF.equals(classNamesLAF.getSelectedItem().toString())) {
if ((customLAF.isSelected() == useDefaultLAF) || !currentLAF.equals(classNamesLAF.getSelectedItem().toString())) {
JOptionPane.showMessageDialog(null,
Localization.lang("You have changed the look and feel setting.").concat(" ")
.concat(Localization.lang("You must restart JabRef for this to come into effect.")),
Localization.lang("Changed look and feel settings"), JOptionPane.WARNING_MESSAGE);
}

prefs.putBoolean(JabRefPreferences.TABLE_COLOR_CODES_ON, colorCodes.isSelected());
prefs.putBoolean(JabRefPreferences.TABLE_RESOLVED_COLOR_CODES_ON, resolvedColorCodes.isSelected());
prefs.put(JabRefPreferences.FONT_FAMILY, usedFont.getFamily());
prefs.putInt(JabRefPreferences.FONT_STYLE, usedFont.getStyle());
prefs.putInt(JabRefPreferences.FONT_SIZE, usedFont.getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ColorSetupPanel() {

FormLayout layout = new FormLayout
("30dlu, 4dlu, fill:pref, 4dlu, fill:pref, 8dlu, 30dlu, 4dlu, fill:pref, 4dlu, fill:pref",
"pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");
"pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");
FormBuilder builder = FormBuilder.create().layout(layout);

buttons.add(new ColorButton(JabRefPreferences.TABLE_TEXT, Localization.lang("Table text color")));
Expand All @@ -75,6 +75,8 @@ public ColorSetupPanel() {
buttons.add(new ColorButton(JabRefPreferences.VALID_FIELD_BACKGROUND_COLOR, Localization.lang("Entry editor background color")));
buttons.add(new ColorButton(JabRefPreferences.ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR, Localization.lang("Entry editor active background color")));
buttons.add(new ColorButton(JabRefPreferences.INVALID_FIELD_BACKGROUND_COLOR, Localization.lang("Entry editor invalid field color")));
buttons.add(new ColorButton(JabRefPreferences.TABLE_RESOLVED_FIELD_BACKGROUND,
Localization.lang("Background color for resolved fields")));

int rowcnt = 0;
int col = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/sf/jabref/model/database/BibDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import java.util.regex.Pattern;

import net.sf.jabref.event.source.EntryEventSource;
import net.sf.jabref.logic.TypedBibEntry;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.BibtexString;
import net.sf.jabref.model.entry.EntryUtil;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.InternalBibtexFields;
import net.sf.jabref.model.entry.MonthUtil;
Expand Down Expand Up @@ -523,8 +523,10 @@ private String resolveContent(String result, Set<String> usedIds) {
*/
public static Optional<String> getResolvedField(String field, BibEntry entry, BibDatabase database) {
Objects.requireNonNull(entry, "entry cannot be null");

if (BibEntry.TYPE_HEADER.equals(field) || BibEntry.OBSOLETE_TYPE_HEADER.equals(field)) {
return Optional.of(EntryUtil.capitalizeFirst(entry.getType()));
TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBLATEX);
return Optional.of(typedEntry.getTypeForDisplay());
}

// TODO: Changed this to also consider alias fields, which is the expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ public class JabRefPreferences {

// Colors
public static final String TABLE_COLOR_CODES_ON = "tableColorCodesOn";
public static final String TABLE_RESOLVED_COLOR_CODES_ON = "tableResolvedColorCodesOn";
public static final String INCOMPLETE_ENTRY_BACKGROUND = "incompleteEntryBackground";
public static final String FIELD_EDITOR_TEXT_COLOR = "fieldEditorTextColor";
public static final String ACTIVE_FIELD_EDITOR_BACKGROUND_COLOR = "activeFieldEditorBackgroundColor";
Expand All @@ -242,6 +243,7 @@ public class JabRefPreferences {
public static final String TABLE_OPT_FIELD_BACKGROUND = "tableOptFieldBackground";
public static final String TABLE_REQ_FIELD_BACKGROUND = "tableReqFieldBackground";
public static final String MARKED_ENTRY_BACKGROUND = "markedEntryBackground";
public static final String TABLE_RESOLVED_FIELD_BACKGROUND = "tableResolvedFieldBackground";
public static final String TABLE_BACKGROUND = "tableBackground";

public static final String TABLE_SHOW_GRID = "tableShowGrid";
Expand Down Expand Up @@ -543,6 +545,7 @@ private JabRefPreferences() {
defaults.put(PREVIEW_PANEL_HEIGHT, 200);
defaults.put(ENTRY_EDITOR_HEIGHT, 400);
defaults.put(TABLE_COLOR_CODES_ON, Boolean.FALSE);
defaults.put(TABLE_RESOLVED_COLOR_CODES_ON, Boolean.FALSE);
defaults.put(NAMES_AS_IS, Boolean.FALSE); // "Show names unchanged"
defaults.put(NAMES_FIRST_LAST, Boolean.FALSE); // "Show 'Firstname Lastname'"
defaults.put(NAMES_NATBIB, Boolean.TRUE); // "Natbib style"
Expand Down Expand Up @@ -655,6 +658,7 @@ private JabRefPreferences() {
defaults.put(TABLE_BACKGROUND, "255:255:255");
defaults.put(TABLE_REQ_FIELD_BACKGROUND, "230:235:255");
defaults.put(TABLE_OPT_FIELD_BACKGROUND, "230:255:230");
defaults.put(TABLE_RESOLVED_FIELD_BACKGROUND, "240:240:240");
defaults.put(TABLE_TEXT, "0:0:0");
defaults.put(GRID_COLOR, "210:210:210");
defaults.put(GRAYED_OUT_BACKGROUND, "210:210:210");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_da.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1752,3 +1752,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2462,3 +2462,6 @@ You_must_enter_at_least_one_field_name=Sie_müssen_mindestens_einen_Feldnamen_an


Non-ASCII_encoded_character_found=Nicht_ASCII-kodiertes_Zeichen_gefunden
Non-ASCII_encoded_character_found=
Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
4 changes: 3 additions & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2288,4 +2288,6 @@ Style_file=Style_file

Open_OpenOffice/LibreOffice_connection=Open_OpenOffice/LibreOffice_connection
You_must_enter_at_least_one_field_name=You_must_enter_at_least_one_field_name
Non-ASCII_encoded_character_found=Non-ASCII_encoded_character_found
Non-ASCII_encoded_character_found=Non-ASCII_encoded_character_found
Background_color_for_resolved_fields=Background_color_for_resolved_fields
Color_codes_for_resolved_fields=Color_codes_for_resolved_fields
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1653,3 +1653,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_fa.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2434,3 +2434,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1694,3 +1694,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_in.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1669,3 +1669,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_it.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1770,3 +1770,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2411,3 +2411,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2443,3 +2443,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_no.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2835,3 +2835,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_pt_BR.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1666,3 +1666,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2412,3 +2412,6 @@ You_must_enter_at_least_one_field_name=


Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1611,3 +1611,7 @@ You_must_enter_at_least_one_field_name=Du_måste_ange_minst_ett_fältnamn


Non-ASCII_encoded_character_found=Bokstäver_som_inte_är_ASCII-kodade_hittades
Non-ASCII_encoded_character_found=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
Loading

0 comments on commit afc8d8f

Please sign in to comment.