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