diff --git a/src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java b/src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java index 52d67203..39afb1ff 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java @@ -20,11 +20,13 @@ import java.net.URI; import java.net.URISyntaxException; import org.harctoolbox.guicomponents.GuiUtils; +import org.harctoolbox.ircore.ThisCannotHappenException; /** * The mandatory about popup ;-). * */ +@SuppressWarnings("serial") public final class AboutPopup extends javax.swing.JDialog { private GuiUtils guiUtils; @@ -39,15 +41,21 @@ public final class AboutPopup extends javax.swing.JDialog { public AboutPopup(java.awt.Frame parent, boolean modal) { super(parent, modal); if (!(parent instanceof GuiMain)) - throw new RuntimeException("Programming error"); + throw new ThisCannotHappenException("Programming error"); GuiMain guiMain = (GuiMain) parent; guiUtils = guiMain.getGuiUtils(); irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version - + "; Database version " + guiMain.getIrpDatabase().getVersion(); + + "; Database version ?"; initComponents(); } + public void setVersion(String irpDatabaseVersion) { + irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version + + "; Database version " + irpDatabaseVersion; + versionLabel2.setText(irpTransmogrifierVersion); + } + /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is diff --git a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java index e201fa55..14884f1c 100755 --- a/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java @@ -106,6 +106,7 @@ import org.harctoolbox.remotelocator.NotFoundException; import org.xml.sax.SAXException; +@SuppressWarnings("serial") public final class GuiMain extends javax.swing.JFrame { private final static String ISSUES_URL = "https://github.com/bengtmartensson/IrScrutinizer/issues"; @@ -225,14 +226,12 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li loadLibraries(); setupGuiUtils(); setupTables(); - setupIrpDatabase(); // must come before initComponents + setupIrpDatabaseAndDecoder(); // must come before initComponents setupImporters(); - setupDecoder(); loadExportFormats(); // must come before initComponents initComponents(); if (!LircHardware.isLibraryLoaded()) sendingHardwareTabbedPane.remove(devLircPanel); - girrImporter.setIrpRendererBean(irpMasterBean); tweakTables(); tweakFrame(); setupRepeatFinder(); @@ -253,7 +252,7 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li * @throws IOException * @throws ParserConfigurationException * @throws SAXException - * @throws IrpParseException + * @throws IrpParseException */ GuiMain() throws IOException, ParserConfigurationException, SAXException, IrpParseException { this(System.getProperty("user.dir") + "/target"); @@ -339,18 +338,24 @@ private void setupTables() { tableUtils = new TableUtils(guiUtils); } - private void setupIrpDatabase() throws IOException, IrpParseException, SAXException { + private void setupIrpDatabaseAndDecoder() throws IOException, IrpParseException, SAXException { List 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); + IrpDatabase newIrpDatabase = new IrpDatabase(configFiles); properties.addSecondaryIrpProtocolsPathChangeListener((String name1, Object oldValue, Object newValue) -> { secondaryRemoveMenuItem.setEnabled(!((String) newValue).isEmpty()); }); + setupIrpDatabaseAndDecoder(newIrpDatabase); + } + + private void setupIrpDatabaseAndDecoder(IrpDatabase newIrpDatabase) throws IrpParseException { + irpDatabase = newIrpDatabase; + setupDecoder(); + Command.setIrpDatabase(irpDatabase); } private void setupImporters() throws MalformedURLException, IrpParseException { @@ -473,7 +478,7 @@ private void setupIctImporter() { private void setupGirrImporter() throws MalformedURLException { Command.setAcceptEmptyCommands(properties.getAllowEmptyGirrCommands()); - girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), irpDatabase); + girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), this); properties.addGirrSchemaLocationChangeListener((String name1, Object oldValue, Object newValue) -> { try { girrImporter.setUrl(new URL((String)newValue)); @@ -1452,7 +1457,7 @@ private void scrutinizeSignal() { guiUtils.error("Unspecified error: \"" + ex.getMessage() + "\", please report."); } } - + /** * Invoke the decoding on the string given as argument. * Meant for testing only- @@ -1485,10 +1490,6 @@ GuiUtils getGuiUtils() { return guiUtils; } - IrpDatabase getIrpDatabase() { - return this.irpDatabase; - } - private void updateOutputFormat(OutputTextFormat format) { updateOutputFormat(format.ordinal()); } @@ -2148,6 +2149,19 @@ private void transformNameActionPerformed(javax.swing.JTable table, NamedIrSigna model.namesTransform(transformation, rows); } + public void patchProtocols(IrpDatabase newProtocols) { + if (newProtocols.isEmpty()) + return; + irpDatabase.patch(newProtocols); + irpMasterBean.updateProtocols(); + try { + setupDecoder(); + Command.setIrpDatabase(irpDatabase); + } catch (IrpParseException ex) { + guiUtils.error(ex); + } + } + /** * 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 @@ -7045,6 +7059,7 @@ private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN aboutBox = new AboutPopup(this, false); aboutBox.setLocationRelativeTo(this); } + aboutBox.setVersion(irpDatabase.getVersion()); aboutBox.setVisible(true); }//GEN-LAST:event_aboutMenuItemActionPerformed @@ -8104,7 +8119,7 @@ private void irpProtocolsSelectMenuItemActionPerformed(java.awt.event.ActionEven properties.setIrpProtocolsPath(f.getAbsolutePath()); try { - setupIrpDatabase(); + setupIrpDatabaseAndDecoder(); } catch (IOException | IrpParseException | SAXException ex) { guiUtils.error(ex); } @@ -9183,7 +9198,7 @@ private void secondaryIrpProtocolsSelectMenuItemActionPerformed(java.awt.event.A guiUtils.message("Secondary IrpProtocol file set to " + f.getAbsolutePath() + "."); } try { - setupIrpDatabase(); + setupIrpDatabaseAndDecoder(); } catch (IOException | IrpParseException | SAXException ex) { guiUtils.error(ex); } @@ -9205,7 +9220,7 @@ private void secondaryIrpProtocolsEditMenuItemActionPerformed(java.awt.event.Act private void irpProtocolsReloadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpProtocolsReloadMenuItemActionPerformed try { - setupIrpDatabase(); + setupIrpDatabaseAndDecoder(); } catch (IOException | IrpParseException | SAXException ex) { guiUtils.error(ex); } diff --git a/src/main/java/org/harctoolbox/irscrutinizer/importer/GirrImporter.java b/src/main/java/org/harctoolbox/irscrutinizer/importer/GirrImporter.java index ac33cdd8..e8435fe7 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/importer/GirrImporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/importer/GirrImporter.java @@ -18,7 +18,6 @@ package org.harctoolbox.irscrutinizer.importer; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -35,10 +34,10 @@ import org.harctoolbox.girr.Remote; import org.harctoolbox.girr.RemoteSet; import org.harctoolbox.girr.XmlStatic; -import org.harctoolbox.guicomponents.IrpRenderBean; import org.harctoolbox.ircore.InvalidArgumentException; import org.harctoolbox.ircore.IrCoreUtils; import org.harctoolbox.irp.IrpDatabase; +import org.harctoolbox.irscrutinizer.GuiMain; import org.harctoolbox.xml.XmlUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -51,22 +50,19 @@ */ public class GirrImporter extends RemoteSetImporter implements IReaderImporter { public static final String homeUrl = "http://www.harctoolbox.org/girr"; - private static final Logger logger = Logger.getLogger(GirrImporter.class.getName()); private transient Schema schema; private URL url; private boolean validate; - private final IrpDatabase irpDatabase; - //private final SetaccumulatedProtocols = new HashSet<>(4); - private IrpRenderBean irpMasterBean; + private final GuiMain guiMain; - public GirrImporter(boolean validate, URL url, IrpDatabase irpDatabase) { + public GirrImporter(boolean validate, URL url, GuiMain guiMain) { super(); schema = null; this.url = url; this.validate = validate; - this.irpDatabase = irpDatabase; + this.guiMain = guiMain; } /** @@ -231,32 +227,13 @@ public String getFormatName() { return "Girr"; } - public RemoteSet getRemoteSet(File file) throws IOException, FileNotFoundException, ParseException, InvalidArgumentException { + public RemoteSet getRemoteSet(File file) throws IOException, ParseException, InvalidArgumentException { possiblyZipLoad(file, IrCoreUtils.UTF8_NAME); return remoteSet; } private void accumulateProtocols(String origin) { IrpDatabase newProtocols = remoteSet.getIrpDatabase(); - // This for branch IrpTransmogrifier/setProtocolDocumentation, i.e. IrpTransmogrifier 1.3.* -// for (NamedProtocol p : newProtocols) { -// DocumentFragment doc = p.getDocumentation(); -// if (doc == null) { -// try { -// newProtocols.setDocumentation(p.getName(), "Protocol imported from " + origin); -// } catch (UnknownProtocolException ex) { -// throw new ThisCannotHappenException(ex); -// } -// } -// } - if (!newProtocols.isEmpty()) { -// accumulatedProtocols.addAll(newProtocols.getKeys()); - irpDatabase.patch(newProtocols); - irpMasterBean.updateProtocols(); - } - } - - public void setIrpRendererBean(IrpRenderBean irpMasterBean) { - this.irpMasterBean = irpMasterBean; + guiMain.patchProtocols(newProtocols); } }