From 6fb9e82df92172116c246585ef3e1c6a624447ec Mon Sep 17 00:00:00 2001 From: berndmoos Date: Sat, 15 Feb 2025 20:27:39 +0100 Subject: [PATCH] #445 --- .../KWICTableActions/AdvancedSortAction.java | 41 +++++ .../KWICTableActions/RowsMenu.java | 17 ++ .../swing/AdvancedSortDialog.form | 96 +++++++++++ .../swing/AdvancedSortDialog.java | 158 ++++++++++++++++++ .../swing/AdvancedSortPanel.form | 91 ++++++++++ .../swing/AdvancedSortPanel.java | 76 +++++++++ .../exmaraldaSearch/swing/COMAKWICTable.java | 2 + .../swing/ColumnSelectionComboBoxModel.java | 40 +++++ .../swing/RegExFilterPanel.java | 14 +- 9 files changed, 522 insertions(+), 13 deletions(-) create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/AdvancedSortAction.java create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.form create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.java create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.form create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.java create mode 100644 src/org/exmaralda/exakt/exmaraldaSearch/swing/ColumnSelectionComboBoxModel.java diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/AdvancedSortAction.java b/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/AdvancedSortAction.java new file mode 100644 index 00000000..1b708db7 --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/AdvancedSortAction.java @@ -0,0 +1,41 @@ +/* + * WordWiseReversedSortAction.java + * + * Created on 19. Februar 2007, 13:45 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.exmaralda.exakt.exmaraldaSearch.KWICTableActions; + +import java.awt.Frame; +import java.awt.event.ActionEvent; +import org.exmaralda.exakt.exmaraldaSearch.swing.AdvancedSortDialog; +import org.exmaralda.exakt.exmaraldaSearch.swing.COMAKWICTable; + +/** + * + * @author thomas + */ +public class AdvancedSortAction extends AbstractKWICTableAction { + + /** Creates a new instance of WordWiseReversedSortAction + * @param t + * @param title */ + public AdvancedSortAction(COMAKWICTable t, String title) { + super(t,title); + } + + @Override + public void actionPerformed(ActionEvent e) { + AdvancedSortDialog advancedSortDialog = new AdvancedSortDialog((Frame) table.getTopLevelAncestor(), true, table); + advancedSortDialog.setLocationRelativeTo(table); + advancedSortDialog.setVisible(true); + if (!advancedSortDialog.approved){ + return; + } + + } + +} diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/RowsMenu.java b/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/RowsMenu.java index 5cb2d4fa..710413f7 100644 --- a/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/RowsMenu.java +++ b/src/org/exmaralda/exakt/exmaraldaSearch/KWICTableActions/RowsMenu.java @@ -29,6 +29,7 @@ public class RowsMenu extends javax.swing.JMenu { private final JMenuItem selectHighlightedMenuItem; private final JMenuItem deselectHighlightedMenuItem; private final JMenuItem removeUnselectedMenuItem; + private final JMenuItem advancedSortMenuItem; @@ -105,9 +106,25 @@ public void actionPerformed(ActionEvent e) { } }); this.add(deselectHighlightedMenuItem); + + this.addSeparator(); + advancedSortMenuItem = new JMenuItem("Advanced sorting..."); + advancedSortMenuItem.addActionListener(new javax.swing.AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + advancedSorting(e); + } + }); + this.add(advancedSortMenuItem); } + + void advancedSorting(ActionEvent e) { + if (exaktFrame.getActiveSearchPanel()==null) return; + exaktFrame.getActiveSearchPanel().getKWICTable().advancedSortAction.actionPerformed(e); + } + void sample(ActionEvent e){ if (exaktFrame.getActiveSearchPanel()==null) return; diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.form b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.form new file mode 100644 index 00000000..f41876ce --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.form @@ -0,0 +1,96 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.java b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.java new file mode 100644 index 00000000..1f3e3ded --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortDialog.java @@ -0,0 +1,158 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JDialog.java to edit this template + */ +package org.exmaralda.exakt.exmaraldaSearch.swing; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author bernd + */ +public class AdvancedSortDialog extends javax.swing.JDialog { + + + COMAKWICTable kwic; + + List sortPanels = new ArrayList<>(); + + public boolean approved = false; + + /** + * Creates new form AdvancedSortDialog + */ + public AdvancedSortDialog(java.awt.Frame parent, boolean modal, COMAKWICTable kwic) { + super(parent, modal); + this.kwic = kwic; + initComponents(); + AdvancedSortPanel initialPanel = new AdvancedSortPanel(kwic); + sortPanels.add(initialPanel); + mainPanel.add(initialPanel); + pack(); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + mainPanel = new javax.swing.JPanel(); + okCancelPanel = new javax.swing.JPanel(); + okButton = new javax.swing.JButton(); + cancelButton = new javax.swing.JButton(); + addPanel = new javax.swing.JPanel(); + addButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setTitle("Advanced sorting"); + + mainPanel.setMaximumSize(new java.awt.Dimension(400, 300)); + mainPanel.setMinimumSize(new java.awt.Dimension(400, 300)); + mainPanel.setLayout(new javax.swing.BoxLayout(mainPanel, javax.swing.BoxLayout.Y_AXIS)); + getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER); + + okButton.setText("OK"); + okButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + okButtonActionPerformed(evt); + } + }); + okCancelPanel.add(okButton); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + cancelButtonActionPerformed(evt); + } + }); + okCancelPanel.add(cancelButton); + + getContentPane().add(okCancelPanel, java.awt.BorderLayout.SOUTH); + + addButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/exmaralda/exakt/exmaraldaSearch/swing/resources/list-add.png"))); // NOI18N + addButton.setToolTipText("Add sort criterion"); + addButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addButtonActionPerformed(evt); + } + }); + addPanel.add(addButton); + + getContentPane().add(addPanel, java.awt.BorderLayout.WEST); + + pack(); + }// //GEN-END:initComponents + + private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed + approved = true; + dispose(); + }//GEN-LAST:event_okButtonActionPerformed + + private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed + dispose(); + }//GEN-LAST:event_cancelButtonActionPerformed + + private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed + AdvancedSortPanel addedPanel = new AdvancedSortPanel(kwic); + sortPanels.add(addedPanel); + mainPanel.add(addedPanel); + pack(); + }//GEN-LAST:event_addButtonActionPerformed + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(AdvancedSortDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(AdvancedSortDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(AdvancedSortDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(AdvancedSortDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the dialog */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + AdvancedSortDialog dialog = new AdvancedSortDialog(new javax.swing.JFrame(), true, null); + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + @Override + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addButton; + private javax.swing.JPanel addPanel; + private javax.swing.JButton cancelButton; + private javax.swing.JPanel mainPanel; + private javax.swing.JButton okButton; + private javax.swing.JPanel okCancelPanel; + // End of variables declaration//GEN-END:variables +} diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.form b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.form new file mode 100644 index 00000000..318d6d26 --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.form @@ -0,0 +1,91 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.java b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.java new file mode 100644 index 00000000..cd1d3684 --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/AdvancedSortPanel.java @@ -0,0 +1,76 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JPanel.java to edit this template + */ +package org.exmaralda.exakt.exmaraldaSearch.swing; + +/** + * + * @author bernd + */ +public class AdvancedSortPanel extends javax.swing.JPanel { + + /** + * Creates new form AdvancedSortPanel + */ + public AdvancedSortPanel(COMAKWICTable kwic) { + initComponents(); + ColumnSelectionComboBoxModel comboBoxModel = new ColumnSelectionComboBoxModel(kwic.getWrappedModel()); + columnNameComboBox.setModel(comboBoxModel); + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jPanel1 = new javax.swing.JPanel(); + activeCheckBox = new javax.swing.JCheckBox(); + columnLabel = new javax.swing.JLabel(); + columnNameComboBox = new javax.swing.JComboBox<>(); + jPanel2 = new javax.swing.JPanel(); + orderLabel = new javax.swing.JLabel(); + orderComboBox = new javax.swing.JComboBox<>(); + orderComboBox2 = new javax.swing.JComboBox<>(); + + setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS)); + + activeCheckBox.setSelected(true); + jPanel1.add(activeCheckBox); + + columnLabel.setText("Sort by column: "); + jPanel1.add(columnLabel); + + columnNameComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); + jPanel1.add(columnNameComboBox); + + add(jPanel1); + + orderLabel.setText("Order: "); + jPanel2.add(orderLabel); + + orderComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "alphabetically", "numerically" })); + jPanel2.add(orderComboBox); + + orderComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "ascending", "descending", "ascending reversed", "descending reversed", " " })); + jPanel2.add(orderComboBox2); + + add(jPanel2); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JCheckBox activeCheckBox; + private javax.swing.JLabel columnLabel; + private javax.swing.JComboBox columnNameComboBox; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JComboBox orderComboBox; + private javax.swing.JComboBox orderComboBox2; + private javax.swing.JLabel orderLabel; + // End of variables declaration//GEN-END:variables +} diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/COMAKWICTable.java b/src/org/exmaralda/exakt/exmaraldaSearch/swing/COMAKWICTable.java index 8d9cf2d9..b0f8fd23 100644 --- a/src/org/exmaralda/exakt/exmaraldaSearch/swing/COMAKWICTable.java +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/COMAKWICTable.java @@ -43,6 +43,7 @@ public class COMAKWICTable extends javax.swing.JTable public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.PraatAction praatAction; public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.CopyAction copyAction; public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.ImportAnalysesAction importAnalysesAction; + public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.AdvancedSortAction advancedSortAction; public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.SampleAction sampleAction; public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.ShuffleAction shuffleAction; public org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.SelectAllAction selectAllAction; @@ -119,6 +120,7 @@ private void initActions(){ copyAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.CopyAction(this, "Copy"); importAnalysesAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.ImportAnalysesAction(this, "Import analyses..."); sampleAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.SampleAction(this, "Sample..."); + advancedSortAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.AdvancedSortAction(this, "Advanced sort..."); shuffleAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.ShuffleAction(this, "Shuffle"); selectAllAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.SelectAllAction(this, "Select all"); deselectAllAction = new org.exmaralda.exakt.exmaraldaSearch.KWICTableActions.DeselectAllAction(this, "Deselect all"); diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/ColumnSelectionComboBoxModel.java b/src/org/exmaralda/exakt/exmaraldaSearch/swing/ColumnSelectionComboBoxModel.java new file mode 100644 index 00000000..916c1a5e --- /dev/null +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/ColumnSelectionComboBoxModel.java @@ -0,0 +1,40 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package org.exmaralda.exakt.exmaraldaSearch.swing; + +import java.util.List; +import javax.swing.DefaultComboBoxModel; +import org.exmaralda.exakt.search.analyses.AnalysisInterface; + +/** + * + * @author bernd + */ +public class ColumnSelectionComboBoxModel extends DefaultComboBoxModel { + + public static String[] fixedColumns = {"Left context", "Match text", "Right context", "Communication", "Speaker"}; + + + public ColumnSelectionComboBoxModel(COMASearchResultListTableModel m) { + List metaIdentifiers = m.getMetaIdentifiers(); + + for (String s : fixedColumns){ + addElement(s); + } + for (AnalysisInterface ai : m.getData().getAnalyses()){ + addElement(ai.getName()); + } + for (String[] s : metaIdentifiers){ + addElement(s[1] + "[" + s[0] + "]"); + } + + + } + + + + + +} diff --git a/src/org/exmaralda/exakt/exmaraldaSearch/swing/RegExFilterPanel.java b/src/org/exmaralda/exakt/exmaraldaSearch/swing/RegExFilterPanel.java index 27534547..5c6ebd26 100644 --- a/src/org/exmaralda/exakt/exmaraldaSearch/swing/RegExFilterPanel.java +++ b/src/org/exmaralda/exakt/exmaraldaSearch/swing/RegExFilterPanel.java @@ -20,7 +20,6 @@ public class RegExFilterPanel extends javax.swing.JPanel { InputHelperDialog inputHelperDialog = new InputHelperDialog(this); DefaultComboBoxModel columnSelectionComboBoxModel; List meta; - String[] fixedColumns = {"Left context", "Match text", "Right context", "Communication", "Speaker"}; COMASearchResultListTableModel tableModel; private int selectedColumn = -1; @@ -28,18 +27,7 @@ public class RegExFilterPanel extends javax.swing.JPanel { public RegExFilterPanel(COMASearchResultListTableModel m) { initComponents(); tableModel = m; - meta = m.getMetaIdentifiers(); - - columnSelectionComboBoxModel = new DefaultComboBoxModel(); - for (String s : fixedColumns){ - columnSelectionComboBoxModel.addElement(s); - } - for (AnalysisInterface ai : m.getData().getAnalyses()){ - columnSelectionComboBoxModel.addElement(ai.getName()); - } - for (String[] s : meta){ - columnSelectionComboBoxModel.addElement(s[1] + "[" + s[0] + "]"); - } + columnSelectionComboBoxModel = new ColumnSelectionComboBoxModel(m); columnSelectionComboBox.setModel(columnSelectionComboBoxModel); }