From 8c44c45817f83e5efddac6c50fed239fcbe8d5b6 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sat, 26 Mar 2016 00:07:49 +0100 Subject: [PATCH] fixed problem with attributes stored in model files --- .../digital/core/element/AttributeKey.java | 34 +++++++++++-------- .../core/element/ElementAttributes.java | 10 +++--- src/test/resources/dig/MS-JK.dig | 28 +++++---------- src/test/resources/dig/and.dig | 29 +++++++--------- src/test/resources/dig/nestedAnd.dig | 11 +++--- src/test/resources/dig/nestedMSFF.dig | 11 +++--- src/test/resources/dig/trafficLight.dig | 11 +++--- 7 files changed, 58 insertions(+), 76 deletions(-) diff --git a/src/main/java/de/neemann/digital/core/element/AttributeKey.java b/src/main/java/de/neemann/digital/core/element/AttributeKey.java index 09547f793..21dab5114 100644 --- a/src/main/java/de/neemann/digital/core/element/AttributeKey.java +++ b/src/main/java/de/neemann/digital/core/element/AttributeKey.java @@ -8,29 +8,35 @@ import de.neemann.digital.lang.Lang; */ public class AttributeKey { - public static final AttributeKey Bits = new AttributeKey<>(Lang.get("key_dataBits"), 1); - public static final AttributeKey InputCount = new AttributeKey<>(Lang.get("key_numberInputs"), 2); - public static final AttributeKey Label = new AttributeKey<>(Lang.get("key_label"), ""); - public static final AttributeKey Value = new AttributeKey<>(Lang.get("key_value"), 1); - public static final AttributeKey Default = new AttributeKey<>(Lang.get("key_default"), 0); - public static final AttributeKey Color = new AttributeKey<>(Lang.get("key_color"), java.awt.Color.RED); - public static final AttributeKey InputSplit = new AttributeKey<>(Lang.get("key_inputSplitting"), ""); - public static final AttributeKey OutputSplit = new AttributeKey<>(Lang.get("key_outputSplitting"), ""); - public static final AttributeKey Frequency = new AttributeKey<>(Lang.get("key_frequency"), 1); - public static final AttributeKey SelectorBits = new AttributeKey<>(Lang.get("key_selectorBits"), 1); - public static final AttributeKey Signed = new AttributeKey<>(Lang.get("key_signed"), false); - public static final AttributeKey Data = new AttributeKey<>(Lang.get("key_data"), DataField.DEFAULT); + public static final AttributeKey Bits = new AttributeKey<>("Bits", Lang.get("key_dataBits"), 1); + public static final AttributeKey InputCount = new AttributeKey<>("Inputs", Lang.get("key_numberInputs"), 2); + public static final AttributeKey Label = new AttributeKey<>("Label", Lang.get("key_label"), ""); + public static final AttributeKey Value = new AttributeKey<>("Value", Lang.get("key_value"), 1); + public static final AttributeKey Default = new AttributeKey<>("Default", Lang.get("key_default"), 0); + public static final AttributeKey Color = new AttributeKey<>("Color", Lang.get("key_color"), java.awt.Color.RED); + public static final AttributeKey InputSplit = new AttributeKey<>("Input Splitting", Lang.get("key_inputSplitting"), ""); + public static final AttributeKey OutputSplit = new AttributeKey<>("Output Splitting", Lang.get("key_outputSplitting"), ""); + public static final AttributeKey Frequency = new AttributeKey<>("Frequency", Lang.get("key_frequency"), 1); + public static final AttributeKey SelectorBits = new AttributeKey<>("Selector Bits", Lang.get("key_selectorBits"), 1); + public static final AttributeKey Signed = new AttributeKey<>("Signed", Lang.get("key_signed"), false); + public static final AttributeKey Data = new AttributeKey<>("Data", Lang.get("key_data"), DataField.DEFAULT); - private final String name; + private final String key; private final VALUE def; + private final String name; - private AttributeKey(String name, VALUE def) { + private AttributeKey(String key, String name, VALUE def) { + this.key = key; this.name = name; if (def == null) throw new NullPointerException(); this.def = def; } + public String getKey() { + return key; + } + public String getName() { return name; } diff --git a/src/main/java/de/neemann/digital/core/element/ElementAttributes.java b/src/main/java/de/neemann/digital/core/element/ElementAttributes.java index 8902c7331..8c3dba20b 100644 --- a/src/main/java/de/neemann/digital/core/element/ElementAttributes.java +++ b/src/main/java/de/neemann/digital/core/element/ElementAttributes.java @@ -10,7 +10,7 @@ import java.util.Map; * @author hneemann */ public class ElementAttributes { - private HashMap attributes; + private HashMap attributes; private transient ArrayList listeners; public ElementAttributes() { @@ -19,7 +19,7 @@ public class ElementAttributes { public ElementAttributes(ElementAttributes proto) { if (proto.attributes != null) { attributes = new HashMap<>(); - for (Map.Entry e : proto.attributes.entrySet()) { + for (Map.Entry e : proto.attributes.entrySet()) { attributes.put(e.getKey(), e.getValue()); } } @@ -29,7 +29,7 @@ public class ElementAttributes { if (attributes == null) return key.getDefault(); else { - VALUE value = (VALUE) attributes.get(key); + VALUE value = (VALUE) attributes.get(key.getKey()); if (value == null) return key.getDefault(); return value; @@ -40,11 +40,11 @@ public class ElementAttributes { if (value != get(key)) { if (value.equals(key.getDefault())) { if (attributes != null) - attributes.remove(key); + attributes.remove(key.getKey()); } else { if (attributes == null) attributes = new HashMap<>(); - attributes.put(key, value); + attributes.put(key.getKey(), value); } fireValueChanged(key); } diff --git a/src/test/resources/dig/MS-JK.dig b/src/test/resources/dig/MS-JK.dig index 487911458..42b0e7256 100644 --- a/src/test/resources/dig/MS-JK.dig +++ b/src/test/resources/dig/MS-JK.dig @@ -5,10 +5,7 @@ And - - Inputs - 2 - + Inputs 3 @@ -19,7 +16,7 @@ And - + Inputs 3 @@ -36,17 +33,11 @@ In - - Label - - + Label J - - Default - 0 - + Default 1 @@ -57,7 +48,7 @@ In - + Label C @@ -104,7 +95,7 @@ Out - + Label Q @@ -115,7 +106,7 @@ Out - + Label ~Q @@ -126,10 +117,7 @@ In - - Label - - + Label K diff --git a/src/test/resources/dig/and.dig b/src/test/resources/dig/and.dig index ef850cda5..727d67502 100644 --- a/src/test/resources/dig/and.dig +++ b/src/test/resources/dig/and.dig @@ -4,58 +4,55 @@ And - + 0 In - - Label - - + Label A - + 0 In - + Label B - + 0 Out - + Label Out - + 0 - - + + - - + + - - + + \ No newline at end of file diff --git a/src/test/resources/dig/nestedAnd.dig b/src/test/resources/dig/nestedAnd.dig index abd5ea632..ba2d17234 100644 --- a/src/test/resources/dig/nestedAnd.dig +++ b/src/test/resources/dig/nestedAnd.dig @@ -11,10 +11,7 @@ In - - Label - - + Label A @@ -25,7 +22,7 @@ In - + Label B @@ -36,8 +33,8 @@ Out - - Out + Label + C diff --git a/src/test/resources/dig/nestedMSFF.dig b/src/test/resources/dig/nestedMSFF.dig index 823b403e9..fcbe89732 100644 --- a/src/test/resources/dig/nestedMSFF.dig +++ b/src/test/resources/dig/nestedMSFF.dig @@ -5,10 +5,7 @@ In - - Label - - + Label C @@ -19,7 +16,7 @@ In - + Label J @@ -30,7 +27,7 @@ Out - + Label Q @@ -47,7 +44,7 @@ In - + Label K diff --git a/src/test/resources/dig/trafficLight.dig b/src/test/resources/dig/trafficLight.dig index cca8c7ead..f42e09ea2 100644 --- a/src/test/resources/dig/trafficLight.dig +++ b/src/test/resources/dig/trafficLight.dig @@ -17,10 +17,7 @@ In - - Label - - + Label Clock @@ -31,7 +28,7 @@ Out - + Label Red @@ -42,7 +39,7 @@ Out - + Label Yellow @@ -53,7 +50,7 @@ Out - + Label Green