use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.
the class AddTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
Component added = null;
if (state == SHOW_ADD) {
Circuit circ = canvas.getCircuit();
if (!canvas.getProject().getLogisimFile().contains(circ))
return;
if (shouldSnap)
Canvas.snapToGrid(e);
moveTo(canvas, g, e.getX(), e.getY());
Location loc = Location.create(e.getX(), e.getY());
ComponentFactory source = getFactory();
AttributeSet attrsCopy = (AttributeSet) attrs.clone();
if (attrsCopy.containsAttribute(StdAttr.LABEL)) {
attrsCopy.setValue(StdAttr.LABEL, AutoLabler.GetCurrent(canvas.getCircuit(), source));
if (AutoLabler.IsActive(canvas.getCircuit())) {
if (AutoLabler.hasNext(canvas.getCircuit()))
AutoLabler.GetNext(canvas.getCircuit(), source);
else
AutoLabler.Stop(canvas.getCircuit());
} else
AutoLabler.SetLabel("", canvas.getCircuit(), source);
}
if (source == null)
return;
Component c = source.createComponent(loc, attrsCopy);
if (circ.hasConflict(c)) {
canvas.setErrorMessage(Strings.getter("exclusiveError"));
return;
}
Bounds bds = c.getBounds(g);
if (bds.getX() < 0 || bds.getY() < 0) {
canvas.setErrorMessage(Strings.getter("negativeCoordError"));
return;
}
try {
CircuitMutation mutation = new CircuitMutation(circ);
mutation.add(c);
Action action = mutation.toAction(Strings.getter("addComponentAction", factory.getDisplayGetter()));
canvas.getProject().doAction(action);
lastAddition = action;
added = c;
canvas.repaint();
} catch (CircuitException ex) {
JOptionPane.showMessageDialog(canvas.getProject().getFrame(), ex.getMessage());
}
setState(canvas, SHOW_GHOST);
} else if (state == SHOW_ADD_NO) {
setState(canvas, SHOW_NONE);
}
Project proj = canvas.getProject();
Tool next = determineNext(proj);
if (next != null) {
proj.setTool(next);
Action act = SelectionActions.dropAll(canvas.getSelection());
if (act != null) {
proj.doAction(act);
}
if (added != null)
canvas.getSelection().add(added);
}
}
use of com.cburch.logisim.data.AttributeSet 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.AttributeSet in project logisim-evolution by reds-heig.
the class AddTool method processKeyEvent.
private void processKeyEvent(Canvas canvas, KeyEvent event, int type) {
KeyConfigurator handler = keyHandler;
if (!keyHandlerTried) {
ComponentFactory source = getFactory();
AttributeSet baseAttrs = getBaseAttributes();
handler = (KeyConfigurator) source.getFeature(KeyConfigurator.class, baseAttrs);
keyHandler = handler;
keyHandlerTried = true;
}
if (handler != null) {
AttributeSet baseAttrs = getBaseAttributes();
KeyConfigurationEvent e = new KeyConfigurationEvent(type, baseAttrs, event, this);
KeyConfigurationResult r = handler.keyEventReceived(e);
if (r != null) {
Action act = ToolAttributeAction.create(r);
canvas.getProject().doAction(act);
}
}
}
use of com.cburch.logisim.data.AttributeSet 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.AttributeSet in project logisim-evolution by reds-heig.
the class AttrTableSelectionModel method setValueRequested.
@Override
public void setValueRequested(Attribute<Object> attr, Object value) throws AttrTableSetException {
SelectionAttributes attrs = (SelectionAttributes) getAttributeSet();
Map<AttributeMapKey, Object> oldVals;
oldVals = new HashMap<AttributeMapKey, Object>();
Map<AttributeMapKey, Object> newVals;
newVals = new HashMap<AttributeMapKey, Object>();
for (Map.Entry<AttributeSet, CanvasObject> ent : attrs.entries()) {
AttributeMapKey key = new AttributeMapKey(attr, ent.getValue());
oldVals.put(key, ent.getKey().getValue(attr));
newVals.put(key, value);
}
CanvasModel model = canvas.getModel();
canvas.doAction(new ModelChangeAttributeAction(model, oldVals, newVals));
fireTitleChanged();
}
Aggregations