use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class SelectionAttributes method updateList.
private void updateList(boolean ignoreIfSelectionSame) {
Selection sel = selection;
Set<Component> oldSel = selected;
Set<Component> newSel;
if (sel == null) {
newSel = Collections.emptySet();
} else {
newSel = createSet(sel.getComponents());
}
if (haveSameElements(newSel, oldSel)) {
if (ignoreIfSelectionSame) {
return;
}
newSel = oldSel;
} else {
for (Component o : oldSel) {
if (!newSel.contains(o)) {
o.getAttributeSet().removeAttributeListener(listener);
}
}
for (Component o : newSel) {
if (!oldSel.contains(o)) {
o.getAttributeSet().addAttributeListener(listener);
}
}
}
LinkedHashMap<Attribute<Object>, Object> attrMap = computeAttributes(newSel);
boolean same = isSame(attrMap, this.attrs, this.values);
if (same) {
if (newSel != oldSel) {
this.selected = newSel;
}
} else {
Attribute<?>[] oldAttrs = this.attrs;
Object[] oldValues = this.values;
Attribute<?>[] newAttrs = new Attribute[attrMap.size()];
Object[] newValues = new Object[newAttrs.length];
boolean[] newReadOnly = new boolean[newAttrs.length];
int i = -1;
for (Map.Entry<Attribute<Object>, Object> entry : attrMap.entrySet()) {
i++;
newAttrs[i] = entry.getKey();
newValues[i] = entry.getValue();
newReadOnly[i] = computeReadOnly(newSel, newAttrs[i]);
}
if (newSel != oldSel) {
this.selected = newSel;
}
this.attrs = newAttrs;
this.attrsView = new UnmodifiableList<Attribute<?>>(newAttrs);
this.values = newValues;
this.readOnly = newReadOnly;
boolean listSame = oldAttrs != null && oldAttrs.length == newAttrs.length;
if (listSame) {
for (i = 0; i < oldAttrs.length; i++) {
if (!oldAttrs[i].equals(newAttrs[i])) {
listSame = false;
break;
}
}
}
if (listSame) {
for (i = 0; i < oldValues.length; i++) {
Object oldVal = oldValues[i];
Object newVal = newValues[i];
boolean sameVals = oldVal == null ? newVal == null : oldVal.equals(newVal);
if (!sameVals) {
@SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) oldAttrs[i];
fireAttributeValueChanged(attr, newVal, oldVal);
}
}
} else {
fireAttributeListChanged();
}
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class AddTool method setFacing.
private void setFacing(Canvas canvas, Direction facing) {
ComponentFactory source = getFactory();
if (source == null)
return;
AttributeSet base = getBaseAttributes();
Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
@SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
if (attr != null) {
Action act = ToolAttributeAction.create(this, attr, facing);
canvas.getProject().doAction(act);
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class DrawingAttributeSet method getValue.
@SuppressWarnings("unchecked")
public <V> V getValue(Attribute<V> attr) {
Iterator<Attribute<?>> ait = attrs.iterator();
Iterator<Object> vit = values.iterator();
while (ait.hasNext()) {
Object a = ait.next();
Object v = vit.next();
if (a.equals(attr)) {
return (V) v;
}
}
return null;
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class DrawingAttributeSet method applyTo.
public <E extends CanvasObject> E applyTo(E drawable) {
AbstractCanvasObject d = (AbstractCanvasObject) drawable;
// use a for(i...) loop since the attribute list may change as we go on
for (int i = 0; i < d.getAttributes().size(); i++) {
Attribute<?> attr = d.getAttributes().get(i);
@SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
if (attr == DrawAttr.FILL_COLOR && this.containsAttribute(DrawAttr.TEXT_DEFAULT_FILL)) {
d.setValue(a, this.getValue(DrawAttr.TEXT_DEFAULT_FILL));
} else if (this.containsAttribute(a)) {
Object value = this.getValue(a);
d.setValue(a, value);
}
}
return drawable;
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class SelectionAttributes method setValue.
@Override
public <V> void setValue(Attribute<V> attr, V value) {
Attribute<?>[] attrs = this.selAttrs;
Object[] values = this.selValues;
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] == attr) {
boolean same = value == null ? values[i] == null : value.equals(values[i]);
if (!same) {
values[i] = value;
for (AttributeSet objAttrs : selected.keySet()) {
objAttrs.setValue(attr, value);
}
}
break;
}
}
}
Aggregations