public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
// we cannot re-use the existing LT object anymore
frame.applyComponentOrientation(
ComponentOrientation.getOrientation(Locale.getDefault()));
Language lang = (Language) languageBox.getSelectedItem();
ComponentOrientation componentOrientation =
ComponentOrientation.getOrientation(lang.getLocale());
textArea.applyComponentOrientation(componentOrientation);
resultArea.applyComponentOrientation(componentOrientation);
ltSupport.setLanguage(lang);
}
}
});
autoDetectBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
languageBox.setEnabled(!selected);
ltSupport.getConfig().setAutoDetect(selected);
if (selected) {
Language detected = ltSupport.autoDetectLanguage(textArea.getText());
languageBox.selectLanguage(detected);
}
}
});
ltSupport.addLanguageToolListener(new LanguageToolListener() {
@Override
public void languageToolEventOccurred(LanguageToolEvent event) {
if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) {
final String msg = Tools.makeTexti18n(messages, "checkStart");
statusLabel.setText(msg);
if (event.getCaller() == getFrame()) {
startTime = System.currentTimeMillis();
setWaitCursor();
checkAction.setEnabled(false);
}
} else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) {
if (event.getCaller() == getFrame()) {
checkAction.setEnabled(true);
unsetWaitCursor();
resultAreaHelper.setRunTime(System.currentTimeMillis() - startTime);
resultAreaHelper.displayResult();
final String msg = Tools.makeTexti18n(messages, "checkDone", event.getSource().getMatches().size(), System.currentTimeMillis() - startTime);
statusLabel.setText(msg);
} else {
final String msg = Tools.makeTexti18n(messages, "checkDoneNoTime", event.getSource().getMatches().size());
statusLabel.setText(msg);
}
}
else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) {
languageBox.selectLanguage(ltSupport.getLanguage());
}
}
});
frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
Language lang = ltSupport.getLanguage();
ComponentOrientation componentOrientation =
ComponentOrientation.getOrientation(lang.getLocale());
textArea.applyComponentOrientation(componentOrientation);
resultArea.applyComponentOrientation(componentOrientation);
ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage());
textArea.setText(textLanguageMessageBundle.getString("guiDemoText"));