From 7deb07e3d6e9fcf2b206f5ec0729cdf2019b25ba Mon Sep 17 00:00:00 2001 From: Edi Morales Date: Fri, 8 Mar 2024 02:12:00 -0600 Subject: [PATCH] Sets new icon. Sets JFileChooser CANCEL button based on language selected --- src/main/java/jpass/ui/JPassFrame.java | 15 +++++++++++---- src/main/java/jpass/util/Constants.java | 2 ++ src/main/resources/resources/images/world.svg | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/resources/images/world.svg diff --git a/src/main/java/jpass/ui/JPassFrame.java b/src/main/java/jpass/ui/JPassFrame.java index 3cc1772..5522b93 100644 --- a/src/main/java/jpass/ui/JPassFrame.java +++ b/src/main/java/jpass/ui/JPassFrame.java @@ -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; @@ -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; @@ -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); @@ -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); @@ -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)); @@ -357,8 +362,11 @@ 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) { @@ -366,7 +374,6 @@ private void updateMenuComponents(JMenu menu) { 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())); } diff --git a/src/main/java/jpass/util/Constants.java b/src/main/java/jpass/util/Constants.java index 62bb624..598b450 100644 --- a/src/main/java/jpass/util/Constants.java +++ b/src/main/java/jpass/util/Constants.java @@ -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"; diff --git a/src/main/resources/resources/images/world.svg b/src/main/resources/resources/images/world.svg new file mode 100644 index 0000000..a1a9d03 --- /dev/null +++ b/src/main/resources/resources/images/world.svg @@ -0,0 +1,2 @@ + +world \ No newline at end of file