Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed May 27, 2024
1 parent d544a9b commit c52b1dc
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 9 deletions.
59 changes: 55 additions & 4 deletions src/org/exmaralda/coma/actions/CollectTypesAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.exmaralda.common.corpusbuild.CategoryPlusType;
import org.exmaralda.common.corpusbuild.CollectTierCategoriesTypes;
import org.exmaralda.common.corpusbuild.CollectTypesInCategory;
import org.exmaralda.common.corpusbuild.ReplaceTypesInCategory;
import org.exmaralda.common.dialogs.ProgressBarDialog;
import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
import org.exmaralda.partitureditor.jexmaralda.Tier;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void actionPerformed(ActionEvent e) {
preCollector.checkCorpus(coma.getData().getDocument(), file.getParent());
Map<CategoryPlusType, Integer> categoryPlusTypeMap = preCollector.getCategoryPlusTypeMap();
CategoriesPlusTypesDialog dialog = new CategoriesPlusTypesDialog(coma, true, categoryPlusTypeMap);
dialog.setSelectMode(true);
dialog.setLocationRelativeTo(coma);
dialog.setVisible(true);

Expand Down Expand Up @@ -104,10 +106,59 @@ private void displayEditDialog(CollectTypesInCategory collector, String category
pbd.setVisible(false);
Map<String, Integer> typesTable = collector.getTypesTable();
Tier dummyTier = new Tier("idx", null, category, type);
TypesDialog dialog = new TypesDialog(coma, true);
dialog.setData(typesTable, dummyTier);
dialog.setLocationRelativeTo(coma);
dialog.setVisible(true);
TypesDialog typesDialog = new TypesDialog(coma, true);
typesDialog.setData(typesTable, dummyTier);
typesDialog.setLocationRelativeTo(coma);
typesDialog.setVisible(true);

if (typesDialog.approved){
Map<String,String> mappings = typesDialog.getMappings();
int countMappings = 0;
for (String source : mappings.keySet()){
String target = mappings.get(source);
if (!source.equals(target)) countMappings++;
}
if (countMappings==0) return;


String message = Integer.toString(countMappings) + " types will be mapped to a different value. \nAre you sure that you want to continue?";
int optionChosen = JOptionPane.showConfirmDialog(coma, message, "Confirm replace", JOptionPane.YES_NO_OPTION);
if (optionChosen != JOptionPane.YES_OPTION) return;

final ReplaceTypesInCategory executor = new ReplaceTypesInCategory(category, type, mappings);

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

final Runnable doDisplayReplacementDoneDialog = new Runnable() {
@Override
public void run() {
//displayEditDialog(collector, category, type);
String message = Integer.toString(executor.allReplacementCounts) + " replacements were made. <br/> Resegmentation may be necessary. ";
JOptionPane.showMessageDialog(coma, message);
}
};
Thread replaceThread = new Thread() {
@Override
public void run() {
try {
executor.checkCorpus(coma.getData().getDocument(), coma.getData().getOpenFile().getParent());
javax.swing.SwingUtilities.invokeLater(doDisplayReplacementDoneDialog);
} catch (URISyntaxException | JexmaraldaException | JDOMException | SAXException ex) {
JOptionPane.showMessageDialog(coma, ex);
System.out.println(ex.getMessage());
pbd.setVisible(false);
}
}
};
replaceThread.start();


}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>

<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
Expand Down
25 changes: 24 additions & 1 deletion src/org/exmaralda/coma/dialogs/CategoriesPlusTypesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package org.exmaralda.coma.dialogs;

import java.util.Map;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import org.exmaralda.coma.models.CategoryPlusTypesTableModel;
Expand All @@ -18,9 +20,13 @@
public class CategoriesPlusTypesDialog extends javax.swing.JDialog {

public boolean approved = false;
boolean selectMode = false;

/**
* Creates new form CategoriesPlusTypesDialog
* @param parent
* @param modal
* @param categoryPlusTypeMap
*/
public CategoriesPlusTypesDialog(java.awt.Frame parent, boolean modal, Map<CategoryPlusType, Integer> categoryPlusTypeMap) {
super(parent, modal);
Expand All @@ -30,7 +36,24 @@ public CategoriesPlusTypesDialog(java.awt.Frame parent, boolean modal, Map<Categ
categoriesPlusTypesTable.setDefaultRenderer(String.class, new CategoryPlusTypesTableCellRenderer());
categoriesPlusTypesTable.setDefaultRenderer(Integer.class, new CategoryPlusTypesTableCellRenderer());
TableRowSorter<TableModel> sorter = new TableRowSorter<>(categoriesPlusTypesTable.getModel());
categoriesPlusTypesTable.setRowSorter(sorter);
categoriesPlusTypesTable.setRowSorter(sorter);


categoriesPlusTypesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent e) {
okButton.setEnabled(categoriesPlusTypesTable.getSelectedRow()>=0);
}

});
}

public void setSelectMode(boolean selectMode){
this.selectMode = selectMode;
if (selectMode){
okButton.setText("Select");
okButton.setEnabled(categoriesPlusTypesTable.getSelectedRow()>=0);
}
}

public String getSelectedCategory(){
Expand Down
6 changes: 3 additions & 3 deletions src/org/exmaralda/coma/resources/languages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ CoMa geçici olarak iç düzeni kullanıyor&lt;/html&gt;&lt;/body&gt;"/>


<uiItem name="err.noCorpusLoaded" lang="deu" value="&lt;html&gt;&lt;body&gt;Laden (oder speichern) Sie zuerst&lt;br&gt;eine Coma-Datei.&lt;/html&gt;&lt;/body&gt;"/>
<uiItem name="err.noCorpusLoaded" lang="eng" value="&lt;html&gt;&lt;body&gt;Please load (or save)&lt;br&gt;na coma-file first.&lt;/html&gt;&lt;/body&gt;"/>
<uiItem name="err.noCorpusLoaded" lang="eng" value="&lt;html&gt;&lt;body&gt;Please load (or save)&lt;br&gt;a COMA file first.&lt;/html&gt;&lt;/body&gt;"/>

<uiItem name="err.noDescriptionKeys" lang="deu" value="Es existieren keine Description-Schlüssel!"/>
<uiItem name="err.noDescriptionKeys" lang="eng" value="There are no description-keys to harmonize!"/>
Expand Down Expand Up @@ -1094,8 +1094,8 @@ CoMa geçici olarak iç düzeni kullanıyor&lt;/html&gt;&lt;/body&gt;"/>
<!-- Messages (message.*) -->
<uiItem name="msg.changesTranscriptionsWarning" lang="deu" value="&lt;html&gt;&lt;b&gt;Achtung!&lt;/b&gt;&lt;br/&gt;Diese Funktion &lt;b&gt;modifiziert&lt;/b&gt; die Basistranskriptionen im Korpus.&lt;br/&gt;Benutzen Sie diese Funktion nur, wenn Sie genau wissen, was Sie tun!&lt;/html&gt;"/>
<uiItem name="msg.changesTranscriptionsWarning" lang="eng" value="&lt;html&gt;&lt;b&gt;Warning!&lt;/b&gt;&lt;br/&gt;This Operation &lt;b&gt;modifies&lt;/b&gt; basic transcriptions in your corpus.&lt;br/&gt;Please use with extreme caution!&lt;/html&gt;"/>
<uiItem name="message.comaGenerated" lang="deu" value="Coma-File geschrieben."/>
<uiItem name="message.comaGenerated" lang="eng" value="Coma-file written."/>
<uiItem name="message.comaGenerated" lang="deu" value="Coma-Datei geschrieben."/>
<uiItem name="message.comaGenerated" lang="eng" value="Coma file written."/>
<uiItem name="message.comaGenerated" lang="tk" value="Coma-dosyası yazıldı."/>

<uiItem name="metadata" lang="deu" value="Metadaten"/>
Expand Down
2 changes: 1 addition & 1 deletion src/org/exmaralda/coma/root/Coma.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ public String getPreferencesNode() {
public void resetSettings() {
try {
java.util.prefs.Preferences.userRoot().node(getPreferencesNode()).clear();
JOptionPane.showMessageDialog(rootPane, "Preferences reset.\nRestart the editor.");
JOptionPane.showMessageDialog(rootPane, "<html>Preferences reset.<br/><b>Restart the editor.</b></html>");
} catch (BackingStoreException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(rootPane, "Problem resetting preferences:\n" + ex.getLocalizedMessage());
Expand Down

0 comments on commit c52b1dc

Please sign in to comment.