Skip to content

Commit

Permalink
Parametric and raw remote table now has search. Resolves #387.
Browse files Browse the repository at this point in the history
  • Loading branch information
bengtmartensson committed Dec 30, 2023
1 parent d80dd47 commit 8250c4b
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,20 @@
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator27">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="searchParametrizedMenuItem">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+F"/>
</Property>
<Property name="text" type="java.lang.String" value="Search name..."/>
<Property name="toolTipText" type="java.lang.String" value="Selects all commands containing a particular string"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="searchParametrizedMenuItemActionPerformed"/>
</Events>
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator43">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="parametrizedPasteColumnMenuItem">
<Properties>
<Property name="text" type="java.lang.String" value="Paste in column"/>
Expand Down Expand Up @@ -869,6 +883,20 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="rawCopySelectionMenuItemActionPerformed"/>
</Events>
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator44">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="searchRawMenuItem">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+F"/>
</Property>
<Property name="text" type="java.lang.String" value="Search name..."/>
<Property name="toolTipText" type="java.lang.String" value="Select all commands which names contain a given string"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="searchRawMenuItemActionPerformed"/>
</Events>
</MenuItem>
<Component class="javax.swing.JPopupMenu$Separator" name="jSeparator39">
</Component>
<MenuItem class="javax.swing.JMenuItem" name="rawPasteColumnMenuItem">
Expand Down Expand Up @@ -3013,6 +3041,7 @@
</Properties>
<Events>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="parameterTableMouseReleased"/>
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="parameterTableKeyReleased"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_SerializeTo" type="java.lang.String" value="GuiMain_parameterTable"/>
Expand Down Expand Up @@ -3079,6 +3108,7 @@
<Events>
<EventHandler event="mousePressed" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="rawTableMousePressed"/>
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="rawTableMouseReleased"/>
<EventHandler event="keyReleased" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="rawTableKeyReleased"/>
</Events>
</Component>
</SubComponents>
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand Down Expand Up @@ -2175,6 +2176,8 @@ private void initComponents() {
parametrizedCopyAllMenuItem = new javax.swing.JMenuItem();
parametrizedCopySelectionMenuItem = new javax.swing.JMenuItem();
jSeparator27 = new javax.swing.JPopupMenu.Separator();
searchParametrizedMenuItem = new javax.swing.JMenuItem();
jSeparator43 = new javax.swing.JPopupMenu.Separator();
parametrizedPasteColumnMenuItem = new javax.swing.JMenuItem();
jSeparator40 = new javax.swing.JPopupMenu.Separator();
hideColumnMenuItem1 = new javax.swing.JMenuItem();
Expand Down Expand Up @@ -2231,6 +2234,8 @@ private void initComponents() {
jSeparator28 = new javax.swing.JPopupMenu.Separator();
rawCopyAllMenuItem = new javax.swing.JMenuItem();
rawCopySelectionMenuItem = new javax.swing.JMenuItem();
jSeparator44 = new javax.swing.JPopupMenu.Separator();
searchRawMenuItem = new javax.swing.JMenuItem();
jSeparator39 = new javax.swing.JPopupMenu.Separator();
rawPasteColumnMenuItem = new javax.swing.JMenuItem();
jSeparator29 = new javax.swing.JPopupMenu.Separator();
Expand Down Expand Up @@ -3020,6 +3025,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
parameterTablePopupMenu.add(parametrizedCopySelectionMenuItem);
parameterTablePopupMenu.add(jSeparator27);

searchParametrizedMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_DOWN_MASK));
searchParametrizedMenuItem.setText("Search name...");
searchParametrizedMenuItem.setToolTipText("Selects all commands containing a particular string");
searchParametrizedMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchParametrizedMenuItemActionPerformed(evt);
}
});
parameterTablePopupMenu.add(searchParametrizedMenuItem);
parameterTablePopupMenu.add(jSeparator43);

parametrizedPasteColumnMenuItem.setText("Paste in column");
parametrizedPasteColumnMenuItem.setToolTipText("Paste clipboard into column, starting with selected row");
parametrizedPasteColumnMenuItem.addActionListener(new java.awt.event.ActionListener() {
Expand Down Expand Up @@ -3416,6 +3432,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
rawTablePopupMenu.add(rawCopySelectionMenuItem);
rawTablePopupMenu.add(jSeparator44);

searchRawMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_DOWN_MASK));
searchRawMenuItem.setText("Search name...");
searchRawMenuItem.setToolTipText("Select all commands which names contain a given string");
searchRawMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
searchRawMenuItemActionPerformed(evt);
}
});
rawTablePopupMenu.add(searchRawMenuItem);
rawTablePopupMenu.add(jSeparator39);

rawPasteColumnMenuItem.setText("Paste in column");
Expand Down Expand Up @@ -3759,6 +3786,11 @@ public void mouseReleased(java.awt.event.MouseEvent evt) {
parameterTableMouseReleased(evt);
}
});
parameterTable.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
parameterTableKeyReleased(evt);
}
});
parameterTableScrollPane.setViewportView(parameterTable);
parameterTable.setColumnModel(parameterTableColumnModel);

Expand Down Expand Up @@ -3791,6 +3823,11 @@ public void mouseReleased(java.awt.event.MouseEvent evt) {
rawTableMouseReleased(evt);
}
});
rawTable.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
rawTableKeyReleased(evt);
}
});
rawTableScrollPane.setViewportView(rawTable);
rawTable.setColumnModel(this.rawTableColumnModel);

Expand Down Expand Up @@ -9447,6 +9484,27 @@ private void deleteEmptyRawSignalsMenuItemActionPerformed(java.awt.event.ActionE
rawTableModel.deleteEmptySignals();
}//GEN-LAST:event_deleteEmptyRawSignalsMenuItemActionPerformed

private void searchParametrizedMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchParametrizedMenuItemActionPerformed
tableUtils.searchNameInTable(parameterTable);
}//GEN-LAST:event_searchParametrizedMenuItemActionPerformed

private void parameterTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_parameterTableKeyReleased
tableKeyReleased(parameterTable, evt);
}//GEN-LAST:event_parameterTableKeyReleased

private void rawTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rawTableKeyReleased
tableKeyReleased(rawTable, evt);
}//GEN-LAST:event_rawTableKeyReleased

private void searchRawMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchRawMenuItemActionPerformed
tableUtils.searchNameInTable(rawTable);
}//GEN-LAST:event_searchRawMenuItemActionPerformed

private void tableKeyReleased(JTable table, KeyEvent evt) {
if (evt.getModifiersEx() == java.awt.event.InputEvent.CTRL_DOWN_MASK) {
tableUtils.searchNameInTable(table);
}
}
//<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 @@ -9777,6 +9835,8 @@ private void deleteEmptyRawSignalsMenuItemActionPerformed(java.awt.event.ActionE
private javax.swing.JPopupMenu.Separator jSeparator40;
private javax.swing.JPopupMenu.Separator jSeparator41;
private javax.swing.JPopupMenu.Separator jSeparator42;
private javax.swing.JPopupMenu.Separator jSeparator43;
private javax.swing.JPopupMenu.Separator jSeparator44;
private javax.swing.JPopupMenu.Separator jSeparator5;
private javax.swing.JPopupMenu.Separator jSeparator6;
private javax.swing.JPopupMenu.Separator jSeparator7;
Expand Down Expand Up @@ -9915,6 +9975,8 @@ private void deleteEmptyRawSignalsMenuItemActionPerformed(java.awt.event.ActionE
private javax.swing.JButton scrutinizeRemoteHelpButton;
private javax.swing.JButton scrutinizeSignalHelpButton;
private javax.swing.JMenuItem scrutinizeSignalProtocolDocuMenuItem;
private javax.swing.JMenuItem searchParametrizedMenuItem;
private javax.swing.JMenuItem searchRawMenuItem;
private javax.swing.JMenuItem sendMenuItem;
private javax.swing.JButton sendingCommandFusionHelpButton;
private javax.swing.JButton sendingDevLircHardwareHelpButton;
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/harctoolbox/irscrutinizer/TableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -194,6 +195,30 @@ void printTableSelectedRows(JTable table) {
}
}

void searchNameInTable(JTable table, String fragment) {
// assumes table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.clearSelection();
NamedIrSignal.LearnedIrSignalTableModel tableModel = (NamedIrSignal.LearnedIrSignalTableModel) table.getModel();
for (int i = 0; i < table.getRowCount(); i++) {
NamedIrSignal cmd = tableModel.getNamedIrSignal(i);
String name = cmd.getName();
if (name.toUpperCase(Locale.US).contains(fragment.toUpperCase(Locale.US))) {
int viewRow = table.convertRowIndexToView(i);
table.addRowSelectionInterval(viewRow, viewRow);
}
}
int selected = table.getSelectedRow();
if (selected != -1)
table.scrollRectToVisible(table.getCellRect(selected, 0, true));
}

void searchNameInTable(JTable table) {
String fragment = guiUtils.getInput("Enter string to seach for", "Search request", "");
if (fragment == null) // Cancel pressed
return;
searchNameInTable(table, fragment);
}

Command commandTableSelectedRow(JTable table) throws ErroneousSelectionException, GirrException {
barfIfNotExactlyOneSelected(table);
return commandTableSelected(table).values().iterator().next();
Expand Down

0 comments on commit 8250c4b

Please sign in to comment.