use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class ToolAttributeAction method doIt.
@Override
public void doIt(Project proj) {
AttributeSet attrs = config.getEvent().getAttributeSet();
Map<Attribute<?>, Object> newValues = config.getAttributeValues();
Map<Attribute<?>, Object> oldValues = new HashMap<Attribute<?>, Object>(newValues.size());
for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
@SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
oldValues.put(attr, attrs.getValue(attr));
attrs.setValue(attr, entry.getValue());
}
this.oldValues = oldValues;
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class ToolAttributeAction method undo.
@Override
public void undo(Project proj) {
AttributeSet attrs = config.getEvent().getAttributeSet();
Map<Attribute<?>, Object> oldValues = this.oldValues;
for (Map.Entry<Attribute<?>, Object> entry : oldValues.entrySet()) {
@SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) entry.getKey();
attrs.setValue(attr, entry.getValue());
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class InstanceComponent method computeEnds.
private void computeEnds() {
List<Port> ports = portList;
EndData[] esOld = endArray;
int esOldLength = esOld == null ? 0 : esOld.length;
EndData[] es = esOld;
if (es == null || es.length != ports.size()) {
es = new EndData[ports.size()];
if (esOldLength > 0) {
int toCopy = Math.min(esOldLength, es.length);
System.arraycopy(esOld, 0, es, 0, toCopy);
}
}
HashSet<Attribute<BitWidth>> wattrs = null;
boolean toolTipFound = false;
ArrayList<EndData> endsChangedOld = null;
ArrayList<EndData> endsChangedNew = null;
Iterator<Port> pit = ports.iterator();
for (int i = 0; pit.hasNext() || i < esOldLength; i++) {
Port p = pit.hasNext() ? pit.next() : null;
EndData oldEnd = i < esOldLength ? esOld[i] : null;
EndData newEnd = p == null ? null : p.toEnd(loc, attrs);
if (oldEnd == null || !oldEnd.equals(newEnd)) {
if (newEnd != null)
es[i] = newEnd;
if (endsChangedOld == null) {
endsChangedOld = new ArrayList<EndData>();
endsChangedNew = new ArrayList<EndData>();
}
endsChangedOld.add(oldEnd);
endsChangedNew.add(newEnd);
}
if (p != null) {
Attribute<BitWidth> attr = p.getWidthAttribute();
if (attr != null) {
if (wattrs == null) {
wattrs = new HashSet<Attribute<BitWidth>>();
}
wattrs.add(attr);
}
if (p.getToolTip() != null)
toolTipFound = true;
}
}
if (!attrListenRequested) {
HashSet<Attribute<BitWidth>> oldWattrs = widthAttrs;
if (wattrs == null && oldWattrs != null) {
getAttributeSet().removeAttributeListener(this);
} else if (wattrs != null && oldWattrs == null) {
getAttributeSet().addAttributeListener(this);
}
}
if (es != esOld) {
endArray = es;
endList = new UnmodifiableList<EndData>(es);
}
widthAttrs = wattrs;
hasToolTips = toolTipFound;
if (endsChangedOld != null) {
fireEndsChanged(endsChangedOld, endsChangedNew);
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class InstanceFactory method getDefaultAttributeValue.
@Override
public Object getDefaultAttributeValue(Attribute<?> attr, LogisimVersion ver) {
Attribute<?>[] as = attrs;
if (as != null) {
for (int i = 0; i < as.length; i++) {
if (as[i] == attr) {
return defaults[i];
}
}
return null;
} else {
AttributeSet dfltSet = defaultSet;
if (dfltSet == null) {
dfltSet = createAttributeSet();
defaultSet = dfltSet;
}
return ((AttributeSet) dfltSet.clone()).getValue(attr);
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class DrawingAttributeSet method setValue.
public <V> void setValue(Attribute<V> attr, V value) {
Iterator<Attribute<?>> ait = attrs.iterator();
ListIterator<Object> vit = values.listIterator();
while (ait.hasNext()) {
Object a = ait.next();
vit.next();
if (a.equals(attr)) {
vit.set(value);
AttributeEvent e = new AttributeEvent(this, attr, value, null);
for (AttributeListener listener : listeners) {
listener.attributeValueChanged(e);
}
if (attr == DrawAttr.PAINT_TYPE) {
e = new AttributeEvent(this);
for (AttributeListener listener : listeners) {
listener.attributeListChanged(e);
}
}
return;
}
}
throw new IllegalArgumentException(attr.toString());
}
Aggregations