Skip to content

Commit

Permalink
Implemented secondary IrpProtocols file.
Browse files Browse the repository at this point in the history
This is one half of #294.
  • Loading branch information
bengtmartensson committed Jan 14, 2024
1 parent d2317e5 commit 6ff4acb
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 26 deletions.
45 changes: 38 additions & 7 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.form
Original file line number Diff line number Diff line change
Expand Up @@ -1956,37 +1956,68 @@
<Property name="text" type="java.lang.String" value="IRP protocol database"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="irpProtocolsSelectMenuItem">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/Crystal-Clear/22x22/actions/fileopen.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Select..."/>
<Property name="toolTipText" type="java.lang.String" value="Select IrpProtocols.xml to use."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="irpProtocolsSelectMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="irpProtocolsEditMenuItem">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/Crystal-Clear/22x22/actions/edit.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Open..."/>
<Property name="text" type="java.lang.String" value="Edit..."/>
<Property name="toolTipText" type="java.lang.String" value="Edit selected IrpProtocols.xml."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="irpProtocolsEditMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="irpProtocolsSelectMenuItem">
<MenuItem class="javax.swing.JPopupMenu$Separator" name="jSeparator45">
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="secondaryIrpProtocolsSelectMenuItem">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/Crystal-Clear/22x22/actions/fileopen.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Select..."/>
<Property name="text" type="java.lang.String" value="Select secondary..."/>
<Property name="toolTipText" type="java.lang.String" value="Select a private version of IrpProtocols. to extend the standard one."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="irpProtocolsSelectMenuItemActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="secondaryIrpProtocolsSelectMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="irpFormatsIniReloadMenuItem">
<MenuItem class="javax.swing.JMenuItem" name="secondaryIrpProtocolsEditMenuItem">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/Crystal-Clear/22x22/actions/edit.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Edit secondary..."/>
<Property name="toolTipText" type="java.lang.String" value="Edit the private extension file for IrpProtocols.xml"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="secondaryIrpProtocolsEditMenuItemActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JPopupMenu$Separator" name="jSeparator46">
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="irpProtocolsReloadMenuItem">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/icons/Crystal-Clear/22x22/actions/reload.png"/>
</Property>
<Property name="text" type="java.lang.String" value="Reload"/>
<Property name="toolTipText" type="java.lang.String" value="Reload data base (not yet implemented)"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="irpProtocolsReloadMenuItemActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
Expand Down
125 changes: 106 additions & 19 deletions src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.comm.DriverGenUnix;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
Expand Down Expand Up @@ -223,7 +225,7 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li
loadLibraries();
setupGuiUtils();
setupTables();
setupIrpDatabase();
setupIrpDatabase(); // must come before initComponents
setupImporters();
setupDecoder();
loadExportFormats(); // must come before initComponents
Expand Down Expand Up @@ -322,9 +324,14 @@ private void setupTables() {
tableUtils = new TableUtils(guiUtils);
}

// must come before initComponents
private void setupIrpDatabase() throws IOException, IrpParseException, SAXException {
irpDatabase = new IrpDatabase(properties.mkPathAbsolute(properties.getIrpProtocolsPath()));
List<File> configFiles = new ArrayList<>(4);
configFiles.add(new File(properties.mkPathAbsolute(properties.getIrpProtocolsPath())));
String secondary = properties.getSecondaryIrpProtocolsPath();
if (!secondary.isEmpty())
configFiles.add(new File(secondary));

irpDatabase = new IrpDatabase(configFiles);
Command.setIrpDatabase(irpDatabase);
}

Expand Down Expand Up @@ -2580,9 +2587,13 @@ private void initComponents() {
removeDefaultedParametersCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
ignoreLeadingGarbageCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
irpProtocolsIniMenu = new javax.swing.JMenu();
irpProtocolsEditMenuItem = new javax.swing.JMenuItem();
irpProtocolsSelectMenuItem = new javax.swing.JMenuItem();
irpFormatsIniReloadMenuItem = new javax.swing.JMenuItem();
irpProtocolsEditMenuItem = new javax.swing.JMenuItem();
jSeparator45 = new javax.swing.JPopupMenu.Separator();
secondaryIrpProtocolsSelectMenuItem = new javax.swing.JMenuItem();
secondaryIrpProtocolsEditMenuItem = new javax.swing.JMenuItem();
jSeparator46 = new javax.swing.JPopupMenu.Separator();
irpProtocolsReloadMenuItem = new javax.swing.JMenuItem();
exportFormatsMenu = new javax.swing.JMenu();
exportFormatsEditMenuItem = new javax.swing.JMenuItem();
exportFormatsSelectMenuItem = new javax.swing.JMenuItem();
Expand Down Expand Up @@ -6621,29 +6632,56 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
irpProtocolsIniMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/apps/database.png"))); // NOI18N
irpProtocolsIniMenu.setText("IRP protocol database");

irpProtocolsSelectMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/fileopen.png"))); // NOI18N
irpProtocolsSelectMenuItem.setText("Select...");
irpProtocolsSelectMenuItem.setToolTipText("Select IrpProtocols.xml to use.");
irpProtocolsSelectMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
irpProtocolsSelectMenuItemActionPerformed(evt);
}
});
irpProtocolsIniMenu.add(irpProtocolsSelectMenuItem);

irpProtocolsEditMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/edit.png"))); // NOI18N
irpProtocolsEditMenuItem.setText("Open...");
irpProtocolsEditMenuItem.setText("Edit...");
irpProtocolsEditMenuItem.setToolTipText("Edit selected IrpProtocols.xml.");
irpProtocolsEditMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
irpProtocolsEditMenuItemActionPerformed(evt);
}
});
irpProtocolsIniMenu.add(irpProtocolsEditMenuItem);
irpProtocolsIniMenu.add(jSeparator45);

irpProtocolsSelectMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/fileopen.png"))); // NOI18N
irpProtocolsSelectMenuItem.setText("Select...");
irpProtocolsSelectMenuItem.addActionListener(new java.awt.event.ActionListener() {
secondaryIrpProtocolsSelectMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/fileopen.png"))); // NOI18N
secondaryIrpProtocolsSelectMenuItem.setText("Select secondary...");
secondaryIrpProtocolsSelectMenuItem.setToolTipText("Select a private version of IrpProtocols. to extend the standard one.");
secondaryIrpProtocolsSelectMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
irpProtocolsSelectMenuItemActionPerformed(evt);
secondaryIrpProtocolsSelectMenuItemActionPerformed(evt);
}
});
irpProtocolsIniMenu.add(irpProtocolsSelectMenuItem);
irpProtocolsIniMenu.add(secondaryIrpProtocolsSelectMenuItem);

irpFormatsIniReloadMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/reload.png"))); // NOI18N
irpFormatsIniReloadMenuItem.setText("Reload");
irpFormatsIniReloadMenuItem.setToolTipText("Reload data base (not yet implemented)");
irpFormatsIniReloadMenuItem.setEnabled(false);
irpProtocolsIniMenu.add(irpFormatsIniReloadMenuItem);
secondaryIrpProtocolsEditMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/edit.png"))); // NOI18N
secondaryIrpProtocolsEditMenuItem.setText("Edit secondary...");
secondaryIrpProtocolsEditMenuItem.setToolTipText("Edit the private extension file for IrpProtocols.xml");
secondaryIrpProtocolsEditMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
secondaryIrpProtocolsEditMenuItemActionPerformed(evt);
}
});
irpProtocolsIniMenu.add(secondaryIrpProtocolsEditMenuItem);
irpProtocolsIniMenu.add(jSeparator46);

irpProtocolsReloadMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Crystal-Clear/22x22/actions/reload.png"))); // NOI18N
irpProtocolsReloadMenuItem.setText("Reload");
irpProtocolsReloadMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
irpProtocolsReloadMenuItemActionPerformed(evt);
}
});
irpProtocolsIniMenu.add(irpProtocolsReloadMenuItem);

optionsMenu.add(irpProtocolsIniMenu);

Expand Down Expand Up @@ -8119,11 +8157,15 @@ private void irpProtocolsEditMenuItemActionPerformed(java.awt.event.ActionEvent
private void irpProtocolsSelectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpProtocolsSelectMenuItemActionPerformed
String oldDir = new File(properties.mkPathAbsolute(properties.getIrpProtocolsPath())).getParent();
File f = SelectFile.selectFile(this, "Select protocol file (typically IrpProtocols.xml)", oldDir, false, false, "XML files (*.xml)", "xml");
if (f == null || f.getAbsolutePath().equals(properties.mkPathAbsolute(properties.getIrpProtocolsPath())))
if (f == null)
return;

properties.setIrpProtocolsPath(f.getAbsolutePath());
guiUtils.warning("The program must be restarted for the changes to take effect.");
try {
setupIrpDatabase();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
}//GEN-LAST:event_irpProtocolsSelectMenuItemActionPerformed

private void exportFormatsEditMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportFormatsEditMenuItemActionPerformed
Expand Down Expand Up @@ -9278,6 +9320,47 @@ private void searchRawMenuItemActionPerformed(java.awt.event.ActionEvent evt) {/
tableUtils.searchNameInTable(rawTable);
}//GEN-LAST:event_searchRawMenuItemActionPerformed

private void secondaryIrpProtocolsSelectMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secondaryIrpProtocolsSelectMenuItemActionPerformed
String secondary = properties.getSecondaryIrpProtocolsPath();
String selectorStartDir = secondary.isEmpty() ? System.getProperty("user.home") : new File(properties.mkPathAbsolute(secondary)).getParent();
File f = SelectFile.selectFile(this, "Select secondary protocol file", selectorStartDir, false, false, "XML files (*.xml)", "xml");
if (f == null)
return;
if (f.toString().equals("/dev/null") || f.toString().equalsIgnoreCase("NULL:")) {
properties.setSecondaryIrpProtocolsPath("");
guiUtils.message("secondary IrpProtocol was removed.");
} else {
properties.setSecondaryIrpProtocolsPath(f.getAbsolutePath());
}
try {
setupIrpDatabase();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
}//GEN-LAST:event_secondaryIrpProtocolsSelectMenuItemActionPerformed

private void secondaryIrpProtocolsEditMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_secondaryIrpProtocolsEditMenuItemActionPerformed
try {
String secondary = properties.getSecondaryIrpProtocolsPath();
if (secondary.isEmpty()) {
guiUtils.error("No secondary IrpProtocol selected. Nothing to edit.");
return;
}
guiUtils.open(new File(properties.mkPathAbsolute(secondary)));
guiUtils.warning("If editing the file, changes will not take effect before you save the file, select \"reload\", (or restart the program).");
} catch (IOException ex) {
guiUtils.error(ex);
}
}//GEN-LAST:event_secondaryIrpProtocolsEditMenuItemActionPerformed

private void irpProtocolsReloadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpProtocolsReloadMenuItemActionPerformed
try {
setupIrpDatabase();
} catch (IOException | IrpParseException | SAXException ex) {
guiUtils.error(ex);
}
}//GEN-LAST:event_irpProtocolsReloadMenuItemActionPerformed

private void tableKeyReleased(JTable table, KeyEvent evt) {
if (evt.getModifiersEx() == java.awt.event.InputEvent.CTRL_DOWN_MASK) {
tableUtils.searchNameInTable(table);
Expand Down Expand Up @@ -9521,10 +9604,10 @@ private void tableKeyReleased(JTable table, KeyEvent evt) {
private javax.swing.JButton irTransWebButton;
private org.harctoolbox.guicomponents.IrWidgetBean irWidgetBean;
private javax.swing.JButton irWidgetHelpButton;
private javax.swing.JMenuItem irpFormatsIniReloadMenuItem;
private org.harctoolbox.guicomponents.IrpRenderBean irpMasterBean;
private javax.swing.JMenuItem irpProtocolsEditMenuItem;
private javax.swing.JMenu irpProtocolsIniMenu;
private javax.swing.JMenuItem irpProtocolsReloadMenuItem;
private javax.swing.JMenuItem irpProtocolsSelectMenuItem;
private javax.swing.JMenuItem irpTransmogrifierHelpMenuItem;
private javax.swing.JPanel irtransImportPanel;
Expand Down Expand Up @@ -9603,6 +9686,8 @@ private void tableKeyReleased(JTable table, KeyEvent evt) {
private javax.swing.JPopupMenu.Separator jSeparator42;
private javax.swing.JPopupMenu.Separator jSeparator43;
private javax.swing.JPopupMenu.Separator jSeparator44;
private javax.swing.JPopupMenu.Separator jSeparator45;
private javax.swing.JPopupMenu.Separator jSeparator46;
private javax.swing.JPopupMenu.Separator jSeparator5;
private javax.swing.JPopupMenu.Separator jSeparator6;
private javax.swing.JPopupMenu.Separator jSeparator7;
Expand Down Expand Up @@ -9743,6 +9828,8 @@ private void tableKeyReleased(JTable table, KeyEvent evt) {
private javax.swing.JMenuItem scrutinizeSignalProtocolDocuMenuItem;
private javax.swing.JMenuItem searchParametrizedMenuItem;
private javax.swing.JMenuItem searchRawMenuItem;
private javax.swing.JMenuItem secondaryIrpProtocolsEditMenuItem;
private javax.swing.JMenuItem secondaryIrpProtocolsSelectMenuItem;
private javax.swing.JMenuItem sendMenuItem;
private javax.swing.JButton sendingCommandFusionHelpButton;
private javax.swing.JButton sendingDevLircHardwareHelpButton;
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 @@ -107,6 +107,7 @@ this program. If not, see http://www.gnu.org/licenses/.
<!--property name="exportPersistentParams" type='boolean' default='"false"' doc='If true, parameters declared persistent in the IRP protocol (typically toggle T) are included in the parameteric export, omitted otherwise.'/-->
<property name="translateProntoFont" type="boolean" default='"true"' doc='If true, one-character Pronto button names, likely using the Pronto font, are tranlated to readable strings.'/>
<property name="irpProtocolsPath" type="string" default='"IrpProtocols.xml"' doc='Path to IrpProtocols.xml' />
<property name="secondaryIrpProtocolsPath" type="string" default='""' doc='Path to secondary IrpProtocols.xml' />
<property name="creatingUser" type="string" default='System.getProperty("user.name", "unknown")' doc='Name of the user, for documentation purposes'/>
<property name="rawSeparatorIndex" type="int" default='"0"' doc='Field separator for parsing raw files.'/>
<property name='rawNameColumn' type="int" default='"1"' doc='Column for name when parsing raw files.'/>
Expand Down

0 comments on commit 6ff4acb

Please sign in to comment.