mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
fixed problem with attributes stored in model files
This commit is contained in:
parent
4cf8e76308
commit
8c44c45817
@ -8,29 +8,35 @@ import de.neemann.digital.lang.Lang;
|
||||
*/
|
||||
public class AttributeKey<VALUE> {
|
||||
|
||||
public static final AttributeKey<Integer> Bits = new AttributeKey<>(Lang.get("key_dataBits"), 1);
|
||||
public static final AttributeKey<Integer> InputCount = new AttributeKey<>(Lang.get("key_numberInputs"), 2);
|
||||
public static final AttributeKey<String> Label = new AttributeKey<>(Lang.get("key_label"), "");
|
||||
public static final AttributeKey<Integer> Value = new AttributeKey<>(Lang.get("key_value"), 1);
|
||||
public static final AttributeKey<Integer> Default = new AttributeKey<>(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<String> InputSplit = new AttributeKey<>(Lang.get("key_inputSplitting"), "");
|
||||
public static final AttributeKey<String> OutputSplit = new AttributeKey<>(Lang.get("key_outputSplitting"), "");
|
||||
public static final AttributeKey<Integer> Frequency = new AttributeKey<>(Lang.get("key_frequency"), 1);
|
||||
public static final AttributeKey<Integer> SelectorBits = new AttributeKey<>(Lang.get("key_selectorBits"), 1);
|
||||
public static final AttributeKey<Boolean> Signed = new AttributeKey<>(Lang.get("key_signed"), false);
|
||||
public static final AttributeKey<DataField> Data = new AttributeKey<>(Lang.get("key_data"), DataField.DEFAULT);
|
||||
public static final AttributeKey<Integer> Bits = new AttributeKey<>("Bits", Lang.get("key_dataBits"), 1);
|
||||
public static final AttributeKey<Integer> InputCount = new AttributeKey<>("Inputs", Lang.get("key_numberInputs"), 2);
|
||||
public static final AttributeKey<String> Label = new AttributeKey<>("Label", Lang.get("key_label"), "");
|
||||
public static final AttributeKey<Integer> Value = new AttributeKey<>("Value", Lang.get("key_value"), 1);
|
||||
public static final AttributeKey<Integer> Default = new AttributeKey<>("Default", Lang.get("key_default"), 0);
|
||||
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<>("Input Splitting", Lang.get("key_inputSplitting"), "");
|
||||
public static final AttributeKey<String> OutputSplit = new AttributeKey<>("Output Splitting", Lang.get("key_outputSplitting"), "");
|
||||
public static final AttributeKey<Integer> Frequency = new AttributeKey<>("Frequency", Lang.get("key_frequency"), 1);
|
||||
public static final AttributeKey<Integer> SelectorBits = new AttributeKey<>("Selector Bits", Lang.get("key_selectorBits"), 1);
|
||||
public static final AttributeKey<Boolean> Signed = new AttributeKey<>("Signed", Lang.get("key_signed"), false);
|
||||
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 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;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
||||
* @author hneemann
|
||||
*/
|
||||
public class ElementAttributes {
|
||||
private HashMap<AttributeKey, Object> attributes;
|
||||
private HashMap<String, Object> attributes;
|
||||
private transient ArrayList<AttributeListener> listeners;
|
||||
|
||||
public ElementAttributes() {
|
||||
@ -19,7 +19,7 @@ public class ElementAttributes {
|
||||
public ElementAttributes(ElementAttributes proto) {
|
||||
if (proto.attributes != null) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
@ -5,10 +5,7 @@
|
||||
<elementName>And</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Inputs</name>
|
||||
<def class="int">2</def>
|
||||
</key>
|
||||
<string>Inputs</string>
|
||||
<int>3</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -19,7 +16,7 @@
|
||||
<elementName>And</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement/elementAttributes/entry/key"/>
|
||||
<string>Inputs</string>
|
||||
<int>3</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -36,17 +33,11 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>J</string>
|
||||
</entry>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Default</name>
|
||||
<def class="int">0</def>
|
||||
</key>
|
||||
<string>Default</string>
|
||||
<int>1</int>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -57,7 +48,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>C</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -104,7 +95,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Q</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -115,7 +106,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[4]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>~Q</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -126,10 +117,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>K</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
|
@ -4,58 +4,55 @@
|
||||
<visualElement>
|
||||
<elementName>And</elementName>
|
||||
<elementAttributes/>
|
||||
<pos x="340" y="180"/>
|
||||
<pos x="360" y="170"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>A</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="300" y="180"/>
|
||||
<pos x="340" y="170"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>B</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="300" y="200"/>
|
||||
<pos x="340" y="190"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
<visualElement>
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Out</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="410" y="190"/>
|
||||
<pos x="410" y="180"/>
|
||||
<rotate>0</rotate>
|
||||
</visualElement>
|
||||
</visualElements>
|
||||
<wires>
|
||||
<wire>
|
||||
<p1 x="300" y="180"/>
|
||||
<p2 x="340" y="180"/>
|
||||
<p1 x="390" y="180"/>
|
||||
<p2 x="410" y="180"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="300" y="200"/>
|
||||
<p2 x="340" y="200"/>
|
||||
<p1 x="340" y="170"/>
|
||||
<p2 x="360" y="170"/>
|
||||
</wire>
|
||||
<wire>
|
||||
<p1 x="370" y="190"/>
|
||||
<p2 x="410" y="190"/>
|
||||
<p1 x="340" y="190"/>
|
||||
<p2 x="360" y="190"/>
|
||||
</wire>
|
||||
</wires>
|
||||
</circuit>
|
@ -11,10 +11,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>A</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -25,7 +22,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>B</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -36,8 +33,8 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[2]/elementAttributes/entry/key"/>
|
||||
<string>Out</string>
|
||||
<string>Label</string>
|
||||
<string>C</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
<pos x="420" y="140"/>
|
||||
|
@ -5,10 +5,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>C</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -19,7 +16,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>J</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -30,7 +27,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Q</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -47,7 +44,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>K</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
|
@ -17,10 +17,7 @@
|
||||
<elementName>In</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key>
|
||||
<name>Label</name>
|
||||
<def class="string"></def>
|
||||
</key>
|
||||
<string>Label</string>
|
||||
<string>Clock</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -31,7 +28,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Red</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -42,7 +39,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Yellow</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
@ -53,7 +50,7 @@
|
||||
<elementName>Out</elementName>
|
||||
<elementAttributes>
|
||||
<entry>
|
||||
<key reference="../../../../visualElement[3]/elementAttributes/entry/key"/>
|
||||
<string>Label</string>
|
||||
<string>Green</string>
|
||||
</entry>
|
||||
</elementAttributes>
|
||||
|
Loading…
x
Reference in New Issue
Block a user