diff --git a/src/org/openlcb/cdi/cmd/RestoreConfig.java b/src/org/openlcb/cdi/cmd/RestoreConfig.java index 49cd91b3..f7986e77 100644 --- a/src/org/openlcb/cdi/cmd/RestoreConfig.java +++ b/src/org/openlcb/cdi/cmd/RestoreConfig.java @@ -40,6 +40,7 @@ public static void parseConfigFromReader(@NonNull BufferedReader reader, @NonNul try { while ((line = reader.readLine()) != null) { if (line.charAt(0) == '#') continue; + if (line.isEmpty()) continue; int pos = line.indexOf('='); if (pos < 0) { logger.log(Level.WARNING, "Failed to parse line: {0}", line); diff --git a/src/org/openlcb/cdi/impl/ConfigRepresentation.java b/src/org/openlcb/cdi/impl/ConfigRepresentation.java index 68e81341..9edcd79f 100644 --- a/src/org/openlcb/cdi/impl/ConfigRepresentation.java +++ b/src/org/openlcb/cdi/impl/ConfigRepresentation.java @@ -60,6 +60,8 @@ public class ConfigRepresentation extends DefaultPropertyListenerSupport { private final Map variables = new HashMap<>(); // Last time the progressbar was updated from the load. private long lastProgress; + + private int cacheMemoryRead; public EventNameStore eventNameStore; @@ -98,10 +100,10 @@ private void triggerFetchCdi() { public void progressNotify(long bytesRead, long totalBytes) { lastProgress = new Date().getTime(); if (totalBytes > 0) { - setState(String.format("Loading: %.2f%% complete", bytesRead * 100.0 / + setState(String.format("Loading display format: %.2f%% complete", bytesRead * 100.0 / totalBytes)); } else { - setState(String.format("Loading: %d bytes complete", bytesRead)); + setState(String.format("Loading display format: %d bytes complete", bytesRead)); } } @@ -139,12 +141,18 @@ public void propertyChange(PropertyChangeEvent propertyChangeEvent) { .UPDATE_LOADING_COMPLETE)) { synchronized (this) { if (--pendingCacheFills == 0) { - firePropertyChange(UPDATE_CACHE_COMPLETE, null, null); + firePropertyChange(UPDATE_CACHE_COMPLETE, null, 1); for (MemorySpaceCache sp : spaces.values()) { sp.removePropertyChangeListener(prefillListener); } } } + } else if (propertyChangeEvent.getPropertyName().equals(MemorySpaceCache + .LOADING_RANGE)) { + cacheMemoryRead += (Integer)propertyChangeEvent.getNewValue(); + setState(String.format("Loading configuration data: %d bytes complete", cacheMemoryRead)); + firePropertyChange(UPDATE_STATE, null, cacheMemoryRead); + } } }; diff --git a/src/org/openlcb/cdi/impl/MemorySpaceCache.java b/src/org/openlcb/cdi/impl/MemorySpaceCache.java index 3ad014a0..83ebd7a4 100644 --- a/src/org/openlcb/cdi/impl/MemorySpaceCache.java +++ b/src/org/openlcb/cdi/impl/MemorySpaceCache.java @@ -24,6 +24,8 @@ public class MemorySpaceCache { // This event will be fired when the cache is completely pre-filled. public static final String UPDATE_LOADING_COMPLETE = "UPDATE_LOADING_COMPLETE"; + // This event will be fired as each range is read + public static final String LOADING_RANGE = "LOADING_RANGE"; // This event will be fired on the registered data listeners. public static final String UPDATE_DATA = "UPDATE_DATA"; private static final Logger logger = Logger.getLogger(MemorySpaceCache.class.getName()); @@ -224,6 +226,7 @@ private void loadRange() { if (count > 64) { count = 64; } + firePropertyChange(LOADING_RANGE, null, count); final int fcount = count; access.doRead(currentRangeNextOffset, space, count, new MemoryConfigurationService.McsReadHandler() { diff --git a/src/org/openlcb/cdi/swing/CdiPanel.java b/src/org/openlcb/cdi/swing/CdiPanel.java index 39d7c50a..7d148b63 100644 --- a/src/org/openlcb/cdi/swing/CdiPanel.java +++ b/src/org/openlcb/cdi/swing/CdiPanel.java @@ -108,6 +108,7 @@ import util.CollapsiblePanel; import util.WrapLayout; +import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_CACHE_COMPLETE; import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_ENTRY_DATA; import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_REP; import static org.openlcb.cdi.impl.ConfigRepresentation.UPDATE_STATE; @@ -670,7 +671,7 @@ private void addLoadingListener() { loadingListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { - if (event.getPropertyName().equals(UPDATE_REP)) { + if (event.getPropertyName().equals(UPDATE_CACHE_COMPLETE)) { displayCdi(); } else if (event.getPropertyName().equals(UPDATE_STATE)) { loadingText.setText(rep.getStatus()); diff --git a/test/org/openlcb/cdi/impl/ConfigRepresentationTest.java b/test/org/openlcb/cdi/impl/ConfigRepresentationTest.java index 6acd0cf9..c44065b7 100644 --- a/test/org/openlcb/cdi/impl/ConfigRepresentationTest.java +++ b/test/org/openlcb/cdi/impl/ConfigRepresentationTest.java @@ -45,7 +45,7 @@ public void testComplexCdiLoad() throws Exception { ConfigRepresentation rep = new ConfigRepresentation(iface, remoteNode); // Since all of our memory configuration commands execute inline, the representation will // be ready by the time it returns. - Assert.assertEquals("Representation complete.", rep.getStatus()); + Assert.assertEquals("Loading configuration data: 73 bytes complete", rep.getStatus()); Assert.assertNotNull(rep.getRoot()); ConfigRepresentation.CdiContainer cont = rep.getRoot();