mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-08-18 02:56:24 +00:00
refactor Spellcheck plugin
This commit is contained in:
@ -41,7 +41,7 @@ public class SpellcheckChatRoomDecorator {
|
||||
private RolloverButton _spellingButton;
|
||||
private final ChatRoom _room;
|
||||
private final JComboBox<String> _languageSelection = new JComboBox<>();
|
||||
private Map<String, String> _languages;
|
||||
private Map<String, String> _languages = new HashMap<>();
|
||||
|
||||
public SpellcheckChatRoomDecorator(ChatRoom room) {
|
||||
_room = room;
|
||||
@ -87,23 +87,18 @@ public class SpellcheckChatRoomDecorator {
|
||||
}
|
||||
|
||||
private void languagesToLocales() {
|
||||
String spellLanguage = SpellcheckManager.getInstance().getSpellcheckerPreference().getPreferences().getSpellLanguage();
|
||||
_languages = new HashMap<>();
|
||||
Locale[] locales = Locale.getAvailableLocales();
|
||||
SpellcheckerPreferences preferences = SpellcheckManager.getInstance().getSpellcheckerPreference().getPreferences();
|
||||
String spellLanguage = preferences.getSpellLanguage();
|
||||
_languages.clear();
|
||||
List<String> languages = SpellcheckManager.getInstance().getSupportedLanguages();
|
||||
for (String language : languages) {
|
||||
for (final Locale locale : locales) {
|
||||
if (locale.toString().equals(language)) {
|
||||
String label = locale.getDisplayLanguage(Locale.getDefault());
|
||||
if (!locale.getDisplayCountry(locale).isEmpty()) {
|
||||
label = label + "-" + locale.getDisplayCountry(locale);
|
||||
}
|
||||
_languages.put(label, language);
|
||||
_languageSelection.addItem(label);
|
||||
if (language.equals(spellLanguage)) {
|
||||
_languageSelection.setSelectedItem(label);
|
||||
}
|
||||
}
|
||||
String localeTag = language.replace("_", "-");
|
||||
Locale locale = Locale.forLanguageTag(localeTag);
|
||||
String label = locale.getDisplayName(Locale.getDefault());
|
||||
_languageSelection.addItem(label);
|
||||
_languages.put(label, language);
|
||||
if (language.equals(spellLanguage)) {
|
||||
_languageSelection.setSelectedItem(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,12 +63,13 @@ public class SpellcheckManager {
|
||||
}
|
||||
|
||||
public SpellDictionary getDictionary(String language) {
|
||||
File personalDictionary = new File(SparkManager.getUserDirectory(), "personalDictionary.dict");
|
||||
try {
|
||||
InputStream dictionary = getClass().getClassLoader().getResourceAsStream("dictionary/" + language + ".zip");
|
||||
if (dictionary == null) {
|
||||
Log.error("Dictionary not found");
|
||||
return null;
|
||||
}
|
||||
File personalDictionary = new File(SparkManager.getUserDirectory(), "personalDictionary.dict");
|
||||
SpellDictionary dict = new OpenOfficeSpellDictionary(dictionary, personalDictionary);
|
||||
return dict;
|
||||
} catch (IOException e) {
|
||||
|
||||
@ -42,7 +42,6 @@ public class SpellcheckerPreferenceDialog extends JPanel {
|
||||
private final JPanel spellPanel = new JPanel();
|
||||
private final JLabel lLanguage = new JLabel();
|
||||
|
||||
private final Locale[] locales = Locale.getAvailableLocales();
|
||||
private final ArrayList<String> languages;
|
||||
|
||||
public SpellcheckerPreferenceDialog(ArrayList<String> languages) {
|
||||
@ -52,15 +51,10 @@ public class SpellcheckerPreferenceDialog extends JPanel {
|
||||
ignoreCase.addActionListener(e -> setIgnoreUppercase(ignoreCase.isSelected()));
|
||||
spellcheckingEnabled.addActionListener(e -> updateUI(spellcheckingEnabled.isSelected()));
|
||||
for (String language : languages) {
|
||||
for (final Locale locale : locales) {
|
||||
if (locale.toString().equals(language)) {
|
||||
String label = locale.getDisplayLanguage(Locale.getDefault());
|
||||
if (!locale.getDisplayCountry(locale).isEmpty()) {
|
||||
label = label + "-" + locale.getDisplayCountry(locale);
|
||||
}
|
||||
spellLanguages.addItem(label);
|
||||
}
|
||||
}
|
||||
String localeTag = language.replace("_", "-");
|
||||
Locale locale = Locale.forLanguageTag(localeTag);
|
||||
String label = locale.getDisplayName(Locale.getDefault());
|
||||
spellLanguages.addItem(label);
|
||||
}
|
||||
|
||||
Insets insets = new Insets(5, 5, 5, 5);
|
||||
|
||||
Reference in New Issue
Block a user