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 8, 2016
1 parent 00a27ac commit 080517e
Show file tree
Hide file tree
Showing 24 changed files with 115 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Undo/redo are enabled/disabled and show the action in the tool tip
- Added ISBN integrity checker
- Added filter to not show selected integrity checks
- 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 @@ -88,6 +88,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 @@ -99,12 +100,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 @@ -139,6 +142,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 @@ -215,8 +219,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,
model.getSearchState() != MainTableDataModel.DisplayOption.DISABLED ? SearchMatcher.INSTANCE : null)) {
score++;
Expand Down Expand Up @@ -262,11 +264,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 @@ -451,8 +457,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 @@ -609,6 +618,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
47 changes: 30 additions & 17 deletions src/main/java/net/sf/jabref/gui/maintable/MainTableColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryUtil;
import net.sf.jabref.model.entry.FieldName;
import net.sf.jabref.model.entry.FieldProperties;
import net.sf.jabref.model.entry.InternalBibtexFields;
Expand Down Expand Up @@ -107,30 +106,22 @@ 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)) {
content = EntryUtil.capitalizeFirst(entry.getType());
} 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 @@ -141,4 +132,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
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ 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 ("bibtextype".equals(field)) {
if (BibEntry.TYPE_HEADER.equals(field) || "bibtextype".equals(field)) {
return Optional.of(EntryUtil.capitalizeFirst(entry.getType()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class JabRefPreferences {
public static final String BIBLATEX_DEFAULT_MODE = "biblatexMode";
public static final String NAMES_AS_IS = "namesAsIs";
public static final String TABLE_COLOR_CODES_ON = "tableColorCodesOn";
public static final String TABLE_RESOLVED_COLOR_CODES_ON = "tableResolvedColorCodesOn";
public static final String ENTRY_EDITOR_HEIGHT = "entryEditorHeight";
public static final String PREVIEW_PANEL_HEIGHT = "previewPanelHeight";
public static final String AUTO_RESIZE_MODE = "autoResizeMode";
Expand Down Expand Up @@ -237,6 +238,7 @@ public class JabRefPreferences {
public static final String TABLE_TEXT = "tableText";
public static final String TABLE_OPT_FIELD_BACKGROUND = "tableOptFieldBackground";
public static final String TABLE_REQ_FIELD_BACKGROUND = "tableReqFieldBackground";
public static final String TABLE_RESOLVED_FIELD_BACKGROUND = "tableResolvedFieldBackground";
public static final String TABLE_BACKGROUND = "tableBackground";
public static final String TABLE_SHOW_GRID = "tableShowGrid";
public static final String TABLE_ROW_PADDING = "tableRowPadding";
Expand Down Expand Up @@ -535,6 +537,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 @@ -1741,3 +1741,6 @@ Entry_from_%0=Post_fra_%0

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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 @@ -2456,3 +2456,6 @@ Entry_from_%0=Eintrag_basierend_auf_%0

Merge_entry_with_%0_information=Eintrag_mit_%0-Informationen_zusammenführen
Updated_entry_with_info_from_%0=Eintrag_wurde_mit_%0-Information_aktualisiert.

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
2 changes: 2 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2294,3 +2294,5 @@ No_%0_found=No_%0_found
Entry_from_%0=Entry_from_%0
Merge_entry_with_%0_information=Merge_entry_with_%0_information
Updated_entry_with_info_from_%0=Updated_entry_with_info_from_%0
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 @@ -1643,3 +1643,6 @@ Entry_from_%0=Entrada_desde_%0

Merge_entry_with_%0_information=Fusionar_entrada_con_informaciçon_%0
Updated_entry_with_info_from_%0=Entrada_actualizada_con_información_del_%0

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 @@ -2423,3 +2423,6 @@ Updated_entry_with_info_from_%0=

Get_BibTeX_data_from_%0=
No_%0_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 @@ -1684,3 +1684,6 @@ Entry_from_%0=Entrée_à_partir_du_%0

Merge_entry_with_%0_information=Fusionner_l'entrée_sur_la_base_des_informations_du_%0
Updated_entry_with_info_from_%0=Entrée_mise_à_jour_à_partir_des_informations_du_%0

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 @@ -1660,3 +1660,6 @@ Entry_from_%0=Entri_dari_%0

Merge_entry_with_%0_information=Gabung_entri_dengan_informasi_%0
Updated_entry_with_info_from_%0=Entri_diperbarui_dengan_informasi_dari_%0

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 @@ -1760,3 +1760,6 @@ Entry_from_%0=

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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 @@ -2401,3 +2401,6 @@ Entry_from_%0=%0からの項目

Merge_entry_with_%0_information=項目を%0情報とマージ
Updated_entry_with_info_from_%0=%0からの情報で項目を更新しました

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 @@ -2435,3 +2435,6 @@ Entry_from_%0=

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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 @@ -2826,3 +2826,6 @@ Entry_from_%0=

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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 @@ -1656,3 +1656,6 @@ Entry_from_%0=

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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 @@ -2402,3 +2402,6 @@ Entry_from_%0=

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1601,3 +1601,6 @@ Entry_from_%0=Post_från_%0

Merge_entry_with_%0_information=Kombinera_post_med_information_från_%0
Updated_entry_with_info_from_%0=Uppdaterade_post_med_information_från_%0

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=
3 changes: 3 additions & 0 deletions src/main/resources/l10n/JabRef_tr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1674,3 +1674,6 @@ Entry_from_%0=%0'den_girdi

Merge_entry_with_%0_information=%0_bilgisiyle_girdiyi_birleştir
Updated_entry_with_info_from_%0=%0'den_edinilen_bilgiyle_girdi_güncellendi

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

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=

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

Merge_entry_with_%0_information=
Updated_entry_with_info_from_%0=已根据_%0_更新记录

Background_color_for_resolved_fields=
Color_codes_for_resolved_fields=

0 comments on commit 080517e

Please sign in to comment.