4989 options panel listens for changes in texttranslator panels

This commit is contained in:
William Schaefer 2019-05-07 10:28:12 -04:00
parent 573b4ced9e
commit 0e367e7a1f
7 changed files with 85 additions and 80 deletions

View File

@ -45,11 +45,8 @@ public final class TextTranslationService {
} }
public void setSelectedTranslator(String translatorName) throws NoServiceProviderException { public void setSelectedTranslator(String translatorName) throws NoServiceProviderException {
System.out.println("Translator name: " + translatorName);
for (TextTranslator translator : translators) { for (TextTranslator translator : translators) {
System.out.println("Is it named: " + translator.getName());
if (translator.getName().equals(translatorName)) { if (translator.getName().equals(translatorName)) {
System.out.println("THEY ARE EQUAL");
selectedTranslator = translator; selectedTranslator = translator;
return; return;
} }

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2018-2018 Basis Technology Corp. * Copyright 2018-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -3,13 +3,6 @@ OptionsCategory_Keywords_Machine_Translation_Settings=Machine Translation Settin
TranslationContentPanel.ShowLabel.text=Show: TranslationContentPanel.ShowLabel.text=Show:
TranslationContentPanel.warningLabel2MB.text=Only the first 1MB of text will be displayed TranslationContentPanel.warningLabel2MB.text=Only the first 1MB of text will be displayed
TranslationContentPanel.ocrLabel.text=OCR: TranslationContentPanel.ocrLabel.text=OCR:
TranslationSettingsPanel.lbIpAddress.text=IP Address or Hostname of Machine Translation Service TranslationOptionsPanel.translationServiceLabel.text=Translation Service:
TranslationSettingsPanel.tbIpAddress.text= TranslationOptionsPanelController.moduleErr=Module Error
TranslationSettingsPanel.tbOops.text= TranslationOptionsPanelController.moduleErr.msg=A module caused an error listening to TranslationSettingsPanelController updates. See log to determine which module. Some data could be incomplete.
TranslationSettingsPanel.bnTest.text=Test
TranslationSettingsPanel.lbTestIpAddress.text=
TranslationSettingsPanel.IpAddress.toolTipText=IP Address or Hostname of Machine Translation Service
TranslationSettingsPanel.IpAddress.CannotConnect=Cannot connect to machine translation service.
TranslationSettingsPanelController.moduleErr=Module Error
TranslationSettingsPanelController.moduleErr.msg=A module caused an error listening to TranslationSettingsPanelController updates. See log to determine which module. Some data could be incomplete.
TranslationOptionsPanel.jLabel1.text=Translation Service:

View File

@ -27,4 +27,4 @@ TranslationSettingsPanel.IpAddress.toolTipText=IP Address or Hostname of Machine
TranslationSettingsPanel.IpAddress.CannotConnect=Cannot connect to machine translation service. TranslationSettingsPanel.IpAddress.CannotConnect=Cannot connect to machine translation service.
TranslationSettingsPanelController.moduleErr=Module Error TranslationSettingsPanelController.moduleErr=Module Error
TranslationSettingsPanelController.moduleErr.msg=A module caused an error listening to TranslationSettingsPanelController updates. See log to determine which module. Some data could be incomplete. TranslationSettingsPanelController.moduleErr.msg=A module caused an error listening to TranslationSettingsPanelController updates. See log to determine which module. Some data could be incomplete.
TranslationOptionsPanel.jLabel1.text=Translation Service: TranslationOptionsPanel.translationServiceLabel.text=Translation Service:

View File

@ -20,12 +20,12 @@
<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" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/> <Component id="translationServiceLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jComboBox1" min="-2" pref="205" max="-2" attributes="0"/> <Component id="translatorComboBox" min="-2" pref="205" max="-2" attributes="0"/>
<EmptySpace min="0" pref="152" max="32767" attributes="0"/> <EmptySpace min="0" pref="152" max="32767" attributes="0"/>
</Group> </Group>
<Component id="jPanel1" alignment="1" max="32767" attributes="0"/> <Component id="translationServicePanel" alignment="1" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -36,33 +36,33 @@
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="jComboBox1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="translatorComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="translationServiceLabel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" pref="222" max="32767" attributes="0"/> <Component id="translationServicePanel" pref="222" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JComboBox" name="jComboBox1"> <Component class="javax.swing.JComboBox" name="translatorComboBox">
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBox1ActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="translatorComboBoxActionPerformed"/>
</Events> </Events>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/> <AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues> </AuxValues>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel1"> <Component class="javax.swing.JLabel" name="translationServiceLabel">
<Properties> <Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor"> <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/sleuthkit/autopsy/texttranslation/ui/Bundle.properties" key="TranslationOptionsPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/> <ResourceString bundle="org/sleuthkit/autopsy/texttranslation/ui/Bundle.properties" key="TranslationOptionsPanel.translationServiceLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property> </Property>
</Properties> </Properties>
</Component> </Component>
<Container class="javax.swing.JPanel" name="jPanel1"> <Container class="javax.swing.JPanel" name="translationServicePanel">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
</Container> </Container>

View File

@ -1,66 +1,81 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * Autopsy Forensic Browser
* To change this template file, choose Tools | Templates *
* and open the template in the editor. * Copyright 2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ */
package org.sleuthkit.autopsy.texttranslation.ui; package org.sleuthkit.autopsy.texttranslation.ui;
import java.awt.Component;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JLabel; import javax.swing.JLabel;
import org.sleuthkit.autopsy.texttranslation.NoServiceProviderException; import org.sleuthkit.autopsy.texttranslation.NoServiceProviderException;
import org.sleuthkit.autopsy.texttranslation.TextTranslationService; import org.sleuthkit.autopsy.texttranslation.TextTranslationService;
/**
*
* @author wschaefer
*/
public class TranslationOptionsPanel extends javax.swing.JPanel { public class TranslationOptionsPanel extends javax.swing.JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final TranslationSettingsPanelController controller; private final TranslationOptionsPanelController controller;
private String currentSelection = "";
/** /**
* Creates new form TranslationOptionsPanel * Creates new form TranslationOptionsPanel
*/ */
public TranslationOptionsPanel(TranslationSettingsPanelController theController) { public TranslationOptionsPanel(TranslationOptionsPanelController theController) {
initComponents(); initComponents();
controller = theController; controller = theController;
TextTranslationService.getInstance().getTranslators().forEach((translator) -> { TextTranslationService.getInstance().getTranslators().forEach((translator) -> {
jComboBox1.addItem(translator.getName()); translatorComboBox.addItem(translator.getName());
}); });
jComboBox1.setEnabled(jComboBox1.getItemCount() > 0); translatorComboBox.setEnabled(translatorComboBox.getItemCount() > 0);
updatePanel(); updatePanel();
} }
private void updatePanel() { private void updatePanel() {
System.out.println("Update panel"); translationServicePanel.removeAll();
jPanel1.removeAll(); String selectedItem = translatorComboBox.getSelectedItem().toString();
if (jComboBox1.getSelectedItem() != null) { if (translatorComboBox.getSelectedItem() != null && !currentSelection.equals(selectedItem)) {
try { try {
System.out.println("Item Selected"); TextTranslationService.getInstance().setSelectedTranslator(translatorComboBox.getSelectedItem().toString());
TextTranslationService.getInstance().setSelectedTranslator(jComboBox1.getSelectedItem().toString()); Component panel = TextTranslationService.getInstance().getSelectedTranslator().getComponent();
jPanel1.add(TextTranslationService.getInstance().getSelectedTranslator().getComponent()); panel.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
controller.changed();
}
});
translationServicePanel.add(panel);
currentSelection = selectedItem;
} catch (NoServiceProviderException ex) { } catch (NoServiceProviderException ex) {
System.out.println(ex.getMessage()); translationServicePanel.add(new JLabel("No Text Translators available"));
jPanel1.add(new JLabel("No Text Translators available"));
} }
} else { } else {
jPanel1.add(new JLabel("No Translators selected")); translationServicePanel.add(new JLabel("No Translators selected"));
} }
revalidate();
repaint();
} }
void load() { void load() {
updatePanel(); updatePanel();
// lbTestIpAddress.setIcon(null);
// tbOops.setText("");
//// tbIpAddress.setText(getMachineTranslationIpAddress());
// handleButtons();
controller.changed(); controller.changed();
} }
void store() { void store() {
// setMachineTranslationIpAddress(tbIpAddress.getText());
} }
/** /**
@ -72,19 +87,19 @@ public class TranslationOptionsPanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
jComboBox1 = new javax.swing.JComboBox<>(); translatorComboBox = new javax.swing.JComboBox<>();
jLabel1 = new javax.swing.JLabel(); translationServiceLabel = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel(); translationServicePanel = new javax.swing.JPanel();
jComboBox1.addActionListener(new java.awt.event.ActionListener() { translatorComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt); translatorComboBoxActionPerformed(evt);
} }
}); });
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(TranslationOptionsPanel.class, "TranslationOptionsPanel.jLabel1.text")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(translationServiceLabel, org.openide.util.NbBundle.getMessage(TranslationOptionsPanel.class, "TranslationOptionsPanel.translationServiceLabel.text")); // NOI18N
jPanel1.setLayout(new java.awt.BorderLayout()); translationServicePanel.setLayout(new java.awt.BorderLayout());
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
@ -94,11 +109,11 @@ public class TranslationOptionsPanel extends javax.swing.JPanel {
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jLabel1) .addComponent(translationServiceLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(translatorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 152, Short.MAX_VALUE)) .addGap(0, 152, Short.MAX_VALUE))
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(translationServicePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
@ -106,23 +121,23 @@ public class TranslationOptionsPanel extends javax.swing.JPanel {
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(translatorComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)) .addComponent(translationServiceLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE) .addComponent(translationServicePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
.addContainerGap()) .addContainerGap())
); );
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed private void translatorComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_translatorComboBoxActionPerformed
updatePanel(); updatePanel();
}//GEN-LAST:event_jComboBox1ActionPerformed }//GEN-LAST:event_translatorComboBoxActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox<String> jComboBox1; private javax.swing.JLabel translationServiceLabel;
private javax.swing.JLabel jLabel1; private javax.swing.JPanel translationServicePanel;
private javax.swing.JPanel jPanel1; private javax.swing.JComboBox<String> translatorComboBox;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@ -34,12 +34,12 @@ import org.sleuthkit.autopsy.coreutils.Logger;
position = 7, position = 7,
keywords = "#OptionsCategory_Keywords_Machine_Translation_Settings", keywords = "#OptionsCategory_Keywords_Machine_Translation_Settings",
keywordsCategory = "Machine Translation") keywordsCategory = "Machine Translation")
public class TranslationSettingsPanelController extends OptionsPanelController { public class TranslationOptionsPanelController extends OptionsPanelController {
private TranslationOptionsPanel panel; private static final Logger logger = Logger.getLogger(TranslationOptionsPanelController.class.getName());
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private boolean changed; private boolean changed;
private static final Logger logger = Logger.getLogger(TranslationSettingsPanelController.class.getName()); private TranslationOptionsPanel panel;
@Override @Override
public void update() { public void update() {
@ -109,10 +109,10 @@ public class TranslationSettingsPanelController extends OptionsPanelController {
try { try {
pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true); pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "TranslationSettingsPanelController listener threw exception", e); //NON-NLS logger.log(Level.SEVERE, "TranslationOptionsPanelController listener threw exception", e); //NON-NLS
MessageNotifyUtil.Notify.show( MessageNotifyUtil.Notify.show(
NbBundle.getMessage(this.getClass(), "TranslationSettingsPanelController.moduleErr"), NbBundle.getMessage(this.getClass(), "TranslationOptionsPanelController.moduleErr"),
NbBundle.getMessage(this.getClass(), "TranslationSettingsPanelController.moduleErr.msg"), NbBundle.getMessage(this.getClass(), "TranslationOptionsPanelController.moduleErr.msg"),
MessageNotifyUtil.MessageType.ERROR); MessageNotifyUtil.MessageType.ERROR);
} }
} }
@ -120,10 +120,10 @@ public class TranslationSettingsPanelController extends OptionsPanelController {
try { try {
pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null); pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "TranslationSettingsPanelController listener threw exception", e); //NON-NLS logger.log(Level.SEVERE, "TranslationOptionsPanelController listener threw exception", e); //NON-NLS
MessageNotifyUtil.Notify.show( MessageNotifyUtil.Notify.show(
NbBundle.getMessage(this.getClass(), "TranslationSettingsPanelController.moduleErr"), NbBundle.getMessage(this.getClass(), "TranslationOptionsPanelController.moduleErr"),
NbBundle.getMessage(this.getClass(), "TranslationSettingsPanelController.moduleErr.msg"), NbBundle.getMessage(this.getClass(), "TranslationOptionsPanelController.moduleErr.msg"),
MessageNotifyUtil.MessageType.ERROR); MessageNotifyUtil.MessageType.ERROR);
} }
} }