updates for async behavior

This commit is contained in:
Greg DiCristofaro 2020-03-05 07:37:51 -05:00
parent dc53c93eec
commit 1f7ab40a4d

View File

@ -22,6 +22,7 @@ import java.awt.Component;
import java.util.logging.Level;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.texttranslation.NoServiceProviderException;
@ -103,12 +104,15 @@ final class TextTranslatableComponent implements TranslatablePanel.TranslatableC
this.translate = translate;
if (this.translate) {
if (this.translated == null) {
try {
this.translated = this.translationService.translate(this.origContent);
} catch (NoServiceProviderException | TranslationException ex) {
LOGGER.log(Level.WARNING, "Unable to translate text with translation service", ex);
return Bundle.TextTranslatableComponent_setTranslated_onTranslateError();
}
final String originalContent = this.origContent;
SwingUtilities.invokeLater(() -> {
try {
this.translated = this.translationService.translate(originalContent);
} catch (NoServiceProviderException | TranslationException ex) {
LOGGER.log(Level.WARNING, "Unable to translate text with translation service", ex);
return Bundle.TextTranslatableComponent_setTranslated_onTranslateError();
}
});
}
return onErr(setPanelContent(this.translated == null ? "" : this.translated));
} else {