From a4357ef5953a20e0e2061b115e7ae626c0f9e86a Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 06:42:18 -0500 Subject: [PATCH 1/6] add more comments --- src/org/openlcb/EventNameStore.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/org/openlcb/EventNameStore.java b/src/org/openlcb/EventNameStore.java index c35b1912..aefc2199 100644 --- a/src/org/openlcb/EventNameStore.java +++ b/src/org/openlcb/EventNameStore.java @@ -16,8 +16,19 @@ */ public interface EventNameStore { + /** + * @param eventName Either a previously stored event name that is + * is associated to an event ID, or the dotted-hex form of an Event ID + * @returns an eventID from tne matching name, if any + * otherwise directly return the doted-hex input. + */ public EventID getEventID(String eventName); + /** + * @parm A valid event ID, not null + * @returns If a name has been associated with this event ID, return that name, + * otherwise an event ID from parsing the eventName as dotted-hex. + */ public String getEventName(EventID eventID); } From 96ae79a0aa4bce0a5d95759904f259e0f70da6ca Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 06:43:11 -0500 Subject: [PATCH 2/6] add new method to get event ID as dotted hex; only dotted hex in backups; refactor access to EventNameStore --- src/org/openlcb/cdi/cmd/BackupConfig.java | 2 +- .../cdi/impl/ConfigRepresentation.java | 23 +++++++++++-- src/org/openlcb/cdi/swing/CdiPanel.java | 34 ++++++------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/org/openlcb/cdi/cmd/BackupConfig.java b/src/org/openlcb/cdi/cmd/BackupConfig.java index 029c8f0d..58a8bd17 100644 --- a/src/org/openlcb/cdi/cmd/BackupConfig.java +++ b/src/org/openlcb/cdi/cmd/BackupConfig.java @@ -62,7 +62,7 @@ public void visitInt(ConfigRepresentation.IntegerEntry e) { @Override public void visitEvent(ConfigRepresentation.EventEntry e) { - writeEntry(finalWriter, e.key, e.getValue()); + writeEntry(finalWriter, e.key, e.getNumericalEventValue()); } } ); diff --git a/src/org/openlcb/cdi/impl/ConfigRepresentation.java b/src/org/openlcb/cdi/impl/ConfigRepresentation.java index 172df1bb..b0c57ce5 100644 --- a/src/org/openlcb/cdi/impl/ConfigRepresentation.java +++ b/src/org/openlcb/cdi/impl/ConfigRepresentation.java @@ -17,6 +17,7 @@ import java.util.logging.Logger; import org.openlcb.DefaultPropertyListenerSupport; import org.openlcb.EventID; +import org.openlcb.EventNameStore; import org.openlcb.NodeID; import org.openlcb.OlcbInterface; import org.openlcb.Utilities; @@ -60,7 +61,7 @@ public class ConfigRepresentation extends DefaultPropertyListenerSupport { // Last time the progressbar was updated from the load. private long lastProgress; - public org.openlcb.cdi.swing.CdiPanel.GuiItemFactory factory = null; + public EventNameStore eventNameStore; /** * Connects to a node, populates the cache by fetching and parsing the CDI. @@ -744,13 +745,29 @@ protected void updateVisibleValue() { } } + /** + * @returns if `eventNameStore` exists, return the name of the contained event + * otherwise return the numerical event ID in dotted-hex form. + */ public String getValue() { MemorySpaceCache cache = getCacheForSpace(space); byte[] b = cache.read(origin, size); if (b == null) return null; EventID eid = new EventID(b); - if (factory == null) return eid.toShortString(); - return factory.getStringFromEventID(eid); + if (eventNameStore == null) return eid.toShortString(); + return eventNameStore.getEventName(eid); + } + + /** + * @returns the numerical event ID in dotted-hex form, + * ignoring any conversion eventNameStore that might exist + */ + public String getNumericalEventValue() { + MemorySpaceCache cache = getCacheForSpace(space); + byte[] b = cache.read(origin, size); + if (b == null) return null; + EventID eid = new EventID(b); + return eid.toShortString(); } public void setValue(EventID event) { diff --git a/src/org/openlcb/cdi/swing/CdiPanel.java b/src/org/openlcb/cdi/swing/CdiPanel.java index 87e5256b..3e203ffd 100644 --- a/src/org/openlcb/cdi/swing/CdiPanel.java +++ b/src/org/openlcb/cdi/swing/CdiPanel.java @@ -226,7 +226,6 @@ public void initComponents(ConfigRepresentation rep, GuiItemFactory factory) { setAlignmentX(Component.LEFT_ALIGNMENT); this.rep = rep; this.factory = factory; - rep.factory = factory; contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); @@ -2328,7 +2327,7 @@ protected void additionalButtons() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { NodeID node = rep.getConnection().getNodeId(); - EventID ev = factory.getEventIDFromString(textField.getText()); + EventID ev = rep.eventNameStore.getEventID(textField.getText()); rep.getConnection().getOutputConnection().put(new ProducerConsumerEventReportMessage(node, ev), rep.getConnection().getOutputConnection()); } }); @@ -2398,15 +2397,18 @@ private void showEventidMoreFunctionsMenu() { @Override protected void writeDisplayTextToNode() { - entry.setValue(factory.getEventIDFromString(textField.getText())); + entry.setValue(rep.eventNameStore.getEventID(textField.getText())); _changeMade = true; notifyTabColorRefresh(); } @Override protected void updateDisplayText(@NonNull String value) { - EventID eid = factory.getEventIDFromString(value); - String retval = factory.getStringFromEventID(eid); + String retval = ""; + if (!value.isEmpty()) { + EventID eid = rep.eventNameStore.getEventID(value); + retval = rep.eventNameStore.getEventName(eid); + } textField.setText(retval); } @@ -2431,7 +2433,7 @@ void updateColor() { try { // id = new EventID(s); - id = factory.getEventIDFromString(s); + id = rep.eventNameStore.getEventID(s); } catch (RuntimeException e) { // Event is not in the right format. Ignore. return; @@ -2461,6 +2463,8 @@ private void releaseListener() { } } + + // represent a slider with an optional text view private class SliderWithView extends JPanel { JSlider slider = null; @@ -3232,24 +3236,6 @@ public JTextField handleStringValue(JTextField value) { public JTextArea handleEditorValue(JTextArea value) { return value; } - - /** Convert a String into an EventID, doing any additional local - * dealiasing required. - * @param content Content to convert, e.g. from a text component - * @return eventID that represents the content - */ - public EventID getEventIDFromString(String content) { - return new EventID(content); - } - - /** Convert an EventID into a String, doing any additional local - * aliasing required. - * @param event EventID to convert, e.g. from reading a node - * @return local representation fo that EventID, often just the dotted hex - */ - public String getStringFromEventID(EventID event) { - return event.toShortString(); - } } /** From 0b61bdca14677037b0119cd22a17097f52d5ca42 Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 07:02:01 -0500 Subject: [PATCH 3/6] Javadoc fixes --- src/org/openlcb/EventNameStore.java | 6 +++--- src/org/openlcb/cdi/impl/ConfigRepresentation.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/org/openlcb/EventNameStore.java b/src/org/openlcb/EventNameStore.java index aefc2199..16d4536a 100644 --- a/src/org/openlcb/EventNameStore.java +++ b/src/org/openlcb/EventNameStore.java @@ -19,14 +19,14 @@ public interface EventNameStore { /** * @param eventName Either a previously stored event name that is * is associated to an event ID, or the dotted-hex form of an Event ID - * @returns an eventID from tne matching name, if any + * @return an eventID from tne matching name, if any * otherwise directly return the doted-hex input. */ public EventID getEventID(String eventName); /** - * @parm A valid event ID, not null - * @returns If a name has been associated with this event ID, return that name, + * @param A valid event ID, not null + * @return If a name has been associated with this event ID, return that name, * otherwise an event ID from parsing the eventName as dotted-hex. */ public String getEventName(EventID eventID); diff --git a/src/org/openlcb/cdi/impl/ConfigRepresentation.java b/src/org/openlcb/cdi/impl/ConfigRepresentation.java index b0c57ce5..2739725b 100644 --- a/src/org/openlcb/cdi/impl/ConfigRepresentation.java +++ b/src/org/openlcb/cdi/impl/ConfigRepresentation.java @@ -746,7 +746,7 @@ protected void updateVisibleValue() { } /** - * @returns if `eventNameStore` exists, return the name of the contained event + * @return if `eventNameStore` exists, return the name of the contained event * otherwise return the numerical event ID in dotted-hex form. */ public String getValue() { @@ -759,7 +759,7 @@ public String getValue() { } /** - * @returns the numerical event ID in dotted-hex form, + * @return the numerical event ID in dotted-hex form, * ignoring any conversion eventNameStore that might exist */ public String getNumericalEventValue() { From 7a954f704b125725fa553f20d8020fd5ab735882 Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 07:04:25 -0500 Subject: [PATCH 4/6] Javadoc fixes --- src/org/openlcb/EventNameStore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/openlcb/EventNameStore.java b/src/org/openlcb/EventNameStore.java index 16d4536a..35dfe998 100644 --- a/src/org/openlcb/EventNameStore.java +++ b/src/org/openlcb/EventNameStore.java @@ -25,7 +25,7 @@ public interface EventNameStore { public EventID getEventID(String eventName); /** - * @param A valid event ID, not null + * @param eventID A valid event ID, not null * @return If a name has been associated with this event ID, return that name, * otherwise an event ID from parsing the eventName as dotted-hex. */ From 33c05554cae8dcb1fd534d03e8032cb00ba7924e Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 07:55:48 -0500 Subject: [PATCH 5/6] add another setValue overloading --- src/org/openlcb/cdi/impl/ConfigRepresentation.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/org/openlcb/cdi/impl/ConfigRepresentation.java b/src/org/openlcb/cdi/impl/ConfigRepresentation.java index 2739725b..68e81341 100644 --- a/src/org/openlcb/cdi/impl/ConfigRepresentation.java +++ b/src/org/openlcb/cdi/impl/ConfigRepresentation.java @@ -776,6 +776,13 @@ public void setValue(EventID event) { if (b == null) return; cache.write(origin, b, this); } + + public void setValue(String eventName) { + EventID event; + if (eventNameStore == null) event = new EventID(eventName); + else event = eventNameStore.getEventID(eventName); + setValue(event); + } } /** From 6281e387619063bf92df00f71c444e930b0dd9a0 Mon Sep 17 00:00:00 2001 From: Bob Jacobsen Date: Thu, 13 Feb 2025 08:34:49 -0500 Subject: [PATCH 6/6] remove dead code --- src/org/openlcb/cdi/swing/CdiPanel.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/openlcb/cdi/swing/CdiPanel.java b/src/org/openlcb/cdi/swing/CdiPanel.java index 3e203ffd..2c086625 100644 --- a/src/org/openlcb/cdi/swing/CdiPanel.java +++ b/src/org/openlcb/cdi/swing/CdiPanel.java @@ -2432,7 +2432,6 @@ void updateColor() { EventID id; try { -// id = new EventID(s); id = rep.eventNameStore.getEventID(s); } catch (RuntimeException e) { // Event is not in the right format. Ignore.