Skip to content

Commit

Permalink
added actions to sound player panel. close #2600
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Oct 3, 2024
1 parent 5b32b02 commit 4779539
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public static JComponent getDocumentViewer(ArchiveFileBean caseDto, String id, S
}
return ptp;
} else if (lFileName.endsWith(".wav") || lFileName.endsWith(".ogg") || lFileName.endsWith(".mp3")) {
SoundplayerPanel spp=new SoundplayerPanel(id, readOnly);
SoundplayerPanel spp=new SoundplayerPanel(id, readOnly, saveCallback);
spp.setSize(new Dimension(width, height));
spp.setMaximumSize(new Dimension(width, height));
spp.setPreferredSize(new Dimension(width, height));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@
</Group>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="cmdPlayPause" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cmdStop" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="cmdAssistant" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="cmdPlayPause" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cmdStop" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="cmdAssistant" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="cmdNewDocument" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cmdCopy" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand All @@ -68,7 +70,13 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cmdAssistant" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="cmdAssistant" min="-2" max="-2" attributes="0"/>
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="cmdCopy" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cmdNewDocument" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="214" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -160,5 +168,27 @@
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="cmdNewDocument">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/edit.png"/>
</Property>
<Property name="text" type="java.lang.String" value="neues Dokument"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdNewDocumentActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="cmdCopy">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons16/editpaste.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Kopieren"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cmdCopyActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,15 @@
import com.jdimension.jlawyer.client.assistant.AssistantFlowAdapter;
import com.jdimension.jlawyer.client.assistant.AssistantInputAdapter;
import com.jdimension.jlawyer.client.editors.EditorsRegistry;
import com.jdimension.jlawyer.client.editors.files.EditArchiveFileDetailsPanel;
import com.jdimension.jlawyer.client.settings.ClientSettings;
import com.jdimension.jlawyer.client.utils.ThreadUtils;
import com.jdimension.jlawyer.client.utils.WavAudioUtils;
import com.jdimension.jlawyer.persistence.AssistantConfig;
import com.jdimension.jlawyer.services.JLawyerServiceLocator;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
Expand All @@ -704,22 +708,27 @@ public class SoundplayerPanel extends javax.swing.JPanel implements PreviewPanel
private static final Logger log = Logger.getLogger(SoundplayerPanel.class.getName());

private String documentId = null;
private byte[] content=null;
private byte[] content = null;
private String initialComment = null;

private Clip clip;
private Timer timer;

private boolean readOnly = true;

private DocumentPreviewSaveCallback saveCallback = null;

/**
* Creates new form SoundplayerPanel
*
* @param docId
* @param readOnly
* @param saveCallback
*/
public SoundplayerPanel(String docId, boolean readOnly) {
public SoundplayerPanel(String docId, boolean readOnly, DocumentPreviewSaveCallback saveCallback) {
this.documentId = docId;
this.readOnly = readOnly;
this.saveCallback = saveCallback;
initComponents();
}

Expand All @@ -742,6 +751,8 @@ private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
jScrollPane1 = new javax.swing.JScrollPane();
taTranscription = new javax.swing.JTextArea();
cmdNewDocument = new javax.swing.JButton();
cmdCopy = new javax.swing.JButton();

cmdPlayPause.setFont(cmdPlayPause.getFont());
cmdPlayPause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons32/material/baseline_play_circle_black_48dp.png"))); // NOI18N
Expand Down Expand Up @@ -780,6 +791,22 @@ public void mouseReleased(java.awt.event.MouseEvent evt) {
taTranscription.setRows(5);
jScrollPane1.setViewportView(taTranscription);

cmdNewDocument.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/edit.png"))); // NOI18N
cmdNewDocument.setText("neues Dokument");
cmdNewDocument.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdNewDocumentActionPerformed(evt);
}
});

cmdCopy.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons16/editpaste.png"))); // NOI18N
cmdCopy.setText("Kopieren");
cmdCopy.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmdCopyActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -795,13 +822,16 @@ public void mouseReleased(java.awt.event.MouseEvent evt) {
.addGap(34, 34, 34))
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cmdPlayPause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdStop))
.addComponent(cmdAssistant))
.addGap(0, 0, Short.MAX_VALUE)))
.addComponent(cmdPlayPause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdStop)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(cmdAssistant)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmdNewDocument)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdCopy)))
.addContainerGap())
);
layout.setVerticalGroup(
Expand All @@ -820,7 +850,11 @@ public void mouseReleased(java.awt.event.MouseEvent evt) {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmdAssistant)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cmdAssistant)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmdCopy)
.addComponent(cmdNewDocument)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
.addContainerGap())
Expand All @@ -836,22 +870,41 @@ private void cmdStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST
}//GEN-LAST:event_cmdStopActionPerformed

private void cmdAssistantMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cmdAssistantMouseReleased
AssistantAccess ingo=AssistantAccess.getInstance();
AssistantAccess ingo = AssistantAccess.getInstance();
try {
Map<AssistantConfig,List<AiCapability>> capabilities=ingo.filterCapabilities(AiCapability.REQUESTTYPE_TRANSCRIBE, AiCapability.INPUTTYPE_FILE);
Map<AssistantConfig, List<AiCapability>> capabilities = ingo.filterCapabilities(AiCapability.REQUESTTYPE_TRANSCRIBE, AiCapability.INPUTTYPE_FILE);
this.popAssistant.removeAll();
//ingo.populateMenu(this.popAssistant, capabilities, this);
ingo.populateMenu(this.popAssistant, capabilities, (AssistantInputAdapter)this, null);
ingo.populateMenu(this.popAssistant, capabilities, (AssistantInputAdapter) this, null);
this.popAssistant.show(this.cmdAssistant, evt.getX(), evt.getY());
} catch (Exception ex) {
log.error(ex);
JOptionPane.showMessageDialog(this, "" + ex.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR, JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_cmdAssistantMouseReleased

private void cmdNewDocumentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdNewDocumentActionPerformed
if (this.saveCallback != null) {
if (this.saveCallback instanceof EditArchiveFileDetailsPanel) {
((EditArchiveFileDetailsPanel) this.saveCallback).newDocumentDialog(null, null, null, null, null, null, this.taTranscription.getText());
}
}
}//GEN-LAST:event_cmdNewDocumentActionPerformed

private void cmdCopyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCopyActionPerformed

Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(this.taTranscription.getText());
clipboard.setContents(strSel, null);

}//GEN-LAST:event_cmdCopyActionPerformed


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cmdAssistant;
private javax.swing.JButton cmdCopy;
private javax.swing.JButton cmdNewDocument;
private javax.swing.JButton cmdPlayPause;
private javax.swing.JButton cmdStop;
private javax.swing.JScrollPane jScrollPane1;
Expand All @@ -872,19 +925,19 @@ public void showStatus(String text) {
public void removeNotify() {
super.removeNotify();
stop(); // Stop the sound when the panel is removed or no longer displayed

if (this.documentId != null && !this.readOnly) {

String currentComment = this.taTranscription.getText();
if (currentComment!=null && !currentComment.equals(this.initialComment)) {
if (currentComment != null && !currentComment.equals(this.initialComment)) {
try {
byte[] newWav=WavAudioUtils.addOrUpdateCommentInWav(this.content, this.taTranscription.getText());

byte[] newWav = WavAudioUtils.addOrUpdateCommentInWav(this.content, this.taTranscription.getText());

ClientSettings settings = ClientSettings.getInstance();
JLawyerServiceLocator locator = JLawyerServiceLocator.getInstance(settings.getLookupProperties());
locator.lookupArchiveFileServiceRemote().setDocumentContent(this.documentId, newWav);
this.content=newWav;
this.content = newWav;
} catch (Throwable t) {
log.error("Error saving document with id " + this.documentId, t);
ThreadUtils.showErrorDialog(EditorsRegistry.getInstance().getMainWindow(), "Fehler beim Speichern: " + t.getMessage(), com.jdimension.jlawyer.client.utils.DesktopUtils.POPUP_TITLE_ERROR);
Expand All @@ -897,23 +950,23 @@ public void removeNotify() {
@Override
public void showContent(String documentId, byte[] content) {
this.documentId = documentId;
this.content=content;
this.initialComment=WavAudioUtils.getInfoChunk(this.content);
if(this.initialComment!=null) {
this.initialComment=this.initialComment.replace("ICMT: ", "");
this.content = content;

this.initialComment = WavAudioUtils.getInfoChunk(this.content);
if (this.initialComment != null) {
this.initialComment = this.initialComment.replace("ICMT: ", "");
this.taTranscription.setText(this.initialComment);
} else {
this.taTranscription.setText("");
}

try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(content));
clip = AudioSystem.getClip();
clip.open(audioInputStream);

clip.addLineListener((LineEvent event) -> {
if (event.getType() == LineEvent.Type.STOP && (clip.getMicrosecondPosition()==clip.getMicrosecondLength())) {
if (event.getType() == LineEvent.Type.STOP && (clip.getMicrosecondPosition() == clip.getMicrosecondLength())) {
clip.setMicrosecondPosition(0);
timer.stop();
updateTimeLabel();
Expand Down Expand Up @@ -983,14 +1036,14 @@ public String getPrompt(AiCapability c) {

@Override
public List<ParameterData> getParameters(AiCapability c) {

return null;
}

@Override
public List<InputData> getInputs(AiCapability c) {
ArrayList<InputData> inputs=new ArrayList<>();
InputData i=new InputData();
ArrayList<InputData> inputs = new ArrayList<>();
InputData i = new InputData();
i.setFileName("Sounddatei.wav");
i.setType("file");
i.setBase64(true);
Expand All @@ -1002,11 +1055,12 @@ public List<InputData> getInputs(AiCapability c) {
@Override
public void processOutput(AiCapability c, AiRequestStatus status) {
status.getResponse();
StringBuilder result=new StringBuilder();
for(OutputData o: status.getResponse().getOutputData()) {
if(o.getType().equalsIgnoreCase(OutputData.TYPE_STRING))
StringBuilder result = new StringBuilder();
for (OutputData o : status.getResponse().getOutputData()) {
if (o.getType().equalsIgnoreCase(OutputData.TYPE_STRING)) {
result.append(o.getStringData()).append(System.lineSeparator()).append(System.lineSeparator());

}

}
taTranscription.setText(result.toString());
}
Expand Down

0 comments on commit 4779539

Please sign in to comment.