19 package org.sleuthkit.autopsy.texttranslation.ui;
21 import com.google.common.base.Strings;
22 import com.google.common.collect.ImmutableBiMap;
23 import java.awt.ComponentOrientation;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30 import javax.swing.JComboBox;
31 import org.openide.util.NbBundle;
32 import org.openide.util.NbBundle.Messages;
40 @SuppressWarnings(
"PMD.SingularField")
44 private static final long serialVersionUID = 1L;
45 private int lastSelectedIndex = 0;
54 additionalInitComponents();
57 DISPLAY_PANE.setEditable(
false);
58 textScrollPane.setViewportView(DISPLAY_PANE);
62 final void removeDisplayTextOptions(String option) {
63 displayTextComboBox.removeItem(option);
66 public void display(String text, ComponentOrientation direction,
int font) {
67 DISPLAY_PANE.setComponentOrientation(direction);
69 DISPLAY_PANE.setFont(
new Font(DISPLAY_PANE.getFont().getName(),
70 font, DISPLAY_PANE.getFont().getSize()));
71 DISPLAY_PANE.setCaretPosition(0);
74 void addDisplayTextActionListener(ActionListener listener) {
75 displayTextComboBox.addActionListener(listener);
78 final void addOcrDropDownActionListener(ActionListener listener) {
79 ocrDropdown.addActionListener(listener);
82 String getDisplayDropDownSelection() {
83 return (String) displayTextComboBox.getSelectedItem();
86 String getSelectedOcrLanguagePack() {
87 String selection = (String) ocrDropdown.getSelectedItem();
88 return Strings.nullToEmpty(LANGUAGE_NAMES.inverse().get(selection));
97 for (ActionListener listener : dropDown.getActionListeners()) {
98 dropDown.removeActionListener(listener);
102 void setWarningLabelMsg(String msg) {
103 warningLabel.setText(msg);
106 @NbBundle.Messages({
"TranslationContentPanel.autoDetectOCR=Autodetect language"})
108 display(
"", ComponentOrientation.LEFT_TO_RIGHT, Font.PLAIN);
110 removeAllActionListeners(displayTextComboBox);
111 displayTextComboBox.removeAllItems();
112 displayTextComboBox.addItem(DisplayDropdownOptions.TRANSLATED_TEXT.toString());
113 displayTextComboBox.addItem(DisplayDropdownOptions.ORIGINAL_TEXT.toString());
115 enableOCRSelection(
false);
116 removeAllActionListeners(ocrDropdown);
117 ocrDropdown.removeAllItems();
120 final void enableOCRSelection(
boolean enabled) {
121 ocrLabel.setEnabled(enabled);
122 ocrDropdown.setEnabled(enabled);
130 void addLanguagePackNames(List<String> languagePackAbbreviations) {
132 ocrDropdown.addItem(Bundle.TranslationContentPanel_autoDetectOCR());
135 List<String> localCopy =
new ArrayList<>(languagePackAbbreviations);
137 localCopy.stream().sorted().forEach((abbrev) -> {
138 if (LANGUAGE_NAMES.get(abbrev) != null) {
139 ocrDropdown.addItem(LANGUAGE_NAMES.get(abbrev));
143 ocrDropdown.setSelectedIndex(lastSelectedIndex);
144 addOcrDropDownActionListener((ActionEvent e) -> {
145 lastSelectedIndex = ocrDropdown.getSelectedIndex();
150 return ImmutableBiMap.<String, String>builder()
151 .put(
"afr",
"Afrikaans")
152 .put(
"amh",
"Amharic")
153 .put(
"ara",
"Arabic")
154 .put(
"asm",
"Assamese")
155 .put(
"aze",
"Azerbaijani")
156 .put(
"aze_cyrl",
"Azerbaijani - Cyrillic")
157 .put(
"bel",
"Belarusian")
158 .put(
"ben",
"Bengali")
159 .put(
"bod",
"Tibetan")
160 .put(
"bos",
"Bosnian")
161 .put(
"bul",
"Bulgarian")
162 .put(
"cat",
"Catalan; Valencian")
163 .put(
"ceb",
"Cebuano")
165 .put(
"chi_sim",
"Chinese - Simplified")
166 .put(
"chi_tra",
"Chinese - Traditional")
167 .put(
"chr",
"Cherokee")
169 .put(
"dan",
"Danish")
170 .put(
"deu",
"German")
171 .put(
"dzo",
"Dzongkha")
172 .put(
"ell",
"Greek, Modern (1453-)")
173 .put(
"eng",
"English")
174 .put(
"enm",
"English, Middle (1100-1500)")
175 .put(
"epo",
"Esperanto")
176 .put(
"est",
"Estonian")
177 .put(
"eus",
"Basque")
178 .put(
"fas",
"Persian")
179 .put(
"fin",
"Finnish")
180 .put(
"fra",
"French")
181 .put(
"frk",
"Frankish")
182 .put(
"frm",
"French, Middle (ca. 1400-1600)")
184 .put(
"glg",
"Galician")
185 .put(
"grc",
"Greek, Ancient (-1453)")
186 .put(
"guj",
"Gujarati")
187 .put(
"hat",
"Haitian; Haitian Creole")
188 .put(
"heb",
"Hebrew")
190 .put(
"hrv",
"Croatian")
191 .put(
"hun",
"Hungarian")
192 .put(
"iku",
"Inuktitut")
193 .put(
"ind",
"Indonesian")
194 .put(
"isl",
"Icelandic")
195 .put(
"ita",
"Italian")
196 .put(
"ita_old",
"Italian - Old")
197 .put(
"jav",
"Javanese")
198 .put(
"jpn",
"Japanese")
199 .put(
"kan",
"Kannada")
200 .put(
"kat",
"Georgian")
201 .put(
"kat_old",
"Georgian - Old")
202 .put(
"kaz",
"Kazakh")
203 .put(
"khm",
"Central Khmer")
204 .put(
"kir",
"Kirghiz; Kyrgyz")
205 .put(
"kor",
"Korean")
206 .put(
"kur",
"Kurdish")
209 .put(
"lav",
"Latvian")
210 .put(
"lit",
"Lithuanian")
211 .put(
"mal",
"Malayalam")
212 .put(
"mar",
"Marathi")
213 .put(
"mkd",
"Macedonian")
214 .put(
"mlt",
"Maltese")
216 .put(
"mya",
"Burmese")
217 .put(
"nep",
"Nepali")
218 .put(
"nld",
"Dutch; Flemish")
219 .put(
"nor",
"Norwegian")
221 .put(
"pan",
"Panjabi; Punjabi")
222 .put(
"pol",
"Polish")
223 .put(
"por",
"Portuguese")
224 .put(
"pus",
"Pushto; Pashto")
225 .put(
"ron",
"Romanian; Moldavian; Moldovan")
226 .put(
"rus",
"Russian")
227 .put(
"san",
"Sanskrit")
228 .put(
"sin",
"Sinhala; Sinhalese")
229 .put(
"slk",
"Slovak")
230 .put(
"slv",
"Slovenian")
231 .put(
"spa",
"Spanish; Castilian")
232 .put(
"spa_old",
"Spanish; Castilian - Old")
233 .put(
"sqi",
"Albanian")
234 .put(
"srp",
"Serbian")
235 .put(
"srp_latn",
"Serbian - Latin")
236 .put(
"swa",
"Swahili")
237 .put(
"swe",
"Swedish")
238 .put(
"syr",
"Syriac")
240 .put(
"tel",
"Telugu")
242 .put(
"tgl",
"Tagalog")
244 .put(
"tir",
"Tigrinya")
245 .put(
"tur",
"Turkish")
246 .put(
"uig",
"Uighur; Uyghur")
247 .put(
"ukr",
"Ukrainian")
250 .put(
"uzb_cyrl",
"Uzbek - Cyrillic")
251 .put(
"vie",
"Vietnamese")
252 .put(
"yid",
"Yiddish")
258 LANGUAGE_NAMES = createLanguageBiMap();
265 controlPanel.setLayout(layout);
271 @Messages({
"TranslatedContentPanel.comboBoxOption.originalText=Original Text (Up to 25KB)",
272 "TranslatedContentPanel.comboBoxOption.translatedText=Translated Text"})
273 static enum DisplayDropdownOptions {
274 ORIGINAL_TEXT(Bundle.TranslatedContentPanel_comboBoxOption_originalText()),
275 TRANSLATED_TEXT(Bundle.TranslatedContentPanel_comboBoxOption_translatedText());
277 private final String displayString;
279 DisplayDropdownOptions(String displayString) {
280 this.displayString = displayString;
284 public String toString() {
285 return displayString;
294 @SuppressWarnings(
"unchecked")
296 private
void initComponents() {
298 controlPanel =
new javax.swing.JPanel();
299 javax.swing.JPanel warningLabelPanel =
new javax.swing.JPanel();
300 warningLabel =
new javax.swing.JLabel();
301 jSeparator1 =
new javax.swing.JSeparator();
302 showPanel =
new javax.swing.JPanel();
303 showLabel =
new javax.swing.JLabel();
304 javax.swing.JSeparator jSepMed1 =
new javax.swing.JSeparator();
305 displayTextComboBox =
new javax.swing.JComboBox<>();
306 ocrPanel =
new javax.swing.JPanel();
307 javax.swing.JSeparator jSepLarge1 =
new javax.swing.JSeparator();
308 ocrLabel =
new javax.swing.JLabel();
309 javax.swing.JSeparator jSepMed2 =
new javax.swing.JSeparator();
310 ocrDropdown =
new javax.swing.JComboBox<>();
311 textScrollPane =
new javax.swing.JScrollPane();
313 setMaximumSize(
new java.awt.Dimension(2000, 2000));
314 setMinimumSize(
new java.awt.Dimension(250, 2));
316 setPreferredSize(
new java.awt.Dimension(250, 58));
317 setVerifyInputWhenFocusTarget(
false);
318 setLayout(
new java.awt.BorderLayout());
320 controlPanel.setMaximumSize(
new java.awt.Dimension(20000, 20000));
321 controlPanel.setMinimumSize(
new java.awt.Dimension(2, 25));
322 controlPanel.setName(
"");
323 controlPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));
325 warningLabelPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
326 warningLabelPanel.setMinimumSize(
new java.awt.Dimension(2, 25));
327 warningLabelPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
329 warningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/warning16.png")));
330 warningLabel.setMaximumSize(
new java.awt.Dimension(250, 25));
331 warningLabel.setMinimumSize(
new java.awt.Dimension(150, 25));
332 warningLabel.setPreferredSize(null);
333 warningLabelPanel.add(warningLabel);
335 jSeparator1.setMaximumSize(
new java.awt.Dimension(1, 25));
336 jSeparator1.setMinimumSize(
new java.awt.Dimension(1, 25));
337 jSeparator1.setPreferredSize(
new java.awt.Dimension(1, 25));
338 warningLabelPanel.add(jSeparator1);
340 controlPanel.add(warningLabelPanel);
342 showPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
343 showPanel.setMinimumSize(
new java.awt.Dimension(0, 25));
344 showPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
346 org.openide.awt.Mnemonics.setLocalizedText(showLabel,
org.openide.util.NbBundle.getMessage(
TranslationContentPanel.class,
"TranslationContentPanel.showLabel.text"));
347 showLabel.setMaximumSize(
new java.awt.Dimension(42, 25));
348 showLabel.setMinimumSize(
new java.awt.Dimension(42, 25));
349 showLabel.setPreferredSize(null);
350 showPanel.add(showLabel);
352 jSepMed1.setPreferredSize(
new java.awt.Dimension(5, 0));
353 showPanel.add(jSepMed1);
355 displayTextComboBox.setMaximumSize(
new java.awt.Dimension(170, 25));
356 displayTextComboBox.setMinimumSize(
new java.awt.Dimension(170, 25));
357 displayTextComboBox.setPreferredSize(
new java.awt.Dimension(170, 25));
358 showPanel.add(displayTextComboBox);
360 controlPanel.add(showPanel);
362 ocrPanel.setMaximumSize(
new java.awt.Dimension(32767, 25));
363 ocrPanel.setMinimumSize(
new java.awt.Dimension(0, 25));
364 ocrPanel.setLayout(
new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));
366 jSepLarge1.setPreferredSize(
new java.awt.Dimension(10, 0));
367 ocrPanel.add(jSepLarge1);
368 jSepLarge1.getAccessibleContext().setAccessibleName(
org.openide.util.NbBundle.getMessage(
TranslationContentPanel.class,
"TranslationContentPanel.jSepLarge1.AccessibleContext.accessibleName"));
370 org.openide.awt.Mnemonics.setLocalizedText(ocrLabel,
org.openide.util.NbBundle.getMessage(
TranslationContentPanel.class,
"TranslationContentPanel.ocrLabel.text"));
371 ocrLabel.setEnabled(
false);
372 ocrLabel.setMaximumSize(
new java.awt.Dimension(40, 25));
373 ocrLabel.setMinimumSize(
new java.awt.Dimension(25, 16));
374 ocrLabel.setPreferredSize(null);
375 ocrPanel.add(ocrLabel);
377 jSepMed2.setPreferredSize(
new java.awt.Dimension(5, 0));
378 ocrPanel.add(jSepMed2);
380 ocrDropdown.setModel(
new javax.swing.DefaultComboBoxModel<>(
new String[] {
"N/A" }));
381 ocrDropdown.setEnabled(
false);
382 ocrDropdown.setMaximumSize(
new java.awt.Dimension(170, 25));
383 ocrDropdown.setMinimumSize(
new java.awt.Dimension(170, 25));
384 ocrDropdown.setName(
"");
385 ocrDropdown.setPreferredSize(
new java.awt.Dimension(170, 25));
386 ocrPanel.add(ocrDropdown);
388 controlPanel.add(ocrPanel);
390 add(controlPanel, java.awt.BorderLayout.NORTH);
392 textScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
393 textScrollPane.setMaximumSize(
new java.awt.Dimension(20000, 20000));
394 textScrollPane.setMinimumSize(
new java.awt.Dimension(20, 20));
395 textScrollPane.setPreferredSize(
new java.awt.Dimension(20, 20));
396 add(textScrollPane, java.awt.BorderLayout.CENTER);
TranslationContentPanel()
static ImmutableBiMap< String, String > createLanguageBiMap()
javax.swing.JScrollPane textScrollPane
void setText(String text)
javax.swing.JSeparator jSeparator1
void display(String text, ComponentOrientation direction, int font)
javax.swing.JLabel ocrLabel
javax.swing.JLabel showLabel
final AutoWrappingJTextPane DISPLAY_PANE
javax.swing.JComboBox< String > displayTextComboBox
javax.swing.JLabel warningLabel
javax.swing.JPanel showPanel
javax.swing.JComboBox< String > ocrDropdown
void additionalInitComponents()
javax.swing.JPanel controlPanel
javax.swing.JPanel ocrPanel
void setOppositeAligned(Collection< Component > oppAlignedComponents)
static final ImmutableBiMap< String, String > LANGUAGE_NAMES
void removeAllActionListeners(JComboBox< String > dropDown)