mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
5061 test button added to google translate options panel
This commit is contained in:
parent
fd399e4cfb
commit
e6670f34ba
@ -16,7 +16,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.sleuthkit.autopsy.texttranslation.translators;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
@ -35,11 +34,12 @@ import org.sleuthkit.autopsy.texttranslation.TextTranslator;
|
||||
import org.sleuthkit.autopsy.texttranslation.TranslationException;
|
||||
|
||||
/**
|
||||
* Translates text by making HTTP requests to Bing Translator.
|
||||
* This requires a valid subscription key for a Microsoft Azure account.
|
||||
* Translates text by making HTTP requests to Bing Translator. This requires a
|
||||
* valid subscription key for a Microsoft Azure account.
|
||||
*/
|
||||
@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
|
||||
//languages separated by commas. A full list of supported languages is here:
|
||||
//https://docs.microsoft.com/en-us/azure/cognitive-services/translator/language-support
|
||||
@ -52,12 +52,11 @@ public class BingTranslator implements TextTranslator{
|
||||
//paid account that's willing to pay for long documents.
|
||||
private final int MAX_STRING_LENGTH = 5000;
|
||||
|
||||
|
||||
public BingTranslator(){
|
||||
public BingTranslator() {
|
||||
settingsPanel = new BingTranslatorSettingsPanel(settings.getAuthenticationKey(), settings.getTargetLanguageCode());
|
||||
}
|
||||
|
||||
static String getTranlatorUrl(String languageCode){
|
||||
static String getTranlatorUrl(String languageCode) {
|
||||
return BASE_URL + languageCode;
|
||||
}
|
||||
|
||||
@ -66,8 +65,11 @@ public class BingTranslator implements TextTranslator{
|
||||
* posts it to Microsoft, and returns the JSON text response.
|
||||
*
|
||||
* @param string The input text to be translated.
|
||||
*
|
||||
* @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 {
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
@ -79,11 +81,11 @@ public class BingTranslator implements TextTranslator{
|
||||
String bodyString = jsonArray.toString();
|
||||
|
||||
RequestBody body = RequestBody.create(mediaType,
|
||||
bodyString);
|
||||
bodyString);
|
||||
Request request = new Request.Builder()
|
||||
.url(getTranlatorUrl(settings.getTargetLanguageCode())).post(body)
|
||||
.addHeader("Ocp-Apim-Subscription-Key", settings.getAuthenticationKey())
|
||||
.addHeader("Content-type", "application/json").build();
|
||||
.url(getTranlatorUrl(settings.getTargetLanguageCode())).post(body)
|
||||
.addHeader("Ocp-Apim-Subscription-Key", settings.getAuthenticationKey())
|
||||
.addHeader("Content-type", "application/json").build();
|
||||
Response response = CLIENT.newCall(request).execute();
|
||||
return response.body().string();
|
||||
}
|
||||
@ -97,10 +99,8 @@ public class BingTranslator implements TextTranslator{
|
||||
//Translates some text into English, without specifying the source langauge.
|
||||
|
||||
// HTML files were producing lots of white space at the end
|
||||
|
||||
//Google Translate required us to replace (\r\n|\n) with <br />
|
||||
//but Bing Translator doesn not have that requirement.
|
||||
|
||||
//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
|
||||
//translating very large documents.
|
||||
@ -131,26 +131,15 @@ public class BingTranslator implements TextTranslator{
|
||||
public void saveSettings() {
|
||||
settings.setAuthenticationKey(settingsPanel.getAuthenticationKey());
|
||||
settings.setTargetLanguageCode(settingsPanel.getTargetLanguageCode());
|
||||
settings.saveSettings();
|
||||
}
|
||||
|
||||
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:
|
||||
[
|
||||
{
|
||||
"detectedLanguage": {
|
||||
"language": "es",
|
||||
"score": 1.0
|
||||
},
|
||||
"translations": [
|
||||
{
|
||||
"text": "cat",
|
||||
"to": "en"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
*/
|
||||
/*
|
||||
* 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" } ] } ]
|
||||
*/
|
||||
JsonParser parser = new JsonParser();
|
||||
try {
|
||||
JsonArray responses = parser.parse(json_text).getAsJsonArray();
|
||||
|
@ -51,7 +51,6 @@ public class BingTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
*/
|
||||
public BingTranslatorSettingsPanel(String authenticationKey, String code) {
|
||||
initComponents();
|
||||
|
||||
authenticationKeyField.setText(authenticationKey);
|
||||
authenticationKeyField.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
@ -284,6 +283,7 @@ public class BingTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
* cancellation, a connectivity problem or timeout.
|
||||
*/
|
||||
private boolean testTranslationSetup() {
|
||||
testResultValueLabel.setText("");
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
@ -1,5 +1,5 @@
|
||||
GoogleTranslatorSettingsPanel.browseButton.text=Browse
|
||||
GoogleTranslatorSettingsPanel.credentialsLabel.text=Authentication key:
|
||||
GoogleTranslatorSettingsPanel.credentialsLabel.text=Credentials Path:
|
||||
GoogleTranslatorSettingsPanel.warningLabel.text=
|
||||
GoogleTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
|
||||
BingTranslatorSettingsPanel.testButton.text=Test
|
||||
@ -10,3 +10,7 @@ BingTranslatorSettingsPanel.translationSizeLabel.text=Translation Size:
|
||||
BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
|
||||
BingTranslatorSettingsPanel.unitsLabel.text=characters
|
||||
BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the
|
||||
GoogleTranslatorSettingsPanel.testButton.text=Test
|
||||
GoogleTranslatorSettingsPanel.untranslatedLabel.text=Untranslated:
|
||||
GoogleTranslatorSettingsPanel.resultLabel.text=Result:
|
||||
GoogleTranslatorSettingsPanel.testResultValueLabel.text=
|
||||
|
@ -1,7 +1,7 @@
|
||||
BingTranslator.name.text=Bing Translator
|
||||
GoogleTranslator.name.text=Google Translate
|
||||
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.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.
|
||||
@ -20,3 +20,7 @@ BingTranslatorSettingsPanel.translationSizeLabel.text=Translation Size:
|
||||
BingTranslatorSettingsPanel.targetLanguageLabel.text=Target Language:
|
||||
BingTranslatorSettingsPanel.unitsLabel.text=characters
|
||||
BingTranslatorSettingsPanel.authenticationKeyField.toolTipText=Enter the hash for the
|
||||
GoogleTranslatorSettingsPanel.testButton.text=Test
|
||||
GoogleTranslatorSettingsPanel.untranslatedLabel.text=Untranslated:
|
||||
GoogleTranslatorSettingsPanel.resultLabel.text=Result:
|
||||
GoogleTranslatorSettingsPanel.testResultValueLabel.text=
|
||||
|
@ -16,13 +16,9 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="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"/>
|
||||
<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="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="credentialsLabel" max="32767" attributes="0"/>
|
||||
@ -31,7 +27,7 @@
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" 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"/>
|
||||
<Component id="browseButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
|
||||
@ -42,6 +38,18 @@
|
||||
</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>
|
||||
@ -60,9 +68,16 @@
|
||||
<Component id="targetLanguageLabel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="targetLanguageComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</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"/>
|
||||
<EmptySpace pref="23" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
@ -118,5 +133,43 @@
|
||||
</Property>
|
||||
</Properties>
|
||||
</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, "{key}")"/>
|
||||
</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, "{key}")"/>
|
||||
</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, "{key}")"/>
|
||||
</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, "{key}")"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="testButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
@ -21,7 +21,9 @@ package org.sleuthkit.autopsy.texttranslation.translators;
|
||||
import com.google.auth.Credentials;
|
||||
import com.google.auth.oauth2.ServiceAccountCredentials;
|
||||
import com.google.cloud.translate.Language;
|
||||
import com.google.cloud.translate.Translate;
|
||||
import com.google.cloud.translate.TranslateOptions;
|
||||
import com.google.cloud.translate.Translation;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.io.File;
|
||||
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 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 final ItemListener listener = new ComboBoxSelectionListener();
|
||||
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
|
||||
* settings and use it to retrieve the available target languages for
|
||||
* population of combobox with target language with unsaved settings.
|
||||
* settings 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.",
|
||||
"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.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
|
||||
try {
|
||||
InputStream credentialStream;
|
||||
@ -77,31 +79,31 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
credentialStream = new FileInputStream(credentialsPathField.getText());
|
||||
} catch (FileNotFoundException ignored) {
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_fileNotFound());
|
||||
return new ArrayList<>();
|
||||
return null;
|
||||
}
|
||||
Credentials creds;
|
||||
try {
|
||||
creds = ServiceAccountCredentials.fromStream(credentialStream);
|
||||
} catch (IOException ignored) {
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToMakeCredentials());
|
||||
return new ArrayList<>();
|
||||
return null;
|
||||
}
|
||||
if (creds == null) {
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unableToReadCredentials());
|
||||
logger.log(Level.WARNING, "Credentials were not successfully made, no translations will be available from the GoogleTranslator");
|
||||
return new ArrayList<>();
|
||||
return null;
|
||||
} else {
|
||||
TranslateOptions.Builder builder = TranslateOptions.newBuilder();
|
||||
builder.setCredentials(creds);
|
||||
builder.setTargetLanguage(targetLanguageCode); //localize the list to the currently selected target language
|
||||
warningLabel.setText(""); //clear any previous warning text
|
||||
return builder.build().getService().listSupportedLanguages();
|
||||
return builder.build().getService();
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
//Catching throwables because some of this Google Translate code throws throwables
|
||||
warningLabel.setText(Bundle.GoogleTranslatorSettingsPanel_errorMessage_unknownFailureGetting());
|
||||
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);
|
||||
try {
|
||||
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();
|
||||
if (!listSupportedLanguages.isEmpty()) {
|
||||
listSupportedLanguages.forEach((lang) -> {
|
||||
@ -167,6 +175,11 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
targetLanguageComboBox = new javax.swing.JComboBox<>();
|
||||
targetLanguageLabel = 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
|
||||
|
||||
@ -186,6 +199,21 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
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(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);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@ -193,9 +221,6 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.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)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.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)
|
||||
.addComponent(browseButton)
|
||||
.addGap(14, 14, 14))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.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.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)
|
||||
.addComponent(targetLanguageLabel)
|
||||
.addComponent(targetLanguageComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(warningLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(23, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.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
|
||||
|
||||
@ -249,12 +291,31 @@ public class GoogleTranslatorSettingsPanel extends javax.swing.JPanel {
|
||||
}
|
||||
}//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
|
||||
private javax.swing.JButton browseButton;
|
||||
private javax.swing.JLabel credentialsLabel;
|
||||
private javax.swing.JTextField credentialsPathField;
|
||||
private javax.swing.JLabel resultLabel;
|
||||
private javax.swing.JComboBox<org.sleuthkit.autopsy.texttranslation.translators.LanguageWrapper> targetLanguageComboBox;
|
||||
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;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user