mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
added some documentation
This commit is contained in:
parent
8d704ba955
commit
f335a93cf4
@ -19,9 +19,9 @@ public class SpeedTest {
|
|||||||
public double calculate() throws NodeException {
|
public double calculate() throws NodeException {
|
||||||
ArrayList<Clock> clocks = model.getClocks();
|
ArrayList<Clock> clocks = model.getClocks();
|
||||||
if (clocks.isEmpty())
|
if (clocks.isEmpty())
|
||||||
throw new NodeException(Lang.get("err_noClockFound"), null);
|
throw new NodeException(Lang.get("err_noClockFound"));
|
||||||
else if (clocks.size() > 1)
|
else if (clocks.size() > 1)
|
||||||
throw new NodeException(Lang.get("err_moreThenOneClocksFound"), null);
|
throw new NodeException(Lang.get("err_moreThenOneClocksFound"));
|
||||||
|
|
||||||
|
|
||||||
Clock clock = clocks.get(0);
|
Clock clock = clocks.get(0);
|
||||||
|
@ -38,7 +38,7 @@ public abstract class FanIn extends Node implements Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class FanInDescription extends ElementTypeDescription {
|
public static class FanInDescription extends ElementTypeDescription {
|
||||||
public FanInDescription(Class<?> clazz) {
|
public FanInDescription(Class<? extends Element> clazz) {
|
||||||
super(clazz);
|
super(clazz);
|
||||||
addAttributes();
|
addAttributes();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ import de.neemann.digital.core.memory.DataField;
|
|||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A key for a single attribute
|
||||||
|
*
|
||||||
|
* @param <VALUE> the type of the value
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class AttributeKey<VALUE> {
|
public class AttributeKey<VALUE> {
|
||||||
@ -47,18 +50,34 @@ public class AttributeKey<VALUE> {
|
|||||||
this.def = def;
|
this.def = def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the attributes key
|
||||||
|
*
|
||||||
|
* @return the key
|
||||||
|
*/
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the attributes display name
|
||||||
|
*
|
||||||
|
* @return thr name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the default value of this key
|
||||||
|
*/
|
||||||
public VALUE getDefault() {
|
public VALUE getDefault() {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The values class
|
||||||
|
*/
|
||||||
public Class getValueClass() {
|
public Class getValueClass() {
|
||||||
return def.getClass();
|
return def.getClass();
|
||||||
}
|
}
|
||||||
@ -68,6 +87,10 @@ public class AttributeKey<VALUE> {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A integer attribute.
|
||||||
|
* Stores additional combo box values
|
||||||
|
*/
|
||||||
public static final class AttributeKeyInteger extends AttributeKey<Integer> {
|
public static final class AttributeKeyInteger extends AttributeKey<Integer> {
|
||||||
private Integer[] values;
|
private Integer[] values;
|
||||||
|
|
||||||
@ -80,6 +103,9 @@ public class AttributeKey<VALUE> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the values to show in the combo box
|
||||||
|
*/
|
||||||
public Integer[] getComboBoxValues() {
|
public Integer[] getComboBoxValues() {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package de.neemann.digital.core.element;
|
package de.neemann.digital.core.element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Interface to implement a AttributeListener
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public interface AttributeListener {
|
public interface AttributeListener {
|
||||||
|
/**
|
||||||
|
* Is called if an attribute changes
|
||||||
|
*
|
||||||
|
* @param key the key which value has changed
|
||||||
|
*/
|
||||||
void attributeChanged(AttributeKey key);
|
void attributeChanged(AttributeKey key);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public interface Element {
|
|||||||
* inputs of this element.
|
* inputs of this element.
|
||||||
*
|
*
|
||||||
* @param inputs the list of <code>ObservableValue</code>s to use
|
* @param inputs the list of <code>ObservableValue</code>s to use
|
||||||
* @throws NodeException
|
* @throws NodeException NodeException
|
||||||
*/
|
*/
|
||||||
void setInputs(ObservableValue... inputs) throws NodeException;
|
void setInputs(ObservableValue... inputs) throws NodeException;
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes one concrete Part.
|
* Describes one concrete Part.
|
||||||
|
* Its a Key value list, which is used to store the diferent elements attributes.
|
||||||
*
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
@ -14,9 +15,17 @@ public class ElementAttributes {
|
|||||||
private HashMap<String, Object> attributes;
|
private HashMap<String, Object> attributes;
|
||||||
private transient ArrayList<AttributeListener> listeners;
|
private transient ArrayList<AttributeListener> listeners;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*/
|
||||||
public ElementAttributes() {
|
public ElementAttributes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a deep copy of the given attributes
|
||||||
|
*
|
||||||
|
* @param proto the ElementAttributes to copy
|
||||||
|
*/
|
||||||
public ElementAttributes(ElementAttributes proto) {
|
public ElementAttributes(ElementAttributes proto) {
|
||||||
if (proto.attributes != null) {
|
if (proto.attributes != null) {
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
@ -26,6 +35,15 @@ public class ElementAttributes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a value from the map.
|
||||||
|
* If the value is not present the default value is returned
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param <VALUE> the type of the value
|
||||||
|
* @return the value
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <VALUE> VALUE get(AttributeKey<VALUE> key) {
|
public <VALUE> VALUE get(AttributeKey<VALUE> key) {
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
return key.getDefault();
|
return key.getDefault();
|
||||||
@ -37,6 +55,13 @@ public class ElementAttributes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a value is present.
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param <VALUE> the type of the value
|
||||||
|
* @return true if value is present
|
||||||
|
*/
|
||||||
public <VALUE> boolean contains(AttributeKey<VALUE> key) {
|
public <VALUE> boolean contains(AttributeKey<VALUE> key) {
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
return false;
|
return false;
|
||||||
@ -44,6 +69,14 @@ public class ElementAttributes {
|
|||||||
return attributes.containsKey(key.getKey());
|
return attributes.containsKey(key.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value
|
||||||
|
*
|
||||||
|
* @param key the key
|
||||||
|
* @param value the value
|
||||||
|
* @param <VALUE> the type of the value
|
||||||
|
* @return this to chain calls
|
||||||
|
*/
|
||||||
public <VALUE> ElementAttributes set(AttributeKey<VALUE> key, VALUE value) {
|
public <VALUE> ElementAttributes set(AttributeKey<VALUE> key, VALUE value) {
|
||||||
if (value != get(key)) {
|
if (value != get(key)) {
|
||||||
if (value.equals(key.getDefault())) {
|
if (value.equals(key.getDefault())) {
|
||||||
@ -68,6 +101,11 @@ public class ElementAttributes {
|
|||||||
l.attributeChanged(key);
|
l.attributeChanged(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a listener to this class
|
||||||
|
*
|
||||||
|
* @param listener the listener
|
||||||
|
*/
|
||||||
public void addListener(AttributeListener listener) {
|
public void addListener(AttributeListener listener) {
|
||||||
if (listeners == null)
|
if (listeners == null)
|
||||||
listeners = new ArrayList<>();
|
listeners = new ArrayList<>();
|
||||||
@ -75,19 +113,43 @@ public class ElementAttributes {
|
|||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* removes a listener to this class
|
||||||
|
*
|
||||||
|
* @param listener the listener
|
||||||
|
*/
|
||||||
public void removeListener(AttributeListener listener) {
|
public void removeListener(AttributeListener listener) {
|
||||||
if (listeners != null)
|
if (listeners != null)
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the bits count stored in this attributes.
|
||||||
|
* Its a short hand for get(AttributeKey.Bits)
|
||||||
|
*
|
||||||
|
* @return the number of bits
|
||||||
|
*/
|
||||||
public int getBits() {
|
public int getBits() {
|
||||||
return get(AttributeKey.Bits);
|
return get(AttributeKey.Bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the label stored in this attributes.
|
||||||
|
* Its a short hand for get(AttributeKey.Label)
|
||||||
|
*
|
||||||
|
* @return the label
|
||||||
|
*/
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return get(AttributeKey.Label);
|
return get(AttributeKey.Label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the bit count to this map.
|
||||||
|
* Shorthand for set(AttributeKey.Bits, bits);
|
||||||
|
*
|
||||||
|
* @param bits the number of bits
|
||||||
|
* @return this tp chain calls
|
||||||
|
*/
|
||||||
public ElementAttributes setBits(int bits) {
|
public ElementAttributes setBits(int bits) {
|
||||||
set(AttributeKey.Bits, bits);
|
set(AttributeKey.Bits, bits);
|
||||||
return this;
|
return this;
|
||||||
@ -95,17 +157,26 @@ public class ElementAttributes {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ElementAttributes{" +
|
return "ElementAttributes{"
|
||||||
"attributes=" + attributes +
|
+ "attributes=" + attributes
|
||||||
'}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if map is empty
|
||||||
|
*/
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
return true;
|
return true;
|
||||||
return attributes.isEmpty();
|
return attributes.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a file stored directly in the map
|
||||||
|
*
|
||||||
|
* @param fileKey the file key
|
||||||
|
* @return the file
|
||||||
|
*/
|
||||||
public File getFile(String fileKey) {
|
public File getFile(String fileKey) {
|
||||||
if (attributes != null) {
|
if (attributes != null) {
|
||||||
Object f = attributes.get(fileKey);
|
Object f = attributes.get(fileKey);
|
||||||
@ -115,6 +186,12 @@ public class ElementAttributes {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a file directly in the map
|
||||||
|
*
|
||||||
|
* @param fileKey the key
|
||||||
|
* @param file the file
|
||||||
|
*/
|
||||||
public void setFile(String fileKey, File file) {
|
public void setFile(String fileKey, File file) {
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
package de.neemann.digital.core.element;
|
package de.neemann.digital.core.element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Interface is used to implement a factory for elements
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public interface ElementFactory {
|
public interface ElementFactory {
|
||||||
|
/**
|
||||||
|
* creates a new element matching the given attributes
|
||||||
|
*
|
||||||
|
* @param attributes the attributes describing the element
|
||||||
|
* @return the created element
|
||||||
|
*/
|
||||||
Element create(ElementAttributes attributes);
|
Element create(ElementAttributes attributes);
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,24 @@ public class ElementTypeDescription {
|
|||||||
private final String[] inputNames;
|
private final String[] inputNames;
|
||||||
private final ArrayList<AttributeKey> attributeList;
|
private final ArrayList<AttributeKey> attributeList;
|
||||||
|
|
||||||
public ElementTypeDescription(Class<?> clazz, String... inputNames) {
|
/**
|
||||||
|
* Creates a new ElementTypeDescription
|
||||||
|
*
|
||||||
|
* @param clazz the elements class
|
||||||
|
* @param inputNames names of the input signals
|
||||||
|
*/
|
||||||
|
public ElementTypeDescription(Class<? extends Element> clazz, String... inputNames) {
|
||||||
this(clazz.getSimpleName(), clazz, inputNames);
|
this(clazz.getSimpleName(), clazz, inputNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ElementTypeDescription(String name, Class<?> clazz, String... inputNames) {
|
/**
|
||||||
|
* Creates a new ElementTypeDescription
|
||||||
|
*
|
||||||
|
* @param name name of this element
|
||||||
|
* @param clazz the elements class
|
||||||
|
* @param inputNames names of the input signals
|
||||||
|
*/
|
||||||
|
public ElementTypeDescription(String name, Class<? extends Element> clazz, String... inputNames) {
|
||||||
this(name, new ElementFactory() {
|
this(name, new ElementFactory() {
|
||||||
@Override
|
@Override
|
||||||
public Element create(ElementAttributes attributes) {
|
public Element create(ElementAttributes attributes) {
|
||||||
@ -37,6 +50,13 @@ public class ElementTypeDescription {
|
|||||||
}, inputNames);
|
}, inputNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new ElementTypeDescription
|
||||||
|
*
|
||||||
|
* @param name name of this element
|
||||||
|
* @param elementFactory factory used to create the element
|
||||||
|
* @param inputNames names of the input signals
|
||||||
|
*/
|
||||||
public ElementTypeDescription(String name, ElementFactory elementFactory, String... inputNames) {
|
public ElementTypeDescription(String name, ElementFactory elementFactory, String... inputNames) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.shortName = name;
|
this.shortName = name;
|
||||||
@ -108,6 +128,7 @@ public class ElementTypeDescription {
|
|||||||
*
|
*
|
||||||
* @param elementAttributes the elements attributes
|
* @param elementAttributes the elements attributes
|
||||||
* @return the list of input names
|
* @return the list of input names
|
||||||
|
* @throws NodeException NodeException
|
||||||
*/
|
*/
|
||||||
public String[] getInputNames(ElementAttributes elementAttributes) throws NodeException {
|
public String[] getInputNames(ElementAttributes elementAttributes) throws NodeException {
|
||||||
return inputNames;
|
return inputNames;
|
||||||
|
@ -1,13 +1,31 @@
|
|||||||
package de.neemann.digital.core.element;
|
package de.neemann.digital.core.element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Warapper for the elements rotation
|
||||||
|
*
|
||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class Rotation {
|
public class Rotation {
|
||||||
public int rotation;
|
/**
|
||||||
|
* The rotation value.
|
||||||
|
* is in between 0 and 3
|
||||||
|
*/
|
||||||
|
private final int rotation;
|
||||||
|
|
||||||
public Rotation(int rot) {
|
/**
|
||||||
rotation = rot;
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param rotation the rotation
|
||||||
|
*/
|
||||||
|
public Rotation(int rotation) {
|
||||||
|
this.rotation = rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the rotation value
|
||||||
|
*/
|
||||||
|
public int getRotation() {
|
||||||
|
return rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package de.neemann.digital.core.element;
|
|
||||||
|
|
||||||
import de.neemann.digital.draw.shapes.Shape;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hneemann
|
|
||||||
*/
|
|
||||||
public interface ShapeFactory {
|
|
||||||
Shape create(ElementAttributes elementAttributes);
|
|
||||||
}
|
|
@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* This package contains the classes used to describe and create the elements.
|
||||||
|
*
|
||||||
|
* @author hneemann
|
||||||
|
*/
|
||||||
|
package de.neemann.digital.core.element;
|
@ -28,7 +28,7 @@ public class Const implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||||
throw new NodeException(Lang.get("err_noInputsAvailable"), null);
|
throw new NodeException(Lang.get("err_noInputsAvailable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,7 +31,7 @@ public class In implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||||
throw new NodeException(Lang.get("err_noInputsAvailable"), null);
|
throw new NodeException(Lang.get("err_noInputsAvailable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,7 +33,7 @@ public class Clock implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||||
throw new NodeException(Lang.get("err_noInputsAvailable"), null);
|
throw new NodeException(Lang.get("err_noInputsAvailable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,7 @@ public class Reset implements Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInputs(ObservableValue... inputs) throws NodeException {
|
public void setInputs(ObservableValue... inputs) throws NodeException {
|
||||||
throw new NodeException(Lang.get("err_noInputsAvailable"), null);
|
throw new NodeException(Lang.get("err_noInputsAvailable"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,7 +195,7 @@ public class VisualElement implements Drawable, Moveable, AttributeListener {
|
|||||||
public void attributeChanged(AttributeKey key) {
|
public void attributeChanged(AttributeKey key) {
|
||||||
shape = null;
|
shape = null;
|
||||||
minMax = null;
|
minMax = null;
|
||||||
rotate = elementAttributes.get(AttributeKey.Rotate).rotation;
|
rotate = elementAttributes.get(AttributeKey.Rotate).getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -77,7 +77,7 @@ public final class ShapeFactory {
|
|||||||
try {
|
try {
|
||||||
if (cr == null) {
|
if (cr == null) {
|
||||||
if (library == null)
|
if (library == null)
|
||||||
throw new NodeException(Lang.get("err_noShapeFoundFor_N", partName), null);
|
throw new NodeException(Lang.get("err_noShapeFoundFor_N", partName));
|
||||||
else {
|
else {
|
||||||
ElementTypeDescription pt = library.getElementType(partName);
|
ElementTypeDescription pt = library.getElementType(partName);
|
||||||
if (pt instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
if (pt instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
||||||
|
@ -241,7 +241,7 @@ public final class EditorFactory {
|
|||||||
@Override
|
@Override
|
||||||
public Component getComponent(ElementAttributes elementAttributes) {
|
public Component getComponent(ElementAttributes elementAttributes) {
|
||||||
comb = new JComboBox<>(LIST);
|
comb = new JComboBox<>(LIST);
|
||||||
comb.setSelectedIndex(rotation.rotation);
|
comb.setSelectedIndex(rotation.getRotation());
|
||||||
return comb;
|
return comb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user