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.List;
29 import javax.swing.JComboBox;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
38 @SuppressWarnings(
"PMD.SingularField")
42 private static final long serialVersionUID = 1L;
43 private int lastSelectedIndex = 0;
54 DISPLAY_PANE.setEditable(
false);
55 textScrollPane.setViewportView(DISPLAY_PANE);
59 final void removeDisplayTextOptions(String option) {
60 displayTextComboBox.removeItem(option);
63 public void display(String text, ComponentOrientation direction,
int font) {
64 DISPLAY_PANE.setComponentOrientation(direction);
66 DISPLAY_PANE.setFont(
new Font(DISPLAY_PANE.getFont().getName(),
67 font, DISPLAY_PANE.getFont().getSize()));
68 DISPLAY_PANE.setCaretPosition(0);
71 void addDisplayTextActionListener(ActionListener listener) {
72 displayTextComboBox.addActionListener(listener);
75 final void addOcrDropDownActionListener(ActionListener listener) {
76 ocrDropdown.addActionListener(listener);
79 String getDisplayDropDownSelection() {
80 return (String) displayTextComboBox.getSelectedItem();
83 String getSelectedOcrLanguagePack() {
84 String selection = (String) ocrDropdown.getSelectedItem();
85 return Strings.nullToEmpty(LANGUAGE_NAMES.inverse().get(selection));
94 for (ActionListener listener : dropDown.getActionListeners()) {
95 dropDown.removeActionListener(listener);
99 void setWarningLabelMsg(String msg) {
100 warningLabel.setText(msg);
103 @NbBundle.Messages({
"TranslationContentPanel.autoDetectOCR=Autodetect language"})
105 display(
"", ComponentOrientation.LEFT_TO_RIGHT, Font.PLAIN);
107 removeAllActionListeners(displayTextComboBox);
108 displayTextComboBox.removeAllItems();
109 displayTextComboBox.addItem(DisplayDropdownOptions.TRANSLATED_TEXT.toString());
110 displayTextComboBox.addItem(DisplayDropdownOptions.ORIGINAL_TEXT.toString());
112 enableOCRSelection(
false);
113 removeAllActionListeners(ocrDropdown);
114 ocrDropdown.removeAllItems();
117 final void enableOCRSelection(
boolean enabled) {
118 ocrLabel.setEnabled(enabled);
119 ocrDropdown.setEnabled(enabled);
127 void addLanguagePackNames(List<String> languagePackAbbreviations) {
129 ocrDropdown.addItem(Bundle.TranslationContentPanel_autoDetectOCR());
132 List<String> localCopy =
new ArrayList<>(languagePackAbbreviations);
134 localCopy.stream().sorted().forEach((abbrev) -> {
135 if (LANGUAGE_NAMES.get(abbrev) != null) {
136 ocrDropdown.addItem(LANGUAGE_NAMES.get(abbrev));
140 ocrDropdown.setSelectedIndex(lastSelectedIndex);
141 addOcrDropDownActionListener((ActionEvent e) -> {
142 lastSelectedIndex = ocrDropdown.getSelectedIndex();
147 return ImmutableBiMap.<String, String>builder()
148 .put(
"afr",
"Afrikaans")
149 .put(
"amh",
"Amharic")
150 .put(
"ara",
"Arabic")
151 .put(
"asm",
"Assamese")
152 .put(
"aze",
"Azerbaijani")
153 .put(
"aze_cyrl",
"Azerbaijani - Cyrillic")
154 .put(
"bel",
"Belarusian")
155 .put(
"ben",
"Bengali")
156 .put(
"bod",
"Tibetan")
157 .put(
"bos",
"Bosnian")
158 .put(
"bul",
"Bulgarian")
159 .put(
"cat",
"Catalan; Valencian")
160 .put(
"ceb",
"Cebuano")
162 .put(
"chi_sim",
"Chinese - Simplified")
163 .put(
"chi_tra",
"Chinese - Traditional")
164 .put(
"chr",
"Cherokee")
166 .put(
"dan",
"Danish")
167 .put(
"deu",
"German")
168 .put(
"dzo",
"Dzongkha")
169 .put(
"ell",
"Greek, Modern (1453-)")
170 .put(
"eng",
"English")
171 .put(
"enm",
"English, Middle (1100-1500)")
172 .put(
"epo",
"Esperanto")
173 .put(
"est",
"Estonian")
174 .put(
"eus",
"Basque")
175 .put(
"fas",
"Persian")
176 .put(
"fin",
"Finnish")
177 .put(
"fra",
"French")
178 .put(
"frk",
"Frankish")
179 .put(
"frm",
"French, Middle (ca. 1400-1600)")
181 .put(
"glg",
"Galician")
182 .put(
"grc",
"Greek, Ancient (-1453)")
183 .put(
"guj",
"Gujarati")
184 .put(
"hat",
"Haitian; Haitian Creole")
185 .put(
"heb",
"Hebrew")
187 .put(
"hrv",
"Croatian")
188 .put(
"hun",
"Hungarian")
189 .put(
"iku",
"Inuktitut")
190 .put(
"ind",
"Indonesian")
191 .put(
"isl",
"Icelandic")
192 .put(
"ita",
"Italian")
193 .put(
"ita_old",
"Italian - Old")
194 .put(
"jav",
"Javanese")
195 .put(
"jpn",
"Japanese")
196 .put(
"kan",
"Kannada")
197 .put(
"kat",
"Georgian")
198 .put(
"kat_old",
"Georgian - Old")
199 .put(
"kaz",
"Kazakh")
200 .put(
"khm",
"Central Khmer")
201 .put(
"kir",
"Kirghiz; Kyrgyz")
202 .put(
"kor",
"Korean")
203 .put(
"kur",
"Kurdish")
206 .put(
"lav",
"Latvian")
207 .put(
"lit",
"Lithuanian")
208 .put(
"mal",
"Malayalam")
209 .put(
"mar",
"Marathi")
210 .put(
"mkd",
"Macedonian")
211 .put(
"mlt",
"Maltese")
213 .put(
"mya",
"Burmese")
214 .put(
"nep",
"Nepali")
215 .put(
"nld",
"Dutch; Flemish")
216 .put(
"nor",
"Norwegian")
218 .put(
"pan",
"Panjabi; Punjabi")
219 .put(
"pol",
"Polish")
220 .put(
"por",
"Portuguese")
221 .put(
"pus",
"Pushto; Pashto")
222 .put(
"ron",
"Romanian; Moldavian; Moldovan")
223 .put(
"rus",
"Russian")
224 .put(
"san",
"Sanskrit")
225 .put(
"sin",
"Sinhala; Sinhalese")
226 .put(
"slk",
"Slovak")
227 .put(
"slv",
"Slovenian")
228 .put(
"spa",
"Spanish; Castilian")
229 .put(
"spa_old",
"Spanish; Castilian - Old")
230 .put(
"sqi",
"Albanian")
231 .put(
"srp",
"Serbian")
232 .put(
"srp_latn",
"Serbian - Latin")
233 .put(
"swa",
"Swahili")
234 .put(
"swe",
"Swedish")
235 .put(
"syr",
"Syriac")
237 .put(
"tel",
"Telugu")
239 .put(
"tgl",
"Tagalog")
241 .put(
"tir",
"Tigrinya")
242 .put(
"tur",
"Turkish")
243 .put(
"uig",
"Uighur; Uyghur")
244 .put(
"ukr",
"Ukrainian")
247 .put(
"uzb_cyrl",
"Uzbek - Cyrillic")
248 .put(
"vie",
"Vietnamese")
249 .put(
"yid",
"Yiddish")
255 LANGUAGE_NAMES = createLanguageBiMap();
261 @Messages({
"TranslatedContentPanel.comboBoxOption.originalText=Original Text (Up to 25KB)",
262 "TranslatedContentPanel.comboBoxOption.translatedText=Translated Text"})
263 static enum DisplayDropdownOptions {
264 ORIGINAL_TEXT(Bundle.TranslatedContentPanel_comboBoxOption_originalText()),
265 TRANSLATED_TEXT(Bundle.TranslatedContentPanel_comboBoxOption_translatedText());
267 private final String displayString;
269 DisplayDropdownOptions(String displayString) {
270 this.displayString = displayString;
274 public String toString() {
275 return displayString;
284 @SuppressWarnings(
"unchecked")
286 private
void initComponents() {
287 java.awt.GridBagConstraints gridBagConstraints;
289 jPanel1 =
new javax.swing.JPanel();
290 displayTextComboBox =
new javax.swing.JComboBox<>();
291 ocrDropdown =
new javax.swing.JComboBox<>();
292 ocrLabel =
new javax.swing.JLabel();
293 warningLabel =
new javax.swing.JLabel();
294 showLabel =
new javax.swing.JLabel();
295 textScrollPane =
new javax.swing.JScrollPane();
297 setMaximumSize(
new java.awt.Dimension(2000, 2000));
298 setMinimumSize(
new java.awt.Dimension(2, 2));
300 setPreferredSize(
new java.awt.Dimension(100, 58));
301 setVerifyInputWhenFocusTarget(
false);
302 setLayout(
new java.awt.BorderLayout());
304 jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
305 jPanel1.setMaximumSize(
new java.awt.Dimension(182, 24));
306 jPanel1.setPreferredSize(
new java.awt.Dimension(182, 24));
307 jPanel1.setLayout(
new java.awt.GridBagLayout());
309 displayTextComboBox.setMinimumSize(
new java.awt.Dimension(43, 20));
310 displayTextComboBox.setPreferredSize(
new java.awt.Dimension(43, 20));
311 gridBagConstraints =
new java.awt.GridBagConstraints();
312 gridBagConstraints.gridx = 3;
313 gridBagConstraints.gridy = 0;
314 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
315 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
316 gridBagConstraints.weightx = 0.1;
317 gridBagConstraints.insets =
new java.awt.Insets(0, 5, 0, 0);
318 jPanel1.add(displayTextComboBox, gridBagConstraints);
320 ocrDropdown.setModel(
new javax.swing.DefaultComboBoxModel<>(
new String[] {
"N/A" }));
321 ocrDropdown.setEnabled(
false);
322 ocrDropdown.setName(
"");
323 gridBagConstraints =
new java.awt.GridBagConstraints();
324 gridBagConstraints.gridx = 5;
325 gridBagConstraints.gridy = 0;
326 gridBagConstraints.gridwidth = 2;
327 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
328 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
329 gridBagConstraints.weightx = 0.1;
330 gridBagConstraints.insets =
new java.awt.Insets(0, 5, 0, 0);
331 jPanel1.add(ocrDropdown, gridBagConstraints);
333 org.openide.awt.Mnemonics.setLocalizedText(ocrLabel,
org.openide.util.NbBundle.getMessage(
TranslationContentPanel.class,
"TranslationContentPanel.ocrLabel.text"));
334 ocrLabel.setEnabled(
false);
335 gridBagConstraints =
new java.awt.GridBagConstraints();
336 gridBagConstraints.gridx = 4;
337 gridBagConstraints.gridy = 0;
338 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
339 gridBagConstraints.insets =
new java.awt.Insets(0, 10, 0, 0);
340 jPanel1.add(ocrLabel, gridBagConstraints);
342 warningLabel.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/warning16.png")));
343 gridBagConstraints =
new java.awt.GridBagConstraints();
344 gridBagConstraints.gridx = 0;
345 gridBagConstraints.gridy = 0;
346 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
347 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
348 gridBagConstraints.weightx = 0.25;
349 jPanel1.add(warningLabel, gridBagConstraints);
351 org.openide.awt.Mnemonics.setLocalizedText(showLabel,
org.openide.util.NbBundle.getMessage(
TranslationContentPanel.class,
"TranslationContentPanel.showLabel.text"));
352 gridBagConstraints =
new java.awt.GridBagConstraints();
353 gridBagConstraints.gridx = 2;
354 gridBagConstraints.gridy = 0;
355 jPanel1.add(showLabel, gridBagConstraints);
357 add(jPanel1, java.awt.BorderLayout.NORTH);
359 textScrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
360 textScrollPane.setMaximumSize(
new java.awt.Dimension(20000, 20000));
361 textScrollPane.setPreferredSize(
new java.awt.Dimension(640, 250));
362 add(textScrollPane, java.awt.BorderLayout.CENTER);
TranslationContentPanel()
static ImmutableBiMap< String, String > createLanguageBiMap()
javax.swing.JScrollPane textScrollPane
void setText(String text)
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.JComboBox< String > ocrDropdown
static final ImmutableBiMap< String, String > LANGUAGE_NAMES
javax.swing.JPanel jPanel1
void removeAllActionListeners(JComboBox< String > dropDown)