Search in sources :

Example 56 with AttributeSet

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);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) CircuitException(com.cburch.logisim.circuit.CircuitException) AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Bounds(com.cburch.logisim.data.Bounds) CircuitMutation(com.cburch.logisim.circuit.CircuitMutation) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 57 with AttributeSet

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;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) Direction(com.cburch.logisim.data.Direction)

Example 58 with AttributeSet

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);
        }
    }
}
Also used : KeyConfigurationResult(com.cburch.logisim.tools.key.KeyConfigurationResult) Action(com.cburch.logisim.proj.Action) ToolAttributeAction(com.cburch.logisim.gui.main.ToolAttributeAction) AttributeSet(com.cburch.logisim.data.AttributeSet) KeyConfigurationEvent(com.cburch.logisim.tools.key.KeyConfigurationEvent) ComponentFactory(com.cburch.logisim.comp.ComponentFactory) KeyConfigurator(com.cburch.logisim.tools.key.KeyConfigurator)

Example 59 with AttributeSet

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;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Attribute(com.cburch.logisim.data.Attribute) Direction(com.cburch.logisim.data.Direction)

Example 60 with AttributeSet

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();
}
Also used : AttributeMapKey(com.cburch.draw.model.AttributeMapKey) CanvasObject(com.cburch.draw.model.CanvasObject) AttributeSet(com.cburch.logisim.data.AttributeSet) CanvasObject(com.cburch.draw.model.CanvasObject) CanvasModel(com.cburch.draw.model.CanvasModel) ModelChangeAttributeAction(com.cburch.draw.actions.ModelChangeAttributeAction) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AttributeSet (com.cburch.logisim.data.AttributeSet)65 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)16 Component (com.cburch.logisim.comp.Component)13 TreeMap (java.util.TreeMap)13 Attribute (com.cburch.logisim.data.Attribute)12 Location (com.cburch.logisim.data.Location)9 HashMap (java.util.HashMap)7 Value (com.cburch.logisim.data.Value)6 Circuit (com.cburch.logisim.circuit.Circuit)5 Direction (com.cburch.logisim.data.Direction)4 Graphics (java.awt.Graphics)4 Map (java.util.Map)4 CircuitMutation (com.cburch.logisim.circuit.CircuitMutation)3 Wire (com.cburch.logisim.circuit.Wire)3 AbstractAttributeSet (com.cburch.logisim.data.AbstractAttributeSet)3 BitWidth (com.cburch.logisim.data.BitWidth)3 Bounds (com.cburch.logisim.data.Bounds)3 ToolAttributeAction (com.cburch.logisim.gui.main.ToolAttributeAction)3 Action (com.cburch.logisim.proj.Action)3 Project (com.cburch.logisim.proj.Project)3