19 package org.sleuthkit.autopsy.contentviewers;
21 import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 import java.awt.Component;
23 import java.awt.ComponentOrientation;
24 import java.io.IOException;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.ThreadFactory;
28 import javax.swing.ImageIcon;
29 import javax.swing.JPanel;
30 import javax.swing.SwingUtilities;
31 import org.openide.util.NbBundle.Messages;
55 super(message, cause);
103 boolean shouldTranslate() {
125 ComponentOrientation getOrientation() {
152 protected void onErrorDisplay(String text, ComponentOrientation orientation,
int font) {
157 protected String
retrieveText() throws IOException, InterruptedException, IllegalStateException {
162 protected void onTextDisplay(String text, ComponentOrientation orientation,
int font) {
180 private final ExecutorService
executorService = Executors.newSingleThreadExecutor(translationThreadFactory);
192 @Messages({
"TranslatablePanel.comboBoxOption.originalText=Original Text",
193 "TranslatablePanel.comboBoxOption.translatedText=Translated Text"})
197 Bundle.TranslatablePanel_comboBoxOption_originalText(),
198 Bundle.TranslatablePanel_comboBoxOption_translatedText(),
206 TranslatablePanel(ContentComponent contentComponent, String origOptionText, String translatedOptionText, String origContent,
212 additionalInit(contentComponent.getRootComponent(), origOptionText, translatedOptionText);
232 this.cachedTranslated = translated;
241 if (backgroundTask != null && !backgroundTask.isDone()) {
242 backgroundTask.cancel(
true);
244 backgroundTask = null;
258 executorService.execute(backgroundTask);
275 public void setContent(String content, String contentDescriptor) {
279 this.prevTranslateSelection =
false;
297 return translationService.
translate(input);
312 private synchronized void setStatus(String msg,
boolean showWarningIcon) {
314 statusLabel.setIcon(showWarningIcon ? warningIcon : null);
337 @Messages({
"# {0} - exception message",
"TranslatablePanel.onSetContentError.text=There was an error displaying the text: {0}"})
339 SwingUtilities.invokeLater(() -> {
341 contentComponent.setContent(content, orientation);
343 setStatus(Bundle.TranslatablePanel_onSetContentError_text(ex.getMessage()),
true);
351 private void additionalInit(Component rootComponent, String origOptionText, String translatedOptionText) {
352 add(rootComponent, java.awt.BorderLayout.CENTER);
363 boolean curTranslateSelection = translateOption.shouldTranslate();
364 if (curTranslateSelection != this.prevTranslateSelection) {
365 this.prevTranslateSelection = curTranslateSelection;
370 if (curTranslateSelection) {
372 if (translated != null) {
388 @SuppressWarnings(
"unchecked")
396 setMaximumSize(
new java.awt.Dimension(2000, 2000));
397 setMinimumSize(
new java.awt.Dimension(2, 2));
399 setPreferredSize(
new java.awt.Dimension(100, 58));
400 setVerifyInputWhenFocusTarget(
false);
401 setLayout(
new java.awt.BorderLayout());
403 translationBar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
413 public void actionPerformed(java.awt.event.ActionEvent evt) {
419 statusLabel.setMaximumSize(
new java.awt.Dimension(32767, 32767));
boolean prevTranslateSelection
final ThreadFactory translationThreadFactory
static final long serialVersionUID
TranslatedText getCachedTranslated()
void onTextDisplay(String text, ComponentOrientation orientation, int font)
void onErrorDisplay(String text, ComponentOrientation orientation, int font)
synchronized String translate(String input)
synchronized void setChildComponentContent(String content, ComponentOrientation orientation)
void setContent(String content, ComponentOrientation orientation)
void setContent(String content, String contentDescriptor)
void additionalInit(Component rootComponent, String origOptionText, String translatedOptionText)
final ExecutorService executorService
volatile TranslatedText cachedTranslated
volatile OnTranslation backgroundTask
String retrieveTranslation(String input)
final Object backgroundTaskLock
static TextTranslationService getInstance()
void runTranslationTask()
void setChildComponentContent(String content)
void translateComboBoxActionPerformed(java.awt.event.ActionEvent evt)
final ContentComponent contentComponent
final String contentDescriptor
void onProgressDisplay(String text, ComponentOrientation orientation, int font)
void handleComboBoxChange(TranslateOption translateOption)
String translate(String input)
TranslatablePanel(ContentComponent contentComponent)
synchronized boolean hasProvider()
void setTranslationEnabled()
javax.swing.JComboBox< TranslateOption > translateComboBox
final ComponentOrientation orientation
javax.swing.JLabel statusLabel
void cancelPendingTranslation()
static final ComponentOrientation DEFAULT_ORIENTATION
Component getRootComponent()
final Object cachedTranslatedLock
void setCachedTranslated(TranslatedText translated)
static final long serialVersionUID
synchronized void setStatus(String msg, boolean showWarningIcon)
final ImageIcon warningIcon
final TextTranslationService translationService
javax.swing.JPanel translationBar