use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class XmlWriter method addAttributeSetContent.
void addAttributeSetContent(Element elt, AttributeSet attrs, AttributeDefaultProvider source) {
if (attrs == null)
return;
LogisimVersion ver = Main.VERSION;
if (source != null && source.isAllDefaultValues(attrs, ver))
return;
for (Attribute<?> attrBase : attrs.getAttributes()) {
@SuppressWarnings("unchecked") Attribute<Object> attr = (Attribute<Object>) attrBase;
Object val = attrs.getValue(attr);
if (attrs.isToSave(attr) && val != null) {
Object dflt = source == null ? null : source.getDefaultAttributeValue(attr, ver);
if (dflt == null || !dflt.equals(val)) {
Element a = doc.createElement("a");
a.setAttribute("name", attr.getName());
String value = attr.toStandardString(val);
if (attr.getName().equals("filePath") && outFilepath != null) {
Path outFP = Paths.get(outFilepath);
Path attrValP = Paths.get(value);
value = (outFP.relativize(attrValP)).toString();
a.setAttribute("val", value);
} else {
if (value.indexOf("\n") >= 0) {
a.appendChild(doc.createTextNode(value));
} else {
a.setAttribute("val", attr.toStandardString(val));
}
}
elt.appendChild(a);
}
}
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class SelectTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent e, int type) {
HashMap<Component, KeyConfigurator> handlers = keyHandlers;
if (handlers == null) {
handlers = new HashMap<Component, KeyConfigurator>();
Selection sel = canvas.getSelection();
for (Component comp : sel.getComponents()) {
ComponentFactory factory = comp.getFactory();
AttributeSet attrs = comp.getAttributeSet();
Object handler = factory.getFeature(KeyConfigurator.class, attrs);
if (handler != null) {
KeyConfigurator base = (KeyConfigurator) handler;
handlers.put(comp, base.clone());
}
}
keyHandlers = handlers;
}
if (!handlers.isEmpty()) {
boolean consume = false;
ArrayList<KeyConfigurationResult> results;
results = new ArrayList<KeyConfigurationResult>();
for (Map.Entry<Component, KeyConfigurator> entry : handlers.entrySet()) {
Component comp = entry.getKey();
KeyConfigurator handler = entry.getValue();
KeyConfigurationEvent event = new KeyConfigurationEvent(type, comp.getAttributeSet(), e, comp);
KeyConfigurationResult result = handler.keyEventReceived(event);
consume |= event.isConsumed();
if (result != null) {
results.add(result);
}
}
if (consume) {
e.consume();
}
if (!results.isEmpty()) {
SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
for (KeyConfigurationResult result : results) {
Component comp = (Component) result.getEvent().getData();
Map<Attribute<?>, Object> newValues = result.getAttributeValues();
for (Map.Entry<Attribute<?>, Object> entry : newValues.entrySet()) {
act.set(comp, entry.getKey(), entry.getValue());
}
}
if (!act.isEmpty()) {
canvas.getProject().doAction(act);
}
}
}
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class AddTool method getFacing.
private Direction getFacing() {
ComponentFactory source = getFactory();
if (source == null)
return Direction.NORTH;
AttributeSet base = getBaseAttributes();
Object feature = source.getFeature(ComponentFactory.FACING_ATTRIBUTE_KEY, base);
@SuppressWarnings("unchecked") Attribute<Direction> attr = (Attribute<Direction>) feature;
if (attr != null)
return base.getValue(attr);
else
return Direction.NORTH;
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class EditTool method getFacingAttribute.
private Attribute<Direction> getFacingAttribute(Component comp) {
AttributeSet attrs = comp.getAttributeSet();
Object key = ComponentFactory.FACING_ATTRIBUTE_KEY;
Attribute<?> a = (Attribute<?>) comp.getFactory().getFeature(key, attrs);
@SuppressWarnings("unchecked") Attribute<Direction> ret = (Attribute<Direction>) a;
return ret;
}
use of com.cburch.logisim.data.Attribute in project logisim-evolution by reds-heig.
the class AbstractCanvasObject method setForFill.
protected boolean setForFill(Graphics g) {
List<Attribute<?>> attrs = getAttributes();
if (attrs.contains(DrawAttr.PAINT_TYPE)) {
Object value = getValue(DrawAttr.PAINT_TYPE);
if (value == DrawAttr.PAINT_STROKE)
return false;
}
Color color = getValue(DrawAttr.FILL_COLOR);
if (color != null && color.getAlpha() == 0) {
return false;
} else {
if (color != null)
g.setColor(color);
return true;
}
}
Aggregations