Skip to content

Commit

Permalink
#475: Collect types/categories for tiers + collect types actions
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed Apr 26, 2024
1 parent fbd63ef commit b81dd0f
Show file tree
Hide file tree
Showing 20 changed files with 1,011 additions and 302 deletions.
203 changes: 86 additions & 117 deletions src/org/exmaralda/coma/actions/CheckSegmentationErrorsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
*
* @author thomas Second attempt at application crossover! Bleeding hell!!!!!
*/
public class CheckSegmentationErrorsAction
extends
ComaAction {
public class CheckSegmentationErrorsAction extends ComaAction {

ProgressBarDialog pbd;

Expand All @@ -40,124 +38,95 @@ public CheckSegmentationErrorsAction(String text, ImageIcon icon, Coma c) {

@Override
public void actionPerformed(ActionEvent e) {
final File file = coma.getData().getOpenFile();
if (file == null) {
JOptionPane.showMessageDialog(coma,
Ui.getText("err.noCorpusLoaded"));
return;
}
try {

ChooseSegmentationDialog dialog = new ChooseSegmentationDialog(
this.coma, true);
dialog.setLocationRelativeTo(this.coma);
dialog.setVisible(true);

final SegmentationErrorsChecker checker = new SegmentationErrorsChecker(
dialog.getSegmentationCode(), dialog.getCustomFSMPath());

pbd = new ProgressBarDialog(coma, false);
pbd.setLocationRelativeTo(coma);
pbd.setTitle(Ui.getText("progress.checkSegErrors")
+ coma.getData().getOpenFile().getName());
checker.addSearchListener(pbd);
pbd.setVisible(true);

final Runnable doDisplaySaveDialog = new Runnable() {
@Override
public void run() {
displaySaveDialog(checker);
}

};
Thread checkThread = new Thread() {
@Override
public void run() {
try {
checker.checkCorpus(coma.getData().getDocument(),
file.getParent());
javax.swing.SwingUtilities
.invokeLater(doDisplaySaveDialog);
} catch (URISyntaxException | JexmaraldaException | JDOMException | SAXException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(coma, ex);
pbd.setVisible(false);
}
}
};
checkThread.start();

} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(coma, ex.getMessage());
}
final File file = coma.getData().getOpenFile();
if (file == null) {
JOptionPane.showMessageDialog(coma, Ui.getText("err.noCorpusLoaded"));
return;
}
ChooseSegmentationDialog dialog = new ChooseSegmentationDialog(this.coma, true);
dialog.setLocationRelativeTo(this.coma);
dialog.setVisible(true);

final SegmentationErrorsChecker checker
= new SegmentationErrorsChecker(dialog.getSegmentationCode(), dialog.getCustomFSMPath());

pbd = new ProgressBarDialog(coma, false);
pbd.setLocationRelativeTo(coma);
pbd.setTitle(Ui.getText("progress.checkSegErrors") + coma.getData().getOpenFile().getName());
checker.addSearchListener(pbd);
pbd.setVisible(true);

final Runnable doDisplaySaveDialog = new Runnable() {
@Override
public void run() {
displaySaveDialog(checker);
}

};
Thread checkThread = new Thread() {
@Override
public void run() {
try {
checker.checkCorpus(coma.getData().getDocument(),file.getParent());
javax.swing.SwingUtilities.invokeLater(doDisplaySaveDialog);
} catch (URISyntaxException | JexmaraldaException | JDOMException | SAXException ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(coma, ex);
pbd.setVisible(false);
}
}
};
checkThread.start();

}

private void displaySaveDialog(SegmentationErrorsChecker checker) {
pbd.setVisible(false);
int errorCount = checker.getErrors().getChildren().size();
if (errorCount == 0) {
String message = Ui.getText("result.noSegErrors");
JOptionPane.showMessageDialog(coma, message);
return;
} else {
String message = Integer.toString(errorCount)
+ Ui.getText("result.segErrorsFound");
int choice = JOptionPane.showConfirmDialog(coma, message,
Ui.getText("prompt.saveErrorList"),
JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(coma.getData().getOpenFile());
fc.setFileFilter(new ParameterFileFilter("xml", "XML files"));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
boolean goon = false;
while (!goon) {
int ret = fc.showSaveDialog(coma);
if (ret == JFileChooser.APPROVE_OPTION) {
try {
String filename = fc.getSelectedFile()
.getAbsolutePath();
if (fc.getSelectedFile().getName().indexOf(".") < 0) {
filename += ".xml";
}
if (new File(filename).exists()) {
int ret2 = JOptionPane
.showConfirmDialog(
coma,
filename
+ "\n"
+ Ui.getText("msg.overwriteWarning"),
"", JOptionPane.YES_NO_OPTION);
if (ret2 == JOptionPane.NO_OPTION)
continue;
}
System.out.println("Writing error list to "
+ filename);
// org.exmaralda.common.jdomutilities.IOUtilities.writeDocumentToLocalFile(fc.getSelectedFile().getAbsolutePath(),
// checker.getErrorsDocoument());
checker.output(filename);
goon = true;
} catch (JDOMException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(coma,
ex.getLocalizedMessage());
} catch (URISyntaxException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(coma,
ex.getLocalizedMessage());
} catch (IOException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(coma,
ex.getLocalizedMessage());
}
} else {
goon = true;
}
}
}
}
pbd.setVisible(false);
int errorCount = checker.getErrors().getChildren().size();
if (errorCount == 0) {
String message = Ui.getText("result.noSegErrors");
JOptionPane.showMessageDialog(coma, message);
} else {
String message = Integer.toString(errorCount)
+ Ui.getText("result.segErrorsFound");
int choice = JOptionPane.showConfirmDialog(coma, message,
Ui.getText("prompt.saveErrorList"),
JOptionPane.YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(coma.getData().getOpenFile());
fc.setFileFilter(new ParameterFileFilter("xml", "XML files"));
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
boolean goon = false;
while (!goon) {
int ret = fc.showSaveDialog(coma);
if (ret == JFileChooser.APPROVE_OPTION) {
try {
String filename = fc.getSelectedFile().getAbsolutePath();
if (!fc.getSelectedFile().getName().contains(".")) {
filename += ".xml";
}
if (new File(filename).exists()) {
int ret2 = JOptionPane.showConfirmDialog(
coma,
filename + "\n" + Ui.getText("msg.overwriteWarning"),
"", JOptionPane.YES_NO_OPTION);
if (ret2 == JOptionPane.NO_OPTION)
continue;
}
System.out.println("Writing error list to " + filename);
checker.output(filename);
goon = true;
} catch (JDOMException | URISyntaxException | IOException ex) {
System.out.println(ex.getMessage());
JOptionPane.showMessageDialog(coma, ex.getLocalizedMessage());
}
} else {
goon = true;
}
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package org.exmaralda.coma.actions;

import java.awt.event.ActionEvent;
import java.io.File;
import java.net.URISyntaxException;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import org.exmaralda.coma.dialogs.CategoriesPlusTypesDialog;

import org.exmaralda.coma.root.Coma;
import org.exmaralda.coma.root.Ui;
import org.exmaralda.common.corpusbuild.CategoryPlusType;
import org.exmaralda.common.corpusbuild.CollectTierCategoriesTypes;
import org.exmaralda.common.dialogs.ProgressBarDialog;
import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
import org.jdom.JDOMException;
import org.xml.sax.SAXException;

/**
*
* @author thomas
*/

// 26-04-2024
// as a side-effect of issue #475

public class CollectTierCategoriesTypesAction extends ComaAction {

ProgressBarDialog pbd;

public CollectTierCategoriesTypesAction(String text, ImageIcon icon, Coma c) {
super(text, icon, c);
}

@Override
public void actionPerformed(ActionEvent e) {
final File file = coma.getData().getOpenFile();
if (file == null) {
JOptionPane.showMessageDialog(coma, Ui.getText("err.noCorpusLoaded"));
return;
}
final CollectTierCategoriesTypes collector = new CollectTierCategoriesTypes();

pbd = new ProgressBarDialog(coma, false);
pbd.setLocationRelativeTo(coma);
pbd.setTitle(Ui.getText("progress.collectTierCategoriesTypes") + coma.getData().getOpenFile().getName());
pbd.setVisible(true);

final Runnable doDisplaySaveDialog = new Runnable() {
@Override
public void run() {
displayEditDialog(collector);
}
};
Thread checkThread = new Thread() {
@Override
public void run() {
try {
collector.checkCorpus(coma.getData().getDocument(), file.getParent());
javax.swing.SwingUtilities.invokeLater(doDisplaySaveDialog);
} catch (URISyntaxException | JexmaraldaException | JDOMException | SAXException ex) {
JOptionPane.showMessageDialog(coma, ex);
System.out.println(ex.getMessage());
pbd.setVisible(false);
}
}
};
checkThread.start();
}

private void displayEditDialog(CollectTierCategoriesTypes collector) {
pbd.setVisible(false);
Map<CategoryPlusType, Integer> categoryPlusTypeMap = collector.getCategoryPlusTypeMap();
CategoriesPlusTypesDialog dialog = new CategoriesPlusTypesDialog(coma, true, categoryPlusTypeMap);
dialog.setLocationRelativeTo(coma);
dialog.setVisible(true);
}

}
Loading

0 comments on commit b81dd0f

Please sign in to comment.