Closed rhit-hueyee closed 4 months ago
Here is the current status:
I have added Global Settings #12 and settings contains a current Locale that can be set. I also added a LocaleManager which is where the Languages and Locales are stored. My current problem is that I know how to change the current Locale in settings, I do not know how dispatch an event that calls this.setTitle(Text.getTextFromLocale("Title")); again and updates the title, for example. I have tried an implementation using observers but have been unsuccessful.
This has been solved. The setup involved placing a Listener/Observer at each point where the text needs to be changed. I also tried have to place only 1 Observer at the top and recurse through the component, but I found that it didn't work to well, mainly due to speed/inconsistency.
It starts with implementing:
public interface UIChangeListener {
void updateLangUI();
}
and then adding the method in your class that implements the interface:
@Override
public void updateLangUI() {
configureMenus();
}
Note: idk if Override is neccesary
In general, either directly change the title/text of the thing you want to change, like this:
this.setTitle(Text.getTextFromLocale("Title"));
If you want to loop through a bunch of things:
private void removeAllMenus(JMenuBar jMenuBar) {
int count = jMenuBar.getMenuCount();
for (int i = count - 1; i >= 0; i--) {
jMenuBar.remove(i);
}
}
Then add what you want to add:
JMenu textEditMenu = new JMenu(Text.getTextFromLocale("GeneralMenuEdit"));
this.textEditMenuBar.add(textEditMenu);
Specifically for Language update, it is triggered by this code:
languageItem.addActionListener(e -> {
System.out.println("Setting locale to " + locale.getLanguage());
settings.setLocale(locale);
settings.echoUpdateUI();
this.revalidate();
this.repaint();
});
This section of code has made me concerned:
This is from the Launcher class, which is the entry point into the software.
Currently the Locales are being stored in the Launcher class in this snippet
But then comes this section within TextEditWrapper
This gives me the question: how should Locales/Languages be stored and accessed?