Skip to content

Commit

Permalink
A single class which handles the preference for highlighting matching…
Browse files Browse the repository at this point in the history
… groups.
  • Loading branch information
simonharrer committed Mar 13, 2016
1 parent ba94661 commit 0f9a9e9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
39 changes: 39 additions & 0 deletions src/main/java/net/sf/jabref/HighlightMatchingGroupPreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.sf.jabref;

public class HighlightMatchingGroupPreferences {

public static final String ALL = "all";
public static final String ANY = "any";
public static final String DISABLED = "";

private final JabRefPreferences preferences;

public HighlightMatchingGroupPreferences(JabRefPreferences preferences) {
this.preferences = preferences;
}

public boolean isAll() {
return ALL.equals(preferences.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING));
}

public boolean isAny() {
return ANY.equals(preferences.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING));
}

public boolean isDisabled() {
return !isAll() && !isAny();
}

public void setToAll() {
preferences.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, ALL);
}

public void setToAny() {
preferences.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, ANY);
}

public void setToDisabled() {
preferences.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, DISABLED);
}

}
12 changes: 6 additions & 6 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1053,19 +1053,19 @@ public void update() {
});

actions.put(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ANY, (BaseAction) () -> {
Globals.prefs.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, "any");
new HighlightMatchingGroupPreferences(Globals.prefs).setToAny();
// ping the listener so it updates:
groupsHighlightListener.listChanged(null);
});

actions.put(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ALL, (BaseAction) () -> {
Globals.prefs.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, "all");
new HighlightMatchingGroupPreferences(Globals.prefs).setToAll();
// ping the listener so it updates:
groupsHighlightListener.listChanged(null);
});

actions.put(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_DISABLE, (BaseAction) () -> {
Globals.prefs.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, "");
new HighlightMatchingGroupPreferences(Globals.prefs).setToDisabled();
// ping the listener so it updates:
groupsHighlightListener.listChanged(null);
});
Expand Down Expand Up @@ -1432,10 +1432,10 @@ private void createMainTable() {

@Override
public void listChanged(ListEvent<BibEntry> listEvent) {
String highlightGroupsMatchingOption = Globals.prefs.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING);
if ("any".equals(highlightGroupsMatchingOption)) {
HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences(Globals.prefs);
if(highlightMatchingGroupPreferences.isAny()) {
getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), false);
} else if ("all".equals(highlightGroupsMatchingOption)) {
} else if (highlightMatchingGroupPreferences.isAll()) {
getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), true);
} else {
// no highlight
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -1274,10 +1274,10 @@ private void fillMenu() {
highlightButtonGroup.add(toggleHighlightAnyItem);
highlightButtonGroup.add(toggleHighlightAllItem);

String toggleHighlightStatus = Globals.prefs.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING);
if("all".equals(toggleHighlightStatus)) {
HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences(Globals.prefs);
if(highlightMatchingGroupPreferences.isAll()) {
toggleHighlightAllItem.setSelected(true);
} else if("any".equals(toggleHighlightStatus)) {
} else if(highlightMatchingGroupPreferences.isAny()) {
toggleHighlightAnyItem.setSelected(true);
} else {
toggleHighlightDisableItem.setSelected(true);
Expand Down

0 comments on commit 0f9a9e9

Please sign in to comment.