5061 test button added to google translate options panel

This commit is contained in:
William Schaefer 2019-05-30 13:46:15 -04:00
parent fd399e4cfb
commit e6670f34ba
6 changed files with 184 additions and 73 deletions

View File

@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.sleuthkit.autopsy.texttranslation.translators; package org.sleuthkit.autopsy.texttranslation.translators;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@ -35,11 +34,12 @@ import org.sleuthkit.autopsy.texttranslation.TextTranslator;
import org.sleuthkit.autopsy.texttranslation.TranslationException; import org.sleuthkit.autopsy.texttranslation.TranslationException;
/** /**
* Translates text by making HTTP requests to Bing Translator. * Translates text by making HTTP requests to Bing Translator. This requires a
* This requires a valid subscription key for a Microsoft Azure account. * valid subscription key for a Microsoft Azure account.
*/ */
@ServiceProvider(service = TextTranslator.class) @ServiceProvider(service = TextTranslator.class)
public class BingTranslator implements TextTranslator { public class BingTranslator implements TextTranslator {
//In the String below, "en" is the target language. You can include multiple target //In the String below, "en" is the target language. You can include multiple target
//languages separated by commas. A full list of supported languages is here: //languages separated by commas. A full list of supported languages is here:
//https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support //https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support
@ -52,7 +52,6 @@ public class BingTranslator implements TextTranslator{
//paid account that's willing to pay for long documents. //paid account that's willing to pay for long documents.
private final int MAX_STRING_LENGTH = 5000; private final int MAX_STRING_LENGTH = 5000;
public BingTranslator() { public BingTranslator() {
settingsPanel = new BingTranslatorSettingsPanel(settings.getAuthenticationKey(), settings.getTargetLanguageCode()); settingsPanel = new BingTranslatorSettingsPanel(settings.getAuthenticationKey(), settings.getTargetLanguageCode());
} }
@ -66,8 +65,11 @@ public class BingTranslator implements TextTranslator{
* posts it to Microsoft, and returns the JSON text response. * posts it to Microsoft, and returns the JSON text response.
* *
* @param string The input text to be translated. * @param string The input text to be translated.
*
* @return The translation response as a JSON string * @return The translation response as a JSON string
* @throws IOException if the request could not be executed due to cancellation, a connectivity problem or timeout. *
* @throws IOException if the request could not be executed due to
* cancellation, a connectivity problem or timeout.
*/ */
public String postTranslationRequest(String string) throws IOException { public String postTranslationRequest(String string) throws IOException {
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
@ -97,10 +99,8 @@ public class BingTranslator implements TextTranslator{
//Translates some text into English, without specifying the source langauge. //Translates some text into English, without specifying the source langauge.
// HTML files were producing lots of white space at the end // HTML files were producing lots of white space at the end
//Google Translate required us to replace (\r\n|\n) with <br /> //Google Translate required us to replace (\r\n|\n) with <br />
//but Bing Translator doesn not have that requirement. //but Bing Translator doesn not have that requirement.
//The free account has a maximum file size. If you have a paid account, //The free account has a maximum file size. If you have a paid account,
//you probably still want to limit file size to prevent accidentally //you probably still want to limit file size to prevent accidentally
//translating very large documents. //translating very large documents.
@ -131,25 +131,14 @@ public class BingTranslator implements TextTranslator{
public void saveSettings() { public void saveSettings() {
settings.setAuthenticationKey(settingsPanel.getAuthenticationKey()); settings.setAuthenticationKey(settingsPanel.getAuthenticationKey());
settings.setTargetLanguageCode(settingsPanel.getTargetLanguageCode()); settings.setTargetLanguageCode(settingsPanel.getTargetLanguageCode());
settings.saveSettings();
} }
private String parseJSONResponse(String json_text) throws TranslationException { private String parseJSONResponse(String json_text) throws TranslationException {
/* Here is an example of the text we get from Bing when input is "gato", /*
the Spanish word for cat: * Here is an example of the text we get from Bing when input is "gato",
[ * the Spanish word for cat: [ { "detectedLanguage": { "language": "es",
{ * "score": 1.0 }, "translations": [ { "text": "cat", "to": "en" } ] } ]
"detectedLanguage": {
"language": "es",
"score": 1.0
},
"translations": [
{
"text": "cat",
"to": "en"
}
]
}
]
*/ */
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
try { try {

View File

@ -51,7 +51,6 @@ public class BingTranslatorSettingsPanel extends javax.swing.JPanel {
*/ */
public BingTranslatorSettingsPanel(String authenticationKey, String code) { public BingTranslatorSettingsPanel(String authenticationKey, String code) {
initComponents(); initComponents();
authenticationKeyField.setText(authenticationKey); authenticationKeyField.setText(authenticationKey);
authenticationKeyField.getDocument().addDocumentListener(new DocumentListener() { authenticationKeyField.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
@ -284,6 +283,7 @@ public class BingTranslatorSettingsPanel extends javax.swing.JPanel {
* cancellation, a connectivity problem or timeout. * cancellation, a connectivity problem or timeout.
*/ */
private boolean testTranslationSetup() { private boolean testTranslationSetup() {
testResultValueLabel.setText("");
MediaType mediaType = MediaType.parse("application/json"); MediaType mediaType = MediaType.parse("application/json");
JsonArray jsonArray = new JsonArray(); JsonArray jsonArray = new JsonArray();
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();

View File

@ -1,5 +1,5 @@
GoogleTranslatorSettingsPanel.browseButton.text=Browse GoogleTranslatorSettingsPanel.browseButton.text=Browse
GoogleTranslatorSettingsPanel.credentialsLabel.text=Authentication key: GoogleTranslatorSettingsPanel.credentialsLabel.text=Credentials Path:
GoogleTranslatorSettingsPanel.warningLabel.text= GoogleTranslatorSettingsPanel.warningLabel.text=
GoogleTranslatorSettingsPanel.targetLanguageLabel.text=Target Language: GoogleTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
BingTranslatorSettingsPanel.testButton.text=Test BingTranslatorSettingsPanel.testButton.text=Test
@ -10,3 +10,7 @@ BingTranslatorSettingsPanel.translationSizeLabel.text=Translation Size:
BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language: BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
BingTranslatorSettingsPanel.unitsLabel.text=characters BingTranslatorSettingsPanel.unitsLabel.text=characters
BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the
GoogleTranslatorSettingsPanel.testButton.text=Test
GoogleTranslatorSettingsPanel.untranslatedLabel.text=Untranslated:
GoogleTranslatorSettingsPanel.resultLabel.text=Result:
GoogleTranslatorSettingsPanel.testResultValueLabel.text=

View File

@ -1,7 +1,7 @@
BingTranslator.name.text=Bing Translator BingTranslator.name.text=Bing Translator
GoogleTranslator.name.text=Google Translate GoogleTranslator.name.text=Google Translate
GoogleTranslatorSettingsPanel.browseButton.text=Browse GoogleTranslatorSettingsPanel.browseButton.text=Browse
GoogleTranslatorSettingsPanel.credentialsLabel.text=Authentication key: GoogleTranslatorSettingsPanel.credentialsLabel.text=Credentials Path:
GoogleTranslatorSettingsPanel.errorMessage.fileNotFound=Credentials file not found, please set the location to be a valid JSON credentials file. GoogleTranslatorSettingsPanel.errorMessage.fileNotFound=Credentials file not found, please set the location to be a valid JSON credentials file.
GoogleTranslatorSettingsPanel.errorMessage.noFileSelected=A JSON file must be selected to provide your credentials for Google Translate. GoogleTranslatorSettingsPanel.errorMessage.noFileSelected=A JSON file must be selected to provide your credentials for Google Translate.
GoogleTranslatorSettingsPanel.errorMessage.unableToMakeCredentials=Unable to construct credentials object from credentials file, please set the location to be a valid JSON credentials file. GoogleTranslatorSettingsPanel.errorMessage.unableToMakeCredentials=Unable to construct credentials object from credentials file, please set the location to be a valid JSON credentials file.
@ -20,3 +20,7 @@ BingTranslatorSettingsPanel.translationSizeLabel.text=Translation Size:
BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language: BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
BingTranslatorSettingsPanel.unitsLabel.text=characters BingTranslatorSettingsPanel.unitsLabel.text=characters
BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the
GoogleTranslatorSettingsPanel.testButton.text=Test
GoogleTranslatorSettingsPanel.untranslatedLabel.text=Untranslated:
GoogleTranslatorSettingsPanel.resultLabel.text=Result:
GoogleTranslatorSettingsPanel.testResultValueLabel.text=

View File

@ -16,13 +16,9 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="warningLabel" min="-2" pref="551" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="credentialsLabel" max="32767" attributes="0"/> <Component id="credentialsLabel" max="32767" attributes="0"/>
@ -31,7 +27,7 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="credentialsPathField" pref="443" max="32767" attributes="0"/> <Component id="credentialsPathField" pref="451" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="browseButton" min="-2" max="-2" attributes="0"/> <Component id="browseButton" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/> <EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
@ -42,6 +38,18 @@
</Group> </Group>
</Group> </Group>
</Group> </Group>
<Component id="warningLabel" min="-2" pref="551" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Component id="testButton" min="-2" pref="83" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="untranslatedLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="testUntranslatedTextField" min="-2" pref="140" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="resultLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="testResultValueLabel" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</Group> </Group>
</Group> </Group>
@ -60,9 +68,16 @@
<Component id="targetLanguageLabel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="targetLanguageLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="targetLanguageComboBox" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="targetLanguageComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace pref="15" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="testButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="testUntranslatedTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="untranslatedLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="resultLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="testResultValueLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="warningLabel" min="-2" pref="18" max="-2" attributes="0"/> <Component id="warningLabel" min="-2" pref="18" max="-2" attributes="0"/>
<EmptySpace pref="23" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -118,5 +133,43 @@
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JLabel" name="testResultValueLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.testResultValueLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="resultLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.resultLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="untranslatedLabel">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.untranslatedLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="testUntranslatedTextField">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="DEFUALT_TEST_STRING" type="code"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="testButton">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/translators/Bundle.properties" key="GoogleTranslatorSettingsPanel.testButton.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="testButtonActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -21,7 +21,9 @@ package org.sleuthkit.autopsy.texttranslation.translators;
import com.google.auth.Credentials; import com.google.auth.Credentials;
import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.translate.Language; import com.google.cloud.translate.Language;
import com.google.cloud.translate.Translate;
import com.google.cloud.translate.TranslateOptions; import com.google.cloud.translate.TranslateOptions;
import com.google.cloud.translate.Translation;
import java.awt.event.ItemListener; import java.awt.event.ItemListener;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -44,6 +46,7 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(GoogleTranslatorSettingsPanel.class.getName()); private static final Logger logger = Logger.getLogger(GoogleTranslatorSettingsPanel.class.getName());
private static final String JSON_EXTENSION = "json"; private static final String JSON_EXTENSION = "json";
private static final String DEFUALT_TEST_STRING = "traducción exitoso"; //spanish which should translate to something along the lines of "successful translation"
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final ItemListener listener = new ComboBoxSelectionListener(); private final ItemListener listener = new ComboBoxSelectionListener();
private String targetLanguageCode = ""; private String targetLanguageCode = "";
@ -60,16 +63,15 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
/** /**
* Private method to make a temporary translation service given the current * Private method to make a temporary translation service given the current
* settings and use it to retrieve the available target languages for * settings with unsaved settings.
* population of combobox with target language with unsaved settings.
* *
* @return A list of Languages * @return A Translate object which is the translation service
*/ */
@Messages({"GoogleTranslatorSettingsPanel.errorMessage.fileNotFound=Credentials file not found, please set the location to be a valid JSON credentials file.", @Messages({"GoogleTranslatorSettingsPanel.errorMessage.fileNotFound=Credentials file not found, please set the location to be a valid JSON credentials file.",
"GoogleTranslatorSettingsPanel.errorMessage.unableToReadCredentials=Unable to read credentials from credentials file, please set the location to be a valid JSON credentials file.", "GoogleTranslatorSettingsPanel.errorMessage.unableToReadCredentials=Unable to read credentials from credentials file, please set the location to be a valid JSON credentials file.",
"GoogleTranslatorSettingsPanel.errorMessage.unableToMakeCredentials=Unable to construct credentials object from credentials file, please set the location to be a valid JSON credentials file.", "GoogleTranslatorSettingsPanel.errorMessage.unableToMakeCredentials=Unable to construct credentials object from credentials file, please set the location to be a valid JSON credentials file.",
"GoogleTranslatorSettingsPanel.errorMessage.unknownFailureGetting=Failure getting list of supported languages with current credentials file.",}) "GoogleTranslatorSettingsPanel.errorMessage.unknownFailureGetting=Failure getting list of supported languages with current credentials file.",})
private List<Language> getListOfTargetLanguages() { private Translate getTemporaryTranslationService() {
//This method also has the side effect of more or less validating the JSON file which was selected as it is necessary to get the list of target languages //This method also has the side effect of more or less validating the JSON file which was selected as it is necessary to get the list of target languages
try { try {
InputStream credentialStream; InputStream credentialStream;
@ -77,31 +79,31 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
credentialStream = new FileInputStream(credentialsPathField.getText()); credentialStream = new FileInputStream(credentialsPathField.getText());
} catch (FileNotFoundException ignored) { } catch (FileNotFoundException ignored) {
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_fileNotFound()); warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_fileNotFound());
return new ArrayList<>(); return null;
} }
Credentials creds; Credentials creds;
try { try {
creds = ServiceAccountCredentials.fromStream(credentialStream); creds = ServiceAccountCredentials.fromStream(credentialStream);
} catch (IOException ignored) { } catch (IOException ignored) {
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToMakeCredentials()); warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToMakeCredentials());
return new ArrayList<>(); return null;
} }
if (creds == null) { if (creds == null) {
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToReadCredentials()); warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToReadCredentials());
logger.log(Level.WARNING, "Credentials were not successfully made, no translations will be available from the GoogleTranslator"); logger.log(Level.WARNING, "Credentials were not successfully made, no translations will be available from the GoogleTranslator");
return new ArrayList<>(); return null;
} else { } else {
TranslateOptions.Builder builder = TranslateOptions.newBuilder(); TranslateOptions.Builder builder = TranslateOptions.newBuilder();
builder.setCredentials(creds); builder.setCredentials(creds);
builder.setTargetLanguage(targetLanguageCode); //localize the list to the currently selected target language builder.setTargetLanguage(targetLanguageCode); //localize the list to the currently selected target language
warningLabel.setText(""); //clear any previous warning text warningLabel.setText(""); //clear any previous warning text
return builder.build().getService().listSupportedLanguages(); return builder.build().getService();
} }
} catch (Throwable throwable) { } catch (Throwable throwable) {
//Catching throwables because some of this Google Translate code throws throwables //Catching throwables because some of this Google Translate code throws throwables
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unknownFailureGetting()); warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unknownFailureGetting());
logger.log(Level.WARNING, "Throwable caught while getting list of supported languages", throwable); logger.log(Level.WARNING, "Throwable caught while getting list of supported languages", throwable);
return new ArrayList<>(); return null;
} }
} }
@ -114,7 +116,13 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
targetLanguageComboBox.removeItemListener(listener); targetLanguageComboBox.removeItemListener(listener);
try { try {
if (!StringUtils.isBlank(credentialsPathField.getText())) { if (!StringUtils.isBlank(credentialsPathField.getText())) {
List<Language> listSupportedLanguages = getListOfTargetLanguages(); List<Language> listSupportedLanguages;
Translate tempService = getTemporaryTranslationService();
if (tempService != null) {
listSupportedLanguages = tempService.listSupportedLanguages();
} else {
listSupportedLanguages = new ArrayList<>();
}
targetLanguageComboBox.removeAllItems(); targetLanguageComboBox.removeAllItems();
if (!listSupportedLanguages.isEmpty()) { if (!listSupportedLanguages.isEmpty()) {
listSupportedLanguages.forEach((lang) -> { listSupportedLanguages.forEach((lang) -> {
@ -167,6 +175,11 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
targetLanguageComboBox = new javax.swing.JComboBox<>(); targetLanguageComboBox = new javax.swing.JComboBox<>();
targetLanguageLabel = new javax.swing.JLabel(); targetLanguageLabel = new javax.swing.JLabel();
warningLabel = new javax.swing.JLabel(); warningLabel = new javax.swing.JLabel();
testResultValueLabel = new javax.swing.JLabel();
resultLabel = new javax.swing.JLabel();
untranslatedLabel = new javax.swing.JLabel();
testUntranslatedTextField = new javax.swing.JTextField();
testButton = new javax.swing.JButton();
org.openide.awt.Mnemonics.setLocalizedText(credentialsLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.credentialsLabel.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(credentialsLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.credentialsLabel.text")); // NOI18N
@ -186,6 +199,21 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
warningLabel.setForeground(new java.awt.Color(255, 0, 0)); warningLabel.setForeground(new java.awt.Color(255, 0, 0));
org.openide.awt.Mnemonics.setLocalizedText(warningLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.warningLabel.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(warningLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.warningLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(testResultValueLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.testResultValueLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(resultLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.resultLabel.text")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(untranslatedLabel, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.untranslatedLabel.text")); // NOI18N
testUntranslatedTextField.setText(DEFUALT_TEST_STRING);
org.openide.awt.Mnemonics.setLocalizedText(testButton, org.openide.util.NbBundle.getMessage(GoogleTranslatorSettingsPanel.class, "GoogleTranslatorSettingsPanel.testButton.text")); // NOI18N
testButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
testButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@ -193,9 +221,6 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(credentialsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(credentialsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
@ -203,13 +228,24 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(credentialsPathField, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) .addComponent(credentialsPathField, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(browseButton) .addComponent(browseButton)
.addGap(14, 14, 14)) .addGap(14, 14, 14))
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))))) .addGap(0, 0, Short.MAX_VALUE))))
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 551, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(testButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(untranslatedLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(testUntranslatedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(resultLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(testResultValueLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -223,9 +259,15 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(targetLanguageLabel) .addComponent(targetLanguageLabel)
.addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addContainerGap(23, Short.MAX_VALUE)) .addComponent(testButton)
.addComponent(testUntranslatedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(untranslatedLabel)
.addComponent(resultLabel)
.addComponent(testResultValueLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
@ -249,12 +291,31 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
} }
}//GEN-LAST:event_browseButtonActionPerformed }//GEN-LAST:event_browseButtonActionPerformed
private void testButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testButtonActionPerformed
testResultValueLabel.setText("");
Translate tempTranslate = getTemporaryTranslationService();
if (tempTranslate != null) {
try {
Translation translation = tempTranslate.translate(testUntranslatedTextField.getText());
testResultValueLabel.setText(translation.getTranslatedText());
warningLabel.setText("");
} catch (Exception ex) {
warningLabel.setText("Invalid translation credentials path");
}
}
}//GEN-LAST:event_testButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton browseButton; private javax.swing.JButton browseButton;
private javax.swing.JLabel credentialsLabel; private javax.swing.JLabel credentialsLabel;
private javax.swing.JTextField credentialsPathField; private javax.swing.JTextField credentialsPathField;
private javax.swing.JLabel resultLabel;
private javax.swing.JComboBox<org.sleuthkit.autopsy.texttranslation.translators.LanguageWrapper> targetLanguageComboBox; private javax.swing.JComboBox<org.sleuthkit.autopsy.texttranslation.translators.LanguageWrapper> targetLanguageComboBox;
private javax.swing.JLabel targetLanguageLabel; private javax.swing.JLabel targetLanguageLabel;
private javax.swing.JButton testButton;
private javax.swing.JLabel testResultValueLabel;
private javax.swing.JTextField testUntranslatedTextField;
private javax.swing.JLabel untranslatedLabel;
private javax.swing.JLabel warningLabel; private javax.swing.JLabel warningLabel;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables