Skip to content

Commit

Permalink
#471: attempt number one
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed Apr 27, 2024
1 parent 8d4b18e commit 599bd1a
Show file tree
Hide file tree
Showing 17 changed files with 270 additions and 47 deletions.
46 changes: 22 additions & 24 deletions src/org/exmaralda/coma/actions/SegmentTranscriptionAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.exmaralda.common.dialogs.ProgressBarDialog;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.xpath.XPath;

/**
Expand All @@ -37,10 +38,9 @@ public class SegmentTranscriptionAction extends
ComaAction {

ProgressBarDialog pbd;
SegmentationOptionsDialog dialog = new SegmentationOptionsDialog(this.coma,
true);
SegmentationOptionsDialog dialog = new SegmentationOptionsDialog(this.coma, true);
Vector<File> basicTr;
HashSet<File> existingSegs = new HashSet<File>();
HashSet<File> existingSegs = new HashSet<>();
Hashtable<File, Element> basicTr2Communication;
Document comaDocument;

Expand All @@ -52,16 +52,14 @@ public SegmentTranscriptionAction(String text, ImageIcon icon, Coma c) {
public void actionPerformed(ActionEvent e) {
final File file = coma.getData().getOpenFile();
if (file == null) {
JOptionPane.showMessageDialog(coma,
Ui.getText("err.noCorpusLoaded"));
return;
JOptionPane.showMessageDialog(coma, Ui.getText("err.noCorpusLoaded"));
return;
}

dialog.setLocationRelativeTo(this.coma);
dialog.setVisible(true);

if (!dialog.approved)
return;
if (!dialog.approved) return;

comaDocument = coma.getData().getDocument();
String CORPUS_BASEDIRECTORY = coma.getData().getOpenFile().getParent();
Expand All @@ -72,24 +70,24 @@ public void actionPerformed(ActionEvent e) {
basicTr2Communication = new Hashtable<File, Element>();

try {
basicTransNSLinks = XPath.newInstance(
AbstractCorpusProcessor.BASIC_FILE_XPATH).selectNodes(
comaDocument);
segmentedTransNSLinks = XPath.newInstance(
AbstractCorpusProcessor.SEGMENTED_FILE_XPATH).selectNodes(
comaDocument);
} catch (Exception ex) {
ex.printStackTrace();
basicTransNSLinks = XPath.newInstance(
AbstractCorpusProcessor.BASIC_FILE_XPATH).selectNodes(
comaDocument);
segmentedTransNSLinks = XPath.newInstance(
AbstractCorpusProcessor.SEGMENTED_FILE_XPATH).selectNodes(
comaDocument);
} catch (JDOMException ex) {
ex.printStackTrace();
}
for (Object o : basicTransNSLinks) {
Element nslink = (Element) (o);
String fullTranscriptionName = CORPUS_BASEDIRECTORY
+ System.getProperty("file.separator", "/")
+ nslink.getText();
File transcriptionFile = new File(fullTranscriptionName);
basicTr.add(transcriptionFile);
basicTr2Communication.put(transcriptionFile, nslink
.getParentElement().getParentElement());
Element nslink = (Element) (o);
String fullTranscriptionName = CORPUS_BASEDIRECTORY
+ System.getProperty("file.separator", "/")
+ nslink.getText();
File transcriptionFile = new File(fullTranscriptionName);
basicTr.add(transcriptionFile);
basicTr2Communication.put(transcriptionFile, nslink
.getParentElement().getParentElement());
}
for (Object o : segmentedTransNSLinks) {
Element nslink = (Element) (o);
Expand Down
3 changes: 2 additions & 1 deletion src/org/exmaralda/coma/helpers/SegmentationOptionsPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<Component class="javax.swing.JComboBox" name="segSelector">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="9">
<StringArray count="10">
<StringItem index="0" value="default"/>
<StringItem index="1" value="HIAT"/>
<StringItem index="2" value="DIDA"/>
Expand All @@ -108,6 +108,7 @@
<StringItem index="6" value="GENERIC"/>
<StringItem index="7" value="cGAT_MINIMAL"/>
<StringItem index="8" value="CHAT_MINIMAL"/>
<StringItem index="9" value="INEL_EVENT_BASED"/>
</StringArray>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
algorithmPanel.setAlignmentX(0.0F);
algorithmPanel.setLayout(new java.awt.BorderLayout());

segSelector.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "default", "HIAT", "DIDA", "CHAT", "GAT", "IPA", "GENERIC", "cGAT_MINIMAL", "CHAT_MINIMAL" }));
segSelector.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "default", "HIAT", "DIDA", "GAT", "CHAT", "IPA", "GENERIC", "cGAT_MINIMAL", "CHAT_MINIMAL", "INEL_EVENT_BASED" }));
segSelector.setMaximumSize(new java.awt.Dimension(300, 20));
segSelector.setPreferredSize(new java.awt.Dimension(200, 20));
algorithmPanel.add(segSelector, java.awt.BorderLayout.NORTH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void augmentCommonTimeline(){
}
}

/** returns a hashtable where each tli is assigned the nearest tli on the common timeline */
/** returns a hashtable where each tli is assigned the nearest tli on the common timeline
* @return */
public Hashtable makeTLIHashtable(){
Hashtable result = new Hashtable();
for (int pos=0; pos<getCommonTimeline().getNumberOfTimelineItems(); pos++){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class InelEventBasedSegmentation extends AbstractSegmentation {

@Override
public Vector getSegmentationErrors(BasicTranscription bt) throws SAXException {
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
// just return empty for now
return new Vector();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<characters>
<character>(</character> <!-- opening round parenthesis -->
<character>)</character> <!-- closing round parenthesis -->
<character>[</character> <!-- opening square bracket -->
<character>]</character> <!-- closing square bracket -->
<character> </character> <!-- space -->
<character>…</character> <!-- ellipsis (one symbol) -->
<character>.</character> <!-- period -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
</Constraints>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="2"/>
<Property name="rows" type="int" value="4"/>
<Property name="columns" type="int" value="3"/>
<Property name="rows" type="int" value="3"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JRadioButton" name="jRadioButton7">
Expand Down Expand Up @@ -140,6 +140,14 @@
<Property name="text" type="java.lang.String" value="CHAT_MINIMAL"/>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="jRadioButton9">
<Properties>
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
<ComponentRef name="buttonGroup1"/>
</Property>
<Property name="text" type="java.lang.String" value="INEL_EVENT_BASED"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="customFSMPanel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private void initComponents() {
jRadioButton5 = new javax.swing.JRadioButton();
jRadioButton6 = new javax.swing.JRadioButton();
jRadioButton8 = new javax.swing.JRadioButton();
jRadioButton9 = new javax.swing.JRadioButton();
customFSMPanel = new javax.swing.JPanel();
customFSMTextField = new javax.swing.JTextField();
customFSMBrowseButton = new javax.swing.JButton();
Expand All @@ -85,7 +86,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
mainPanel.setLayout(new java.awt.BorderLayout());

segmentationPickerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Built-in segmentation algorithms"));
segmentationPickerPanel.setLayout(new java.awt.GridLayout(4, 2));
segmentationPickerPanel.setLayout(new java.awt.GridLayout(3, 3));

buttonGroup1.add(jRadioButton7);
jRadioButton7.setSelected(true);
Expand Down Expand Up @@ -120,6 +121,10 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton8.setText("CHAT_MINIMAL");
segmentationPickerPanel.add(jRadioButton8);

buttonGroup1.add(jRadioButton9);
jRadioButton9.setText("INEL_EVENT_BASED");
segmentationPickerPanel.add(jRadioButton9);

mainPanel.add(segmentationPickerPanel, java.awt.BorderLayout.CENTER);

customFSMPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Custom FSM"));
Expand Down Expand Up @@ -188,6 +193,7 @@ public void windowClosing(java.awt.event.WindowEvent e) {
private javax.swing.JRadioButton jRadioButton6;
private javax.swing.JRadioButton jRadioButton7;
private javax.swing.JRadioButton jRadioButton8;
private javax.swing.JRadioButton jRadioButton9;
private javax.swing.JPanel mainPanel;
private javax.swing.JButton okButton;
private javax.swing.JPanel segmentationPickerPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public EditTimelineItemDialog(java.awt.Frame parent,boolean modal, org.exmaralda
numberLabel.setText(Double.toString(timelineItem.getTime()) + " [seconds]");
timeLabel.setText(TimeUtilities.makeTimeString(timelineItem.getTime(),"hh:mm:ss.xxx"));
}
this.setTitle("Edit timeline item: " + tli.getID());
pack ();
absoluteTimeTextField.requestFocus();
org.exmaralda.common.helpers.Internationalizer.internationalizeDialogToolTips(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<Component class="javax.swing.JComboBox" name="segmentationComboBox">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="8">
<StringArray count="10">
<StringItem index="0" value="NONE"/>
<StringItem index="1" value="GENERIC"/>
<StringItem index="2" value="HIAT"/>
Expand All @@ -199,6 +199,8 @@
<StringItem index="5" value="CHAT"/>
<StringItem index="6" value="DIDA"/>
<StringItem index="7" value="IPA"/>
<StringItem index="8" value="INEL_EVENT_BASED"/>
<StringItem index="9" value=" "/>
</StringArray>
</Property>
<Property name="enabled" type="boolean" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jLabel3.setPreferredSize(new java.awt.Dimension(100, 14));
segmentationPanel.add(jLabel3);

segmentationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NONE", "GENERIC", "HIAT", "GAT", "cGAT_MINIMAL", "CHAT", "DIDA", "IPA" }));
segmentationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "NONE", "GENERIC", "HIAT", "GAT", "cGAT_MINIMAL", "CHAT", "DIDA", "IPA", "INEL_EVENT_BASED", " " }));
segmentationComboBox.setEnabled(false);
segmentationComboBox.setMaximumSize(new java.awt.Dimension(150, 20));
segmentationComboBox.setMinimumSize(new java.awt.Dimension(150, 20));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,38 @@ public void moveDownRight (int row, int col){
} catch (JexmaraldaException je){} // should never get here
}

void pasteStructure(BasicTranscription structureClipboard, int selectionStartRow, int selectionEndRow, int selectionStartCol, int selectionEndCol) {
int lengthOfSelection = selectionEndCol - selectionStartCol + 1;
int lengthOfClipboard = structureClipboard.getBody().getCommonTimeline().getNumberOfTimelineItems() - 1;

while (lengthOfSelection<lengthOfClipboard){
insertTimelineItem(selectionEndCol + 1);
lengthOfSelection++;
}

System.out.println(structureClipboard.getBody().toXML());

for (int row=selectionStartRow; row<=selectionEndRow; row++){
Tier sourceTier = structureClipboard.getBody().getTierAt(row-selectionStartRow);
Tier targetTier = getTier(row);
for (int pos=0; pos<sourceTier.getNumberOfEvents(); pos++){
Event event = sourceTier.getEventAt(pos);
int startIndex = structureClipboard.getBody().getCommonTimeline().lookupID(event.getStart());
int endIndex = structureClipboard.getBody().getCommonTimeline().lookupID(event.getEnd());
String startTLI = getTranscription().getBody().getCommonTimeline().getTimelineItemAt(selectionStartCol + startIndex).getID();
String endTLI = getTranscription().getBody().getCommonTimeline().getTimelineItemAt(selectionStartCol + endIndex).getID();
Event newEvent = new Event(startTLI, endTLI, event.getDescription());
System.out.println(newEvent.toXML());
targetTier.addEvent(newEvent);
fireEventAdded(row, selectionStartCol + startIndex, selectionStartCol + endIndex);
fireCellSpanChanged(row, selectionStartCol + startIndex);
fireCellFormatChanged(row, selectionStartCol + startIndex);
}
}

fireAreaChanged(selectionStartCol, selectionEndCol);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,12 @@ public class PartitureTableWithActions extends PartitureTable
public javax.swing.AbstractAction copyTextAction;
/** Action for copying currently selected text to the clipboard as HTML (#338)*/
public javax.swing.AbstractAction copyHTMLAction;
/** Action for copying the current selection as a transcription (#471) */
public javax.swing.AbstractAction copyStructureAction;
/** Action for pasting the clipboard at the current cursor position */
public javax.swing.AbstractAction pasteAction;
/** Action for pasting the structure clipboard at the current position (#471) */
public javax.swing.AbstractAction pasteStructureAction;
/** Action for cutting currently selected text to the clipboard */
public javax.swing.AbstractAction cutAction;

Expand All @@ -322,9 +326,6 @@ public class PartitureTableWithActions extends PartitureTable
public javax.swing.AbstractAction selectionToNewAction;
public javax.swing.AbstractAction leftPartToNewAction;
public javax.swing.AbstractAction rightPartToNewAction;
/*public javax.swing.AbstractAction selectionToHTMLAction;
public javax.swing.AbstractAction selectionToRTFAction;
public javax.swing.AbstractAction printSelectionAction;*/

public javax.swing.AbstractAction glueTranscriptionsAction;
public javax.swing.AbstractAction mergeTranscriptionsAction;
Expand Down Expand Up @@ -635,7 +636,11 @@ private void initActions(){
copyTextAction = new CopyTextAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Copy.gif")));
// new for #338
copyHTMLAction = new CopyHTMLAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Copy.gif")));
// new for #471
copyStructureAction = new CopyStructureAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Copy.gif")));
pasteAction = new PasteAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Paste.gif")));
// new for #471
pasteStructureAction = new PasteStructureAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Paste.gif")));
cutAction = new CutAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Cut.gif")));

searchInEventsAction = new SearchInEventsAction(this, new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/partitureditor/partiture/Icons/Search.gif")));
Expand Down Expand Up @@ -1052,6 +1057,75 @@ public void setFilename(String f){
public String getFilename(){
return filename;
}

// *********************************************************************************** //
// ************************ STRUCTURE CLIPBOARD ************************************** //
// *********************************************************************************** //


BasicTranscription structureClipboard;

public void setStructureClipboard(BasicTranscription newTranscription) {
structureClipboard = newTranscription;
}

public BasicTranscription getStructureClipboard(){
return structureClipboard;
}

public void pasteStructureClipboard() {
boolean clipboardFits = false;

int lengthOfSelection = selectionEndCol - selectionStartCol + 1;
int lengthOfClipboard = structureClipboard.getBody().getCommonTimeline().getNumberOfTimelineItems() - 1;

String rememberSelectionEndColID = getModel().getTimelineItem(selectionEndCol).getID();

if (lengthOfSelection==1 || lengthOfSelection==lengthOfClipboard){
// that's the good case
int heightOfSelection = selectionEndRow - selectionStartRow + 1;
int heightOfClipboard = structureClipboard.getBody().getNumberOfTiers();
if (heightOfSelection==heightOfClipboard){
// that's an even better case
clipboardFits = true;
}
}

if (!clipboardFits){
String message = "The structure in the clipboard does not match the structure of the selection";
JOptionPane.showMessageDialog(this, message);
return;
}

boolean targetIsEmpty = true;
for (int col=selectionStartCol; col<=selectionEndCol; col++){
for (int row=selectionStartRow; row<=selectionEndRow; row++){
targetIsEmpty = targetIsEmpty && (!getModel().containsEvent(row, col));
}
}

if (!targetIsEmpty){
String message = "The target structure is not empty.\n Overwrite?";
int optionChosen = JOptionPane.showConfirmDialog(this, message, "Overwrite target?", JOptionPane.YES_NO_OPTION);
if (optionChosen == JOptionPane.YES_OPTION){
getModel().deleteEvents(selectionStartRow, selectionEndRow, selectionStartCol, selectionEndCol);
} else {
return;
}
}

getModel().pasteStructure(this.getStructureClipboard(), selectionStartRow, selectionEndRow, selectionStartCol, selectionEndCol);

transcriptionChanged = true;

int newSelectionEndCol = getModel().getTranscription().getBody().getCommonTimeline().lookupID(rememberSelectionEndColID) + 1;

setSelection(selectionStartRow, selectionEndRow, selectionStartCol, newSelectionEndCol);


}



// *********************************************************************************** //
// ************************ LISTENER METHODS ***************************************** //
Expand Down Expand Up @@ -3184,6 +3258,8 @@ private int correctYForScreenSize(int y) {
}
return y;
}





Expand Down
Loading

0 comments on commit 599bd1a

Please sign in to comment.