Skip to content

Commit

Permalink
Sets new icon. Sets JFileChooser CANCEL button based on language sele…
Browse files Browse the repository at this point in the history
…cted
  • Loading branch information
edimoral committed Mar 8, 2024
1 parent 9583a46 commit 7deb07e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/jpass/ui/JPassFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

import static jpass.ui.MessageDialog.NO_OPTION;
Expand All @@ -70,7 +71,9 @@
import static jpass.ui.MessageDialog.showQuestionMessage;
import static jpass.util.Constants.BOTTOM_MENU_ENTRIES_COUNT;
import static jpass.util.Constants.BOTTOM_MENU_ENTRIES_FOUND;
import static jpass.util.Constants.BUTTON_MESSAGE_CANCEL;
import static jpass.util.Constants.EDIT_MENU;
import static jpass.util.Constants.FILE_CHOOSER_CANCEL_BUTTON_TEXT;
import static jpass.util.Constants.FILE_MENU;
import static jpass.util.Constants.HELP_MENU;
import static jpass.util.Constants.LANGUAGE_EN_US;
Expand Down Expand Up @@ -127,6 +130,7 @@ private JPassFrame(String fileName, Locale locale) {

setSupportedLanguages();
setLocalizedMessages(locale);
UIManager.put("FileChooser.cancelButtonText", localizedMessages.getString(BUTTON_MESSAGE_CANCEL));

this.toolBar = new JToolBar();
this.toolBar.setFloatable(false);
Expand Down Expand Up @@ -199,13 +203,12 @@ private JPassFrame(String fileName, Locale locale) {

JMenu languageMenu = new JMenu(localizedMessages.getString(SETTINGS_MENU_LANGUAGE));
languageMenu.setActionCommand(SETTINGS_MENU_LANGUAGE);
languageMenu.setIcon(getIcon("world"));

SUPPORTED_LANGUAGES.forEach((key, value) -> {
JMenuItem language = new JMenuItem(localizedMessages.getString(key));
language.setActionCommand(key);
language.addActionListener(e -> {
refreshComponentsWithLanguage(e.getActionCommand());
});
language.addActionListener(e -> refreshComponentsWithLanguage(e.getActionCommand()));
languageMenu.add(language);
});
settingsMenu.add(languageMenu);
Expand Down Expand Up @@ -346,6 +349,8 @@ private void refreshComponentsWithLanguage(String actionCommand) {
Locale locale = Locale.forLanguageTag(getSupportedLanguages().get(actionCommand));
setLocalizedMessages(locale);

UIManager.put(FILE_CHOOSER_CANCEL_BUTTON_TEXT, localizedMessages.getString(BUTTON_MESSAGE_CANCEL));

fileMenu.setText(localizedMessages.getString(FILE_MENU));
editMenu.setText(localizedMessages.getString(EDIT_MENU));
toolsMenu.setText(localizedMessages.getString(TOOLS_MENU));
Expand All @@ -357,16 +362,18 @@ private void refreshComponentsWithLanguage(String actionCommand) {
updateMenuComponents(toolsMenu);
updateMenuComponents(settingsMenu);
updateMenuComponents(helpMenu);
//updateMenuComponents(toolBar);

refreshEntryTitleList(null);

MessageDialog.showInformationMessage(this, "Language has been changed");
}

private void updateMenuComponents(JMenu menu) {
for (int i = 0; i < menu.getItemCount(); i++) {
JMenuItem item = menu.getItem(i);
if (null != item) {
if (null != item.getActionCommand()) {
LOG.log(Level.INFO, String.format("ActionCommand: %s ", item.getActionCommand()));
item.setText(localizedMessages.getString(item.getActionCommand()));
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jpass/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ private Constants() {
// not intended to be instantiated
}

public static final String FILE_CHOOSER_CANCEL_BUTTON_TEXT = "FileChooser.cancelButtonText";

public static final String FILE_MENU = "menuBar.fileMenu";
public static final String EDIT_MENU = "menuBar.editMenu";
public static final String TOOLS_MENU = "menuBar.toolsMenu";
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/resources/images/world.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7deb07e

Please sign in to comment.