fixed problem with attributes stored in model files

This commit is contained in:
hneemann 2016-03-26 00:07:49 +01:00
parent 4cf8e76308
commit 8c44c45817
7 changed files with 58 additions and 76 deletions

View File

@ -8,29 +8,35 @@ import de.neemann.digital.lang.Lang;
*/ */
public class AttributeKey<VALUE> { public class AttributeKey<VALUE> {
public static final AttributeKey<Integer> Bits = new AttributeKey<>(Lang.get("key_dataBits"), 1); public static final AttributeKey<Integer> Bits = new AttributeKey<>("Bits", Lang.get("key_dataBits"), 1);
public static final AttributeKey<Integer> InputCount = new AttributeKey<>(Lang.get("key_numberInputs"), 2); public static final AttributeKey<Integer> InputCount = new AttributeKey<>("Inputs", Lang.get("key_numberInputs"), 2);
public static final AttributeKey<String> Label = new AttributeKey<>(Lang.get("key_label"), ""); public static final AttributeKey<String> Label = new AttributeKey<>("Label", Lang.get("key_label"), "");
public static final AttributeKey<Integer> Value = new AttributeKey<>(Lang.get("key_value"), 1); public static final AttributeKey<Integer> Value = new AttributeKey<>("Value", Lang.get("key_value"), 1);
public static final AttributeKey<Integer> Default = new AttributeKey<>(Lang.get("key_default"), 0); public static final AttributeKey<Integer> Default = new AttributeKey<>("Default", Lang.get("key_default"), 0);
public static final AttributeKey<java.awt.Color> Color = new AttributeKey<>(Lang.get("key_color"), java.awt.Color.RED); public static final AttributeKey<java.awt.Color> Color = new AttributeKey<>("Color", Lang.get("key_color"), java.awt.Color.RED);
public static final AttributeKey<String> InputSplit = new AttributeKey<>(Lang.get("key_inputSplitting"), ""); public static final AttributeKey<String> InputSplit = new AttributeKey<>("Input Splitting", Lang.get("key_inputSplitting"), "");
public static final AttributeKey<String> OutputSplit = new AttributeKey<>(Lang.get("key_outputSplitting"), ""); public static final AttributeKey<String> OutputSplit = new AttributeKey<>("Output Splitting", Lang.get("key_outputSplitting"), "");
public static final AttributeKey<Integer> Frequency = new AttributeKey<>(Lang.get("key_frequency"), 1); public static final AttributeKey<Integer> Frequency = new AttributeKey<>("Frequency", Lang.get("key_frequency"), 1);
public static final AttributeKey<Integer> SelectorBits = new AttributeKey<>(Lang.get("key_selectorBits"), 1); public static final AttributeKey<Integer> SelectorBits = new AttributeKey<>("Selector Bits", Lang.get("key_selectorBits"), 1);
public static final AttributeKey<Boolean> Signed = new AttributeKey<>(Lang.get("key_signed"), false); public static final AttributeKey<Boolean> Signed = new AttributeKey<>("Signed", Lang.get("key_signed"), false);
public static final AttributeKey<DataField> Data = new AttributeKey<>(Lang.get("key_data"), DataField.DEFAULT); public static final AttributeKey<DataField> Data = new AttributeKey<>("Data", Lang.get("key_data"), DataField.DEFAULT);
private final String name; private final String key;
private final VALUE def; 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; this.name = name;
if (def == null) if (def == null)
throw new NullPointerException(); throw new NullPointerException();
this.def = def; this.def = def;
} }
public String getKey() {
return key;
}
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -10,7 +10,7 @@ import java.util.Map;
* @author hneemann * @author hneemann
*/ */
public class ElementAttributes { public class ElementAttributes {
private HashMap<AttributeKey, Object> attributes; private HashMap<String, Object> attributes;
private transient ArrayList<AttributeListener> listeners; private transient ArrayList<AttributeListener> listeners;
public ElementAttributes() { public ElementAttributes() {
@ -19,7 +19,7 @@ public class ElementAttributes {
public ElementAttributes(ElementAttributes proto) { public ElementAttributes(ElementAttributes proto) {
if (proto.attributes != null) { if (proto.attributes != null) {
attributes = new HashMap<>(); attributes = new HashMap<>();
for (Map.Entry<AttributeKey, Object> e : proto.attributes.entrySet()) { for (Map.Entry<String, Object> e : proto.attributes.entrySet()) {
attributes.put(e.getKey(), e.getValue()); attributes.put(e.getKey(), e.getValue());
} }
} }
@ -29,7 +29,7 @@ public class ElementAttributes {
if (attributes == null) if (attributes == null)
return key.getDefault(); return key.getDefault();
else { else {
VALUE value = (VALUE) attributes.get(key); VALUE value = (VALUE) attributes.get(key.getKey());
if (value == null) if (value == null)
return key.getDefault(); return key.getDefault();
return value; return value;
@ -40,11 +40,11 @@ public class ElementAttributes {
if (value != get(key)) { if (value != get(key)) {
if (value.equals(key.getDefault())) { if (value.equals(key.getDefault())) {
if (attributes != null) if (attributes != null)
attributes.remove(key); attributes.remove(key.getKey());
} else { } else {
if (attributes == null) if (attributes == null)
attributes = new HashMap<>(); attributes = new HashMap<>();
attributes.put(key, value); attributes.put(key.getKey(), value);
} }
fireValueChanged(key); fireValueChanged(key);
} }

View File

@ -5,10 +5,7 @@
<elementName>And</elementName> <elementName>And</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Inputs</string>
<name>Inputs</name>
<def class="int">2</def>
</key>
<int>3</int> <int>3</int>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -19,7 +16,7 @@
<elementName>And</elementName> <elementName>And</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement/elementAttributes/entry/key"/> <string>Inputs</string>
<int>3</int> <int>3</int>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -36,17 +33,11 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>J</string> <string>J</string>
</entry> </entry>
<entry> <entry>
<key> <string>Default</string>
<name>Default</name>
<def class="int">0</def>
</key>
<int>1</int> <int>1</int>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -57,7 +48,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/> <string>Label</string>
<string>C</string> <string>C</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -104,7 +95,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/> <string>Label</string>
<string>Q</string> <string>Q</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -115,7 +106,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/> <string>Label</string>
<string>~Q</string> <string>~Q</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -126,10 +117,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>K</string> <string>K</string>
</entry> </entry>
</elementAttributes> </elementAttributes>

View File

@ -4,58 +4,55 @@
<visualElement> <visualElement>
<elementName>And</elementName> <elementName>And</elementName>
<elementAttributes/> <elementAttributes/>
<pos x="340" y="180"/> <pos x="360" y="170"/>
<rotate>0</rotate> <rotate>0</rotate>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>A</string> <string>A</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="300" y="180"/> <pos x="340" y="170"/>
<rotate>0</rotate> <rotate>0</rotate>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/> <string>Label</string>
<string>B</string> <string>B</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="300" y="200"/> <pos x="340" y="190"/>
<rotate>0</rotate> <rotate>0</rotate>
</visualElement> </visualElement>
<visualElement> <visualElement>
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/> <string>Label</string>
<string>Out</string> <string>Out</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="410" y="190"/> <pos x="410" y="180"/>
<rotate>0</rotate> <rotate>0</rotate>
</visualElement> </visualElement>
</visualElements> </visualElements>
<wires> <wires>
<wire> <wire>
<p1 x="300" y="180"/> <p1 x="390" y="180"/>
<p2 x="340" y="180"/> <p2 x="410" y="180"/>
</wire> </wire>
<wire> <wire>
<p1 x="300" y="200"/> <p1 x="340" y="170"/>
<p2 x="340" y="200"/> <p2 x="360" y="170"/>
</wire> </wire>
<wire> <wire>
<p1 x="370" y="190"/> <p1 x="340" y="190"/>
<p2 x="410" y="190"/> <p2 x="360" y="190"/>
</wire> </wire>
</wires> </wires>
</circuit> </circuit>

View File

@ -11,10 +11,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>A</string> <string>A</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -25,7 +22,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/> <string>Label</string>
<string>B</string> <string>B</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -36,8 +33,8 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/> <string>Label</string>
<string>Out</string> <string>C</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
<pos x="420" y="140"/> <pos x="420" y="140"/>

View File

@ -5,10 +5,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>C</string> <string>C</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -19,7 +16,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement/elementAttributes/entry/key"/> <string>Label</string>
<string>J</string> <string>J</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -30,7 +27,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement/elementAttributes/entry/key"/> <string>Label</string>
<string>Q</string> <string>Q</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -47,7 +44,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement/elementAttributes/entry/key"/> <string>Label</string>
<string>K</string> <string>K</string>
</entry> </entry>
</elementAttributes> </elementAttributes>

View File

@ -17,10 +17,7 @@
<elementName>In</elementName> <elementName>In</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key> <string>Label</string>
<name>Label</name>
<def class="string"></def>
</key>
<string>Clock</string> <string>Clock</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -31,7 +28,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/> <string>Label</string>
<string>Red</string> <string>Red</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -42,7 +39,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/> <string>Label</string>
<string>Yellow</string> <string>Yellow</string>
</entry> </entry>
</elementAttributes> </elementAttributes>
@ -53,7 +50,7 @@
<elementName>Out</elementName> <elementName>Out</elementName>
<elementAttributes> <elementAttributes>
<entry> <entry>
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/> <string>Label</string>
<string>Green</string> <string>Green</string>
</entry> </entry>
</elementAttributes> </elementAttributes>