Skip to content

Commit 50aafbd

Browse files
Fix some problems in importing Girr files with embedded IRP protocol.
Resolves #542.
1 parent 643e461 commit 50aafbd

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

src/main/java/org/harctoolbox/irscrutinizer/AboutPopup.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import java.net.URI;
2121
import java.net.URISyntaxException;
2222
import org.harctoolbox.guicomponents.GuiUtils;
23+
import org.harctoolbox.ircore.ThisCannotHappenException;
2324

2425
/**
2526
* The mandatory about popup ;-).
2627
*
2728
*/
29+
@SuppressWarnings("serial")
2830
public final class AboutPopup extends javax.swing.JDialog {
2931

3032
private GuiUtils guiUtils;
@@ -39,15 +41,21 @@ public final class AboutPopup extends javax.swing.JDialog {
3941
public AboutPopup(java.awt.Frame parent, boolean modal) {
4042
super(parent, modal);
4143
if (!(parent instanceof GuiMain))
42-
throw new RuntimeException("Programming error");
44+
throw new ThisCannotHappenException("Programming error");
4345

4446
GuiMain guiMain = (GuiMain) parent;
4547
guiUtils = guiMain.getGuiUtils();
4648
irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version
47-
+ "; Database version " + guiMain.getIrpDatabase().getVersion();
49+
+ "; Database version ?";
4850
initComponents();
4951
}
5052

53+
public void setVersion(String irpDatabaseVersion) {
54+
irpTransmogrifierVersion = "IrpTransmogrifier version " + org.harctoolbox.irp.Version.version
55+
+ "; Database version " + irpDatabaseVersion;
56+
versionLabel2.setText(irpTransmogrifierVersion);
57+
}
58+
5159
/** This method is called from within the constructor to
5260
* initialize the form.
5361
* WARNING: Do NOT modify this code. The content of this method is

src/main/java/org/harctoolbox/irscrutinizer/GuiMain.java

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
import org.harctoolbox.remotelocator.NotFoundException;
107107
import org.xml.sax.SAXException;
108108

109+
@SuppressWarnings("serial")
109110
public final class GuiMain extends javax.swing.JFrame {
110111

111112
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
225226
loadLibraries();
226227
setupGuiUtils();
227228
setupTables();
228-
setupIrpDatabase(); // must come before initComponents
229+
setupIrpDatabaseAndDecoder(); // must come before initComponents
229230
setupImporters();
230-
setupDecoder();
231231
loadExportFormats(); // must come before initComponents
232232
initComponents();
233233
if (!LircHardware.isLibraryLoaded())
234234
sendingHardwareTabbedPane.remove(devLircPanel);
235-
girrImporter.setIrpRendererBean(irpMasterBean);
236235
tweakTables();
237236
tweakFrame();
238237
setupRepeatFinder();
@@ -253,7 +252,7 @@ public GuiMain(String applicationHome, String propsfilename, boolean verbose, Li
253252
* @throws IOException
254253
* @throws ParserConfigurationException
255254
* @throws SAXException
256-
* @throws IrpParseException
255+
* @throws IrpParseException
257256
*/
258257
GuiMain() throws IOException, ParserConfigurationException, SAXException, IrpParseException {
259258
this(System.getProperty("user.dir") + "/target");
@@ -339,18 +338,24 @@ private void setupTables() {
339338
tableUtils = new TableUtils(guiUtils);
340339
}
341340

342-
private void setupIrpDatabase() throws IOException, IrpParseException, SAXException {
341+
private void setupIrpDatabaseAndDecoder() throws IOException, IrpParseException, SAXException {
343342
List<File> configFiles = new ArrayList<>(4);
344343
configFiles.add(new File(properties.mkPathAbsolute(properties.getIrpProtocolsPath())));
345344
String secondary = properties.getSecondaryIrpProtocolsPath();
346345
if (!secondary.isEmpty())
347346
configFiles.add(new File(secondary));
348347

349-
irpDatabase = new IrpDatabase(configFiles);
350-
Command.setIrpDatabase(irpDatabase);
348+
IrpDatabase newIrpDatabase = new IrpDatabase(configFiles);
351349
properties.addSecondaryIrpProtocolsPathChangeListener((String name1, Object oldValue, Object newValue) -> {
352-
secondaryRemoveMenuItem.setEnabled(!((String) newValue).isEmpty());
350+
secondaryRemoveMenuItem.setEnabled(!((CharSequence) newValue).isEmpty());
353351
});
352+
setupIrpDatabaseAndDecoder(newIrpDatabase);
353+
}
354+
355+
private void setupIrpDatabaseAndDecoder(IrpDatabase newIrpDatabase) throws IrpParseException {
356+
irpDatabase = newIrpDatabase;
357+
setupDecoder();
358+
Command.setIrpDatabase(irpDatabase);
354359
}
355360

356361
private void setupImporters() throws MalformedURLException, IrpParseException {
@@ -473,7 +478,7 @@ private void setupIctImporter() {
473478

474479
private void setupGirrImporter() throws MalformedURLException {
475480
Command.setAcceptEmptyCommands(properties.getAllowEmptyGirrCommands());
476-
girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), irpDatabase);
481+
girrImporter = new GirrImporter(properties.getGirrValidate(), new URL(properties.getGirrSchemaLocation()), this);
477482
properties.addGirrSchemaLocationChangeListener((String name1, Object oldValue, Object newValue) -> {
478483
try {
479484
girrImporter.setUrl(new URL((String)newValue));
@@ -1452,7 +1457,7 @@ private void scrutinizeSignal() {
14521457
guiUtils.error("Unspecified error: \"" + ex.getMessage() + "\", please report.");
14531458
}
14541459
}
1455-
1460+
14561461
/**
14571462
* Invoke the decoding on the string given as argument.
14581463
* Meant for testing only-
@@ -1485,10 +1490,6 @@ GuiUtils getGuiUtils() {
14851490
return guiUtils;
14861491
}
14871492

1488-
IrpDatabase getIrpDatabase() {
1489-
return this.irpDatabase;
1490-
}
1491-
14921493
private void updateOutputFormat(OutputTextFormat format) {
14931494
updateOutputFormat(format.ordinal());
14941495
}
@@ -2148,6 +2149,19 @@ private void transformNameActionPerformed(javax.swing.JTable table, NamedIrSigna
21482149
model.namesTransform(transformation, rows);
21492150
}
21502151

2152+
public void patchProtocols(IrpDatabase newProtocols) {
2153+
if (newProtocols.isEmpty())
2154+
return;
2155+
irpDatabase.patch(newProtocols);
2156+
irpMasterBean.updateProtocols();
2157+
try {
2158+
setupDecoder();
2159+
Command.setIrpDatabase(irpDatabase);
2160+
} catch (IrpParseException ex) {
2161+
guiUtils.error(ex);
2162+
}
2163+
}
2164+
21512165
/**
21522166
* This method is called from within the constructor to initialize the form.
21532167
* 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
70457059
aboutBox = new AboutPopup(this, false);
70467060
aboutBox.setLocationRelativeTo(this);
70477061
}
7062+
aboutBox.setVersion(irpDatabase.getVersion());
70487063
aboutBox.setVisible(true);
70497064
}//GEN-LAST:event_aboutMenuItemActionPerformed
70507065

@@ -8104,7 +8119,7 @@ private void irpProtocolsSelectMenuItemActionPerformed(java.awt.event.ActionEven
81048119

81058120
properties.setIrpProtocolsPath(f.getAbsolutePath());
81068121
try {
8107-
setupIrpDatabase();
8122+
setupIrpDatabaseAndDecoder();
81088123
} catch (IOException | IrpParseException | SAXException ex) {
81098124
guiUtils.error(ex);
81108125
}
@@ -9183,7 +9198,7 @@ private void secondaryIrpProtocolsSelectMenuItemActionPerformed(java.awt.event.A
91839198
guiUtils.message("Secondary IrpProtocol file set to " + f.getAbsolutePath() + ".");
91849199
}
91859200
try {
9186-
setupIrpDatabase();
9201+
setupIrpDatabaseAndDecoder();
91879202
} catch (IOException | IrpParseException | SAXException ex) {
91889203
guiUtils.error(ex);
91899204
}
@@ -9205,7 +9220,7 @@ private void secondaryIrpProtocolsEditMenuItemActionPerformed(java.awt.event.Act
92059220

92069221
private void irpProtocolsReloadMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_irpProtocolsReloadMenuItemActionPerformed
92079222
try {
9208-
setupIrpDatabase();
9223+
setupIrpDatabaseAndDecoder();
92099224
} catch (IOException | IrpParseException | SAXException ex) {
92109225
guiUtils.error(ex);
92119226
}

src/main/java/org/harctoolbox/irscrutinizer/importer/GirrImporter.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.harctoolbox.irscrutinizer.importer;
1919

2020
import java.io.File;
21-
import java.io.FileNotFoundException;
2221
import java.io.IOException;
2322
import java.io.InputStream;
2423
import java.io.Reader;
@@ -35,10 +34,10 @@
3534
import org.harctoolbox.girr.Remote;
3635
import org.harctoolbox.girr.RemoteSet;
3736
import org.harctoolbox.girr.XmlStatic;
38-
import org.harctoolbox.guicomponents.IrpRenderBean;
3937
import org.harctoolbox.ircore.InvalidArgumentException;
4038
import org.harctoolbox.ircore.IrCoreUtils;
4139
import org.harctoolbox.irp.IrpDatabase;
40+
import org.harctoolbox.irscrutinizer.GuiMain;
4241
import org.harctoolbox.xml.XmlUtils;
4342
import org.w3c.dom.Document;
4443
import org.w3c.dom.Element;
@@ -51,22 +50,19 @@
5150
*/
5251
public class GirrImporter extends RemoteSetImporter implements IReaderImporter {
5352
public static final String homeUrl = "http://www.harctoolbox.org/girr";
54-
5553
private static final Logger logger = Logger.getLogger(GirrImporter.class.getName());
5654

5755
private transient Schema schema;
5856
private URL url;
5957
private boolean validate;
60-
private final IrpDatabase irpDatabase;
61-
//private final Set<String>accumulatedProtocols = new HashSet<>(4);
62-
private IrpRenderBean irpMasterBean;
58+
private final GuiMain guiMain;
6359

64-
public GirrImporter(boolean validate, URL url, IrpDatabase irpDatabase) {
60+
public GirrImporter(boolean validate, URL url, GuiMain guiMain) {
6561
super();
6662
schema = null;
6763
this.url = url;
6864
this.validate = validate;
69-
this.irpDatabase = irpDatabase;
65+
this.guiMain = guiMain;
7066
}
7167

7268
/**
@@ -231,32 +227,13 @@ public String getFormatName() {
231227
return "Girr";
232228
}
233229

234-
public RemoteSet getRemoteSet(File file) throws IOException, FileNotFoundException, ParseException, InvalidArgumentException {
230+
public RemoteSet getRemoteSet(File file) throws IOException, ParseException, InvalidArgumentException {
235231
possiblyZipLoad(file, IrCoreUtils.UTF8_NAME);
236232
return remoteSet;
237233
}
238234

239235
private void accumulateProtocols(String origin) {
240236
IrpDatabase newProtocols = remoteSet.getIrpDatabase();
241-
// This for branch IrpTransmogrifier/setProtocolDocumentation, i.e. IrpTransmogrifier 1.3.*
242-
// for (NamedProtocol p : newProtocols) {
243-
// DocumentFragment doc = p.getDocumentation();
244-
// if (doc == null) {
245-
// try {
246-
// newProtocols.setDocumentation(p.getName(), "Protocol imported from " + origin);
247-
// } catch (UnknownProtocolException ex) {
248-
// throw new ThisCannotHappenException(ex);
249-
// }
250-
// }
251-
// }
252-
if (!newProtocols.isEmpty()) {
253-
// accumulatedProtocols.addAll(newProtocols.getKeys());
254-
irpDatabase.patch(newProtocols);
255-
irpMasterBean.updateProtocols();
256-
}
257-
}
258-
259-
public void setIrpRendererBean(IrpRenderBean irpMasterBean) {
260-
this.irpMasterBean = irpMasterBean;
237+
guiMain.patchProtocols(newProtocols);
261238
}
262239
}

0 commit comments

Comments
 (0)