Skip to content

Commit

Permalink
Allow empty commands to be imported in Girr. Resolves #511.
Browse files Browse the repository at this point in the history
This can be turned o and off through Options -> Import options -> Accept empty Girr commands on import.
  • Loading branch information
bengtmartensson committed Dec 27, 2023
1 parent 0d03716 commit 6c4e325
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteDefaultedSignalsMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="deleteEmptyParametrizedSignalsMenuItem">
<Properties>
<Property name="text" type="java.lang.String" value="Delete empty Signals"/>
<Property name="toolTipText" type="java.lang.String" value="Remove all signals that do not have content."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteEmptyParametrizedSignalsMenuItemActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
Expand Down Expand Up @@ -916,6 +925,15 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="clearRawCommentMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="deleteEmptyRawSignalsMenuItem">
<Properties>
<Property name="text" type="java.lang.String" value="Delete empty Signals"/>
<Property name="toolTipText" type="java.lang.String" value="Remove all signals that do not have a content."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="deleteEmptyRawSignalsMenuItemActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Container>
<Container class="org.harctoolbox.guicomponents.CopyPastePopupMenu" name="copyPastePopupMenu">
Expand Down Expand Up @@ -2079,6 +2097,17 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="girrSchemaLocationMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JCheckBoxMenuItem" name="girrAcceptEmptyCommandsCheckBoxMenuItem">
<Properties>
<Property name="selected" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="properties.getAllowEmptyGirrCommands()" type="code"/>
</Property>
<Property name="text" type="java.lang.String" value="Accept empty Girr commands on import"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="girrAcceptEmptyCommandsCheckBoxMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JCheckBoxMenuItem" name="rejectLircCodeImports">
<Properties>
<Property name="selected" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
Expand Down
56 changes: 55 additions & 1 deletion src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
Expand All @@ -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

//<editor-fold defaultstate="collapsed" desc="Automatic variable declarations">
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPopupMenu CCFCodePopupMenu;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<GirrImporter> girrFileImporterBean;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/harctoolbox/irscrutinizer/NamedIrSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public String toPrintString() {
return csvString(", ");
}

public abstract boolean isEmpty();

/**
*
*/
Expand Down Expand Up @@ -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();
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/org/harctoolbox/irscrutinizer/RawIrSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void setInvert(boolean aInvert) {
private void setIrSignal(IrSignal irSignal, Decoder.AbstractDecodesCollection<? extends ElementaryDecode> 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);
Expand All @@ -179,7 +179,7 @@ private void setIrSignal(IrSignal irSignal, Decoder.AbstractDecodesCollection<?
}

private void setIrSignal(IrSignal irSignal) {
setIrSignal(irSignal, invokeDecoder ? decoder.decodeLoose(irSignal, decoderParameters) : null);
setIrSignal(irSignal, irSignal != null && invokeDecoder ? decoder.decodeLoose(irSignal, decoderParameters) : null);
}

private void setIrSignal(ModulatedIrSequence irSequence) {
Expand Down Expand Up @@ -263,6 +263,11 @@ public String toPrintString() {
return csvString(", ");
}

@Override
public boolean isEmpty() {
return irSignal == null || irSignal.isEmpty();
}

private static class CapturedIrSignalColumns extends NamedIrSignal.AbstractColumnFunction {

private static final int[] widths = {
Expand Down Expand Up @@ -338,14 +343,14 @@ public Object[] toObjectArray(RawIrSignal cir) {
Object[] result = new Object[]{
cir.getNumeral(),
cir.getDate(),
((IrSequence) irSignal.getIntroSequence()).toString(true, ","),
((IrSequence) irSignal.getRepeatSequence()).toString(true, ","),
((IrSequence) irSignal.getEndingSequence()).toString(true, ","),
irSignal != null ? ((IrSequence) irSignal.getIntroSequence()).toString(true, ",") : "",
irSignal != null ? ((IrSequence) irSignal.getRepeatSequence()).toString(true, ",") : "",
irSignal != null ? ((IrSequence) irSignal.getEndingSequence()).toString(true, ",") : "",
cir.getName(),
cir.getDecodeString(),
cir.getAnalyzerString(),
cir.getComment(),
Math.round(irSignal.getFrequency()),
irSignal != null ? Math.round(irSignal.getFrequency()) : null,
cir, // Analyze
null
};
Expand All @@ -371,6 +376,11 @@ public RawIrSignal getCapturedIrSignal(int row) {
: null;
}

@Override
NamedIrSignal getNamedIrSignal(int row) {
return getCapturedIrSignal(row);
}

@Override
public Command toCommand(int row) {
RawIrSignal rir = getCapturedIrSignal(row);
Expand Down
1 change: 1 addition & 0 deletions src/main/xml/Props.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ this program. If not, see http://www.gnu.org/licenses/.
<property name="importPaneSelectedIndex" type="int" default='"2"' doc="Index of the selected pane in the importer"/>
<property name="parametrizedRawTabbedPaneSelectedIndex" type="int" default='"0"' doc="Index of the selected pane in the CSV importer"/>
<property name="rejectLircCodeImports" type="boolean" default='"true"' doc="If true, Lirc files without timing information are rejected."/>
<property name="allowEmptyGirrCommands" type="boolean" default='"false"' doc="If true, empty Girr Commands are accepted, with just a name. Otherwise they are silently ignored."/>
<property name="chopIctImports" type="boolean" default='"false"' doc="If true, ICT imports are chopped according to the chopThreshold parameter."/>
<property name="prontoModelIndex" type="int" default='"4"' doc="Index of selected Pronto Classic model."/>
<property name="prontoScreenSizeX" type="int" default='"240"' doc="Pronto screen width" />
Expand Down

0 comments on commit 6c4e325

Please sign in to comment.