Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal for menu label enum usage #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -78,6 +77,7 @@
import net.sf.jabref.*;
import net.sf.jabref.gui.actions.*;
import net.sf.jabref.gui.keyboard.KeyBinds;
import net.sf.jabref.gui.labels.MenuLabel;
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.gui.worker.MarkEntriesAction;
import net.sf.jabref.gui.preftabs.PreferencesDialog;
Expand Down Expand Up @@ -209,15 +209,20 @@ void addAction(Action a) {
private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this);
private final AbstractAction integrityCheckAction = new IntegrityCheckAction(this);
private final AbstractAction forkMeOnGitHubAction = new ForkMeOnGitHubAction();
private final AbstractAction help = new HelpAction("JabRef help", helpDiag,
GUIGlobals.baseFrameHelp, Localization.lang("JabRef help"),
prefs.getKey("Help"));
private final AbstractAction contents = new HelpAction("Help contents", helpDiag,
GUIGlobals.helpContents, Localization.lang("Help contents"),
IconTheme.getImage("helpContents"));
private final AbstractAction about = new HelpAction("About JabRef", helpDiag,
GUIGlobals.aboutPage, Localization.lang("About JabRef"),
IconTheme.getImage("about"));

// private final AbstractAction help = new HelpAction("JabRef help", helpDiag,
// GUIGlobals.baseFrameHelp, Localization.lang("JabRef help"),
// prefs.getKey("Help"));
//// private final AbstractAction contents = new HelpAction("Help contents", helpDiag,
// GUIGlobals.helpContents, Localization.lang("Help contents"),
// IconTheme.getImage("helpContents"));
// private final AbstractAction about = new HelpAction("About JabRef", helpDiag,
// GUIGlobals.aboutPage, Localization.lang("About JabRef"),
// IconTheme.getImage("about"));
private final AbstractAction help = new HelpAction(MenuLabel.JabRef_Help, helpDiag, GUIGlobals.baseFrameHelp);
private final AbstractAction contents = new HelpAction(MenuLabel.Help_Contents, helpDiag, GUIGlobals.helpContents);
private final AbstractAction about = new HelpAction(MenuLabel.About_JabRef, helpDiag, GUIGlobals.aboutPage);

private final AbstractAction editEntry = new GeneralAction(Actions.EDIT, "Edit entry",
Localization.lang("Edit entry"),
prefs.getKey(KeyBinds.EDIT_ENTRY),
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/net/sf/jabref/gui/help/HelpAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.net.URL;

import javax.swing.Action;
import javax.swing.ImageIcon;
Expand All @@ -26,6 +25,7 @@

import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.MnemonicAwareAction;
import net.sf.jabref.gui.labels.MenuLabel;
import net.sf.jabref.logic.l10n.Localization;

/**
Expand Down Expand Up @@ -89,6 +89,19 @@ public HelpAction(String title, HelpDialog diag, String helpFile, String tooltip
this.helpFile = helpFile;
}

public HelpAction(MenuLabel menuLabel, HelpDialog dialog, String helpFile) {
putValue(Action.NAME, menuLabel.getTitleKey());
putValue(Action.SMALL_ICON, menuLabel.getIcon().orElse(IconTheme.getImage("help")));
if(menuLabel.getDescriptionKey().isPresent()) {
putValue(Action.SHORT_DESCRIPTION, Localization.lang(menuLabel.getDescriptionKey().get()));
}
if(menuLabel.getKeyStroke().isPresent()) {
putValue(Action.ACCELERATOR_KEY, menuLabel.getKeyStroke().get());
}
this.diag = dialog;
this.helpFile = helpFile;
}

public void setResourceOwner(Class resourceOwner) {
this.resourceOwner = resourceOwner;
}
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/net/sf/jabref/gui/labels/MenuLabel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package net.sf.jabref.gui.labels;

import net.sf.jabref.Globals;
import net.sf.jabref.gui.IconTheme;
import net.sf.jabref.gui.keyboard.KeyBinds;
import net.sf.jabref.logic.l10n.Localization;

import javax.swing.*;
import java.util.Optional;

public enum MenuLabel {

Abbreviate_journal_names_ISO("Abbreviate_journal_names_(ISO)"),
Abbreviate_journal_names_MEDLINE("Abbreviate_journal_names_(MEDLINE)"),
About_JabRef("About_JabRef", "About JabRef", "about"),
Append_database("Append_database"),

Help_Contents("Help_contents", "Help_contents", "helpContents"),
JabRef_Help("JabRef help", "JabRef help", "help", KeyBinds.HELP);

private String titleKey;
private Optional<String> descriptionKey = Optional.empty();
private Optional<ImageIcon> icon = Optional.empty();
private Optional<KeyStroke> keyStroke = Optional.empty();

MenuLabel(String titleKey) {
this.titleKey = Localization.menuTitle(titleKey);
}

MenuLabel(String titleKey, String descriptionKey) {
this.titleKey = Localization.menuTitle(titleKey);
this.descriptionKey = Optional.of(Localization.lang(descriptionKey));
}

MenuLabel(String titleKey, String descriptionKey, String iconName) {
this.titleKey = Localization.menuTitle(titleKey);
this.descriptionKey = Optional.of(Localization.lang(descriptionKey));
this.icon = Optional.of(IconTheme.getImage(iconName));
}

MenuLabel(String titleKey, String descriptionKey, String iconName, String keyStroke) {
this.titleKey = Localization.menuTitle(titleKey);
this.descriptionKey = Optional.of(Localization.lang(descriptionKey));
this.icon = Optional.of(IconTheme.getImage(iconName));
this.keyStroke = Optional.of(Globals.prefs.getKey(keyStroke));
}

public String getTitleKey() {
return titleKey;
}

public Optional<String> getDescriptionKey() {
return descriptionKey;
}

public Optional<ImageIcon> getIcon() {
return icon;
}

public Optional<KeyStroke> getKeyStroke() {
return keyStroke;
}
}