From 6c4e32575b3431e7c9a8d3f430152c9fa2b339d3 Mon Sep 17 00:00:00 2001 From: Bengt Martensson Date: Wed, 27 Dec 2023 16:21:31 +0100 Subject: [PATCH] Allow empty commands to be imported in Girr. Resolves #511. This can be turned o and off through Options -> Import options -> Accept empty Girr commands on import. --- .../harctoolbox/irscrutinizer/GuiMain.form | 29 ++++++++++ .../harctoolbox/irscrutinizer/GuiMain.java | 56 ++++++++++++++++++- .../irscrutinizer/NamedIrSignal.java | 15 +++++ .../irscrutinizer/ParametrizedIrSignal.java | 10 ++++ .../irscrutinizer/RawIrSignal.java | 22 ++++++-- src/main/xml/Props.xml | 1 + 6 files changed, 126 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form index a3a5e229..9b275245 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form +++ b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form @@ -641,6 +641,15 @@ + + + + + + + + + @@ -916,6 +925,15 @@ + + + + + + + + + @@ -2079,6 +2097,17 @@ + + + + + + + + + + + diff --git a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java index 04d26fae..05df1c6d 100755 --- a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java @@ -450,6 +450,7 @@ private void setupIctImporter() { } private void setupGirrImporter() throws MalformedURLException { + Command.setAcceptEmptyCommands(properties.getAllowEmptyGirrCommands()); girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), irpDatabase); properties.addGirrSchemaLocationChangeListener((String name1, Object oldValue, Object newValue) -> { try { @@ -2200,6 +2201,7 @@ private void initComponents() { addMissingFsMenuItem = new javax.swing.JMenuItem(); addMissingNamesMenuItem = new javax.swing.JMenuItem(); deleteDefaultedSignalsMenuItem = new javax.swing.JMenuItem(); + deleteEmptyParametrizedSignalsMenuItem = new javax.swing.JMenuItem(); rawTablePopupMenu = new javax.swing.JPopupMenu(); rawSorterCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem(); jSeparator25 = new javax.swing.JPopupMenu.Separator(); @@ -2237,6 +2239,7 @@ private void initComponents() { removeUnusedMenuItem1 = new javax.swing.JMenuItem(); hideUninterestingColumnsMenuItem1 = new javax.swing.JMenuItem(); clearRawCommentMenuItem = new javax.swing.JMenuItem(); + deleteEmptyRawSignalsMenuItem = new javax.swing.JMenuItem(); copyPastePopupMenu = new org.harctoolbox.guicomponents.CopyPastePopupMenu(true); copyPopupMenu = new org.harctoolbox.guicomponents.CopyPastePopupMenu(); topLevelSplitPane = new javax.swing.JSplitPane(); @@ -2602,6 +2605,7 @@ private void initComponents() { translateProntoFontCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem(); girrValidateCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem(); girrSchemaLocationMenuItem = new javax.swing.JMenuItem(); + girrAcceptEmptyCommandsCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem(); rejectLircCodeImports = new javax.swing.JCheckBoxMenuItem(); exportOptionsMenu = new javax.swing.JMenu(); exportCharsetMenuItem = new javax.swing.JMenuItem(); @@ -3205,6 +3209,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); parametrizedAdvancedMenu.add(deleteDefaultedSignalsMenuItem); + deleteEmptyParametrizedSignalsMenuItem.setText("Delete empty Signals"); + deleteEmptyParametrizedSignalsMenuItem.setToolTipText("Remove all signals that do not have content."); + deleteEmptyParametrizedSignalsMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteEmptyParametrizedSignalsMenuItemActionPerformed(evt); + } + }); + parametrizedAdvancedMenu.add(deleteEmptyParametrizedSignalsMenuItem); + parameterTablePopupMenu.add(parametrizedAdvancedMenu); rawSorterCheckBoxMenuItem.setSelected(properties.getSorterOnRawTable()); @@ -3458,6 +3471,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); rawTablePopupMenu.add(clearRawCommentMenuItem); + deleteEmptyRawSignalsMenuItem.setText("Delete empty Signals"); + deleteEmptyRawSignalsMenuItem.setToolTipText("Remove all signals that do not have a content."); + deleteEmptyRawSignalsMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + deleteEmptyRawSignalsMenuItemActionPerformed(evt); + } + }); + rawTablePopupMenu.add(deleteEmptyRawSignalsMenuItem); + setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); topLevelSplitPane.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); @@ -6834,6 +6856,15 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); importOptionsMenu.add(girrSchemaLocationMenuItem); + girrAcceptEmptyCommandsCheckBoxMenuItem.setSelected(properties.getAllowEmptyGirrCommands()); + girrAcceptEmptyCommandsCheckBoxMenuItem.setText("Accept empty Girr commands on import"); + girrAcceptEmptyCommandsCheckBoxMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + girrAcceptEmptyCommandsCheckBoxMenuItemActionPerformed(evt); + } + }); + importOptionsMenu.add(girrAcceptEmptyCommandsCheckBoxMenuItem); + rejectLircCodeImports.setSelected(properties.getRejectLircCodeImports()); rejectLircCodeImports.setText("Reject Lirc Imports without timings"); rejectLircCodeImports.addActionListener(new java.awt.event.ActionListener() { @@ -9384,7 +9415,7 @@ private void exportGenerateBroadlinkHexCheckBoxActionPerformed(java.awt.event.Ac }//GEN-LAST:event_exportGenerateBroadlinkHexCheckBoxActionPerformed private void exportGenerateBroadlinkBase64CheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportGenerateBroadlinkBase64CheckBoxActionPerformed - properties.setExportGenerateBroadlinkBase64(exportGenerateBroadlinkBase64CheckBox.isSelected()); + properties.setExportGenerateBroadlinkBase64(exportGenerateBroadlinkBase64CheckBox.isSelected()); exportRepeatComboBox.setEnabled(exportGenerateSendIrCheckBox.isSelected() || exportGenerateBroadlinkHexCheckBox.isSelected() || exportGenerateBroadlinkBase64CheckBox.isSelected()); @@ -9398,6 +9429,26 @@ private void disussionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) { } }//GEN-LAST:event_disussionsMenuItemActionPerformed + private void girrAcceptEmptyCommandsCheckBoxMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_girrAcceptEmptyCommandsCheckBoxMenuItemActionPerformed + boolean status = girrAcceptEmptyCommandsCheckBoxMenuItem.isSelected(); + properties.setAllowEmptyGirrCommands(status); + Command.setAcceptEmptyCommands(status); + }//GEN-LAST:event_girrAcceptEmptyCommandsCheckBoxMenuItemActionPerformed + + private void deleteEmptyParametrizedSignalsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteEmptyParametrizedSignalsMenuItemActionPerformed + boolean isOk = guiUtils.confirm("This will delete all signal with no protocol and no parameters.\n" + + "The operation cannot be undone. Consider saving first.\n\nDo you want to continue?"); + if (isOk) + parameterTableModel.deleteEmptySignals(); + }//GEN-LAST:event_deleteEmptyParametrizedSignalsMenuItemActionPerformed + + private void deleteEmptyRawSignalsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteEmptyRawSignalsMenuItemActionPerformed + boolean isOk = guiUtils.confirm("This will delete all signal with no non-empty sequences.\n" + + "The operation cannot be undone. Consider saving first.\n\nDo you want to continue?"); + if (isOk) + rawTableModel.deleteEmptySignals(); + }//GEN-LAST:event_deleteEmptyRawSignalsMenuItemActionPerformed + // // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPopupMenu CCFCodePopupMenu; @@ -9482,6 +9533,8 @@ private void disussionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) { private javax.swing.JMenu debugMenu; private javax.swing.JTextField decodeIRTextField; private javax.swing.JMenuItem deleteDefaultedSignalsMenuItem; + private javax.swing.JMenuItem deleteEmptyParametrizedSignalsMenuItem; + private javax.swing.JMenuItem deleteEmptyRawSignalsMenuItem; private javax.swing.JMenuItem deleteMenuItem; private javax.swing.JMenuItem deleteMenuItem1; private org.harctoolbox.guicomponents.DevLircBean devLircBean; @@ -9558,6 +9611,7 @@ private void disussionsMenuItemActionPerformed(java.awt.event.ActionEvent evt) { private javax.swing.JPanel generatePanel; private javax.swing.JCheckBoxMenuItem generateRawCheckBoxMenuItem; private javax.swing.JTextArea generateTextArea; + private javax.swing.JCheckBoxMenuItem girrAcceptEmptyCommandsCheckBoxMenuItem; private javax.swing.JPanel girrExportOptionsPanel; private javax.swing.JCheckBox girrFatRawCheckBox; private org.harctoolbox.irscrutinizer.importer.FileImporterBean girrFileImporterBean; diff --git a/src/main/java/org/harctoolbox/irscrutinizer/NamedIrSignal.java b/src/main/java/org/harctoolbox/irscrutinizer/NamedIrSignal.java index bca5ce3c..e3b5591d 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/NamedIrSignal.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/NamedIrSignal.java @@ -102,6 +102,8 @@ public String toPrintString() { return csvString(", "); } + public abstract boolean isEmpty(); + /** * */ @@ -512,5 +514,18 @@ boolean hasUnsavedChanges() { } abstract void duplicate(int modelRow); + + abstract NamedIrSignal getNamedIrSignal(int row); + + void deleteEmptySignals() { + for (int row = getRowCount() - 1; row >= 0; row--) { + NamedIrSignal sig = getNamedIrSignal(row); + if (sig.isEmpty()) + removeRow(row); + } + fireTableDataChanged(); + } + + } } diff --git a/src/main/java/org/harctoolbox/irscrutinizer/ParametrizedIrSignal.java b/src/main/java/org/harctoolbox/irscrutinizer/ParametrizedIrSignal.java index b1153b67..95e7a3b7 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/ParametrizedIrSignal.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/ParametrizedIrSignal.java @@ -201,6 +201,11 @@ private String dummyName() { return DefaultSignalNameFormatter.formatName(protocolName, parameters); } + @Override + public boolean isEmpty() { + return (protocolName == null || protocolName.isEmpty()) && (parameters == null || parameters.isEmpty()); + } + private static class ParameterIrSignalColumns extends NamedIrSignal.AbstractColumnFunction /*implements IColumn*/ { private static final int[] widths = { @@ -324,6 +329,11 @@ public ParametrizedIrSignal getParameterIrSignal(int row) { : null; } + @Override + NamedIrSignal getNamedIrSignal(int row) { + return getParameterIrSignal(row); + } + public void addSignal(ParametrizedIrSignal signal) { super.addSignal(signal); } diff --git a/src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java b/src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java index 4df114c9..7a0ca5df 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java @@ -165,7 +165,7 @@ public static void setInvert(boolean aInvert) { private void setIrSignal(IrSignal irSignal, Decoder.AbstractDecodesCollection decodes) { this.irSignal = irSignal; this.decodes = decodes; - if (invokeAnalyzer) { + if (irSignal != null && invokeAnalyzer) { try { Analyzer analyzer = new Analyzer(irSignal, absoluteTolerance, relativeTolerance); Analyzer.AnalyzerParams analyzerParams = new Analyzer.AnalyzerParams(irSignal.getFrequency(), timeBaseString, bitDirection, useExtents, parameterWidths, invert); @@ -179,7 +179,7 @@ private void setIrSignal(IrSignal irSignal, Decoder.AbstractDecodesCollection +