Skip to content

Commit

Permalink
Toggle functionaly of highlight matching entries in groups interface …
Browse files Browse the repository at this point in the history
…works with an additional disable radio button in the menu plus using only a single enum (i.e., a string value instead of using two boolean flags with forbidden combinations (true, true))
  • Loading branch information
simonharrer committed Mar 11, 2016
1 parent 4a5f497 commit e876cd3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public class JabRefPreferences {
public static final String GROUPS_VISIBLE_ROWS = "groupsVisibleRows";
public static final String DEFAULT_ENCODING = "defaultEncoding";
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 HIGHLIGHT_GROUPS_MATCHING = "highlightGroupsMatching";
public static final String UPDATE_TIMESTAMP = "updateTimestamp";
public static final String TIME_STAMP_FIELD = "timeStampField";
public static final String TIME_STAMP_FORMAT = "timeStampFormat";
Expand Down Expand Up @@ -590,8 +589,7 @@ private JabRefPreferences() {
defaults.put(AUTO_ASSIGN_GROUP, Boolean.TRUE);
defaults.put(GROUP_KEYWORD_SEPARATOR, ", ");
defaults.put(EDIT_GROUP_MEMBERSHIP_MODE, Boolean.FALSE);
defaults.put(HIGHLIGHT_GROUPS_MATCHING_ANY, Boolean.FALSE);
defaults.put(HIGHLIGHT_GROUPS_MATCHING_ALL, Boolean.FALSE);
defaults.put(HIGHLIGHT_GROUPS_MATCHING, "");
defaults.put(TOOLBAR_VISIBLE, Boolean.TRUE);
defaults.put(DEFAULT_ENCODING, StandardCharsets.UTF_8.name());
defaults.put(GROUPS_VISIBLE_ROWS, 8);
Expand Down
23 changes: 11 additions & 12 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1053,21 +1053,19 @@ public void update() {
});

actions.put(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ANY, (BaseAction) () -> {
boolean enabled = !Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY);
Globals.prefs.putBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY, enabled);
if (enabled) {
Globals.prefs.putBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL, false);
}
Globals.prefs.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, "any");
// ping the listener so it updates:
groupsHighlightListener.listChanged(null);
});

actions.put(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ALL, (BaseAction) () -> {
boolean enabled = !Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL);
Globals.prefs.putBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL, enabled);
if (enabled) {
Globals.prefs.putBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY, false);
}
Globals.prefs.put(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING, "all");
// 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, "");
// ping the listener so it updates:
groupsHighlightListener.listChanged(null);
});
Expand Down Expand Up @@ -1434,9 +1432,10 @@ private void createMainTable() {

@Override
public void listChanged(ListEvent<BibEntry> listEvent) {
if (Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY)) {
String highlightGroupsMatchingOption = Globals.prefs.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING);
if ("any".equals(highlightGroupsMatchingOption)) {
getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), false);
} else if (Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL)) {
} else if ("all".equals(highlightGroupsMatchingOption)) {
getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), true);
} else {
// no highlight
Expand Down
28 changes: 25 additions & 3 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ public void actionPerformed(ActionEvent e) {
private final Action toggleHighlightAll = enableToggle(new GeneralAction(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ALL,
Localization.menuTitle("Highlight groups matching all selected entries"),
Localization.lang("Highlight groups matching all selected entries")));
private final Action toggleHighlightDisable = enableToggle(new GeneralAction(Actions.TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_DISABLE,
Localization.menuTitle("Disable Highlight groups matching entries"),
Localization.lang("Disable Highlight groups matching entries")));


private final AbstractAction switchPreview = new GeneralAction(Actions.SWITCH_PREVIEW,
Localization.menuTitle("Switch preview layout"),
Globals.getKeyPrefs().getKey(KeyBinding.SWITCH_PREVIEW_LAYOUT));
Expand Down Expand Up @@ -1057,13 +1062,17 @@ public void setTabTitle(JComponent comp, String title, String toolTip) {
tabbedPane.setToolTipTextAt(index, toolTip);
}

private static Action enableToggle(Action a) {
private static Action enableToggle(Action a, boolean initialValue) {
// toggle only works correctly when the SELECTED_KEY is set to false or true explicitly upon start
a.putValue(Action.SELECTED_KEY, "false");
a.putValue(Action.SELECTED_KEY, String.valueOf(initialValue));

return a;
}

private static Action enableToggle(Action a) {
return enableToggle(a, false);
}

class GeneralAction extends MnemonicAwareAction {

private final String command;
Expand Down Expand Up @@ -1257,9 +1266,22 @@ private void fillMenu() {
groups.add(toggleHighlightAnyItem);
JRadioButtonMenuItem toggleHighlightAllItem = new JRadioButtonMenuItem(toggleHighlightAll);
groups.add(toggleHighlightAllItem);
JRadioButtonMenuItem toggleHighlightDisableItem = new JRadioButtonMenuItem(toggleHighlightDisable);
groups.add(toggleHighlightDisableItem);
ButtonGroup highlightButtonGroup = new ButtonGroup();
highlightButtonGroup.add(toggleHighlightDisableItem);
highlightButtonGroup.add(toggleHighlightAnyItem);
highlightButtonGroup.add(toggleHighlightAllItem);

String toggleHighlightStatus = Globals.prefs.get(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING);
if("all".equals(toggleHighlightStatus)) {
toggleHighlightAllItem.setSelected(true);
} else if("any".equals(toggleHighlightStatus)) {
toggleHighlightAnyItem.setSelected(true);
} else {
toggleHighlightDisableItem.setSelected(true);
}

mb.add(groups);

view.add(getBackAction());
Expand Down Expand Up @@ -1497,7 +1519,7 @@ private void initActions() {
moveToGroup, autoLinkFile, resolveDuplicateKeys, openUrl, openFolder, openFile, togglePreview,
dupliCheck, autoSetFile, newEntryAction, plainTextImport, getMassSetField(), getManageKeywords(),
pushExternalButton.getMenuAction(), closeDatabaseAction, getSwitchPreviewAction(), checkIntegrity,
toggleHighlightAny, toggleHighlightAll, databaseProperties, abbreviateIso, abbreviateMedline,
toggleHighlightAny, toggleHighlightAll, toggleHighlightDisable, databaseProperties, abbreviateIso, abbreviateMedline,
unabbreviate, exportAll, exportSelected, importCurrent, saveAll, dbConnect, dbExport, focusTable,
toggleRelevance, toggleQualityAssured, togglePrinted, pushExternalButton.getComponent()));

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/actions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Actions {
public static final String SWITCH_PREVIEW = "switchPreview";
public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ALL = "toggleHighlightGroupsMatchingAll";
public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_ANY = "toggleHighlightGroupsMatchingAny";
public static final String TOGGLE_HIGHLIGHTS_GROUPS_MATCHING_DISABLE = "toggleHighlightGroupsMatchingDisable";
public static final String TOGGLE_GROUPS = "toggleGroups";
public static final String TOGGLE_PREVIEW = "togglePreview";
public static final String TOGGLE_TOOLBAR = "toggleToolbar";
Expand Down

0 comments on commit e876cd3

Please sign in to comment.