Search in sources :

Example 6 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class AddTool method getBounds.

private Bounds getBounds() {
    Bounds ret = bounds;
    if (ret == null) {
        ComponentFactory source = getFactory();
        if (source == null) {
            ret = Bounds.EMPTY_BOUNDS;
        } else {
            AttributeSet base = getBaseAttributes();
            ret = source.getOffsetBounds(base).expand(5);
        }
        bounds = ret;
    }
    return ret;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Bounds(com.cburch.logisim.data.Bounds) ComponentFactory(com.cburch.logisim.comp.ComponentFactory)

Example 7 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class AddTool method getFactory.

public ComponentFactory getFactory() {
    ComponentFactory ret = factory;
    if (ret != null || sourceLoadAttempted) {
        return ret;
    } else {
        ret = description.getFactory(descriptionBase);
        if (ret != null) {
            AttributeSet base = getBaseAttributes();
            Boolean value = (Boolean) ret.getFeature(ComponentFactory.SHOULD_SNAP, base);
            shouldSnap = value == null ? true : value.booleanValue();
        }
        factory = ret;
        sourceLoadAttempted = true;
        return ret;
    }
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory)

Example 8 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class FactoryAttributes method getBase.

AttributeSet getBase() {
    AttributeSet ret = baseAttrs;
    if (ret == null) {
        ComponentFactory fact = factory;
        if (fact == null) {
            fact = desc.getFactory(descBase);
            factory = fact;
        }
        if (fact == null) {
            ret = AttributeSets.EMPTY;
        } else {
            ret = fact.createAttributeSet();
            ret.addAttributeListener(this);
        }
        baseAttrs = ret;
    }
    return ret;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentFactory(com.cburch.logisim.comp.ComponentFactory)

Example 9 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class TextTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    if (!proj.getLogisimFile().contains(circ)) {
        if (caret != null)
            caret.cancelEditing();
        canvas.setErrorMessage(Strings.getter("cannotModifyError"));
        return;
    }
    // Maybe user is clicking within the current caret.
    if (caret != null) {
        if (caret.getBounds(g).contains(e.getX(), e.getY())) {
            // Yes
            caret.mousePressed(e);
            proj.repaintCanvas();
            return;
        } else {
            // No. End the current caret.
            caret.stopEditing();
        }
    }
    // caret will be null at this point
    // Otherwise search for a new caret.
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
    // First search in selection.
    for (Component comp : proj.getSelection().getComponentsContaining(loc, g)) {
        TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            if (caret != null) {
                proj.getFrame().viewComponentAttributes(circ, comp);
                caretComponent = comp;
                caretCreatingText = false;
                break;
            }
        }
    }
    // Then search in circuit
    if (caret == null) {
        for (Component comp : circ.getAllContaining(loc, g)) {
            TextEditable editable = (TextEditable) comp.getFeature(TextEditable.class);
            if (editable != null) {
                caret = editable.getTextCaret(event);
                if (caret != null) {
                    proj.getFrame().viewComponentAttributes(circ, comp);
                    caretComponent = comp;
                    caretCreatingText = false;
                    break;
                }
            }
        }
    }
    // if nothing found, create a new label
    if (caret == null) {
        if (loc.getX() < 0 || loc.getY() < 0)
            return;
        AttributeSet copy = (AttributeSet) attrs.clone();
        caretComponent = Text.FACTORY.createComponent(loc, copy);
        caretCreatingText = true;
        TextEditable editable = (TextEditable) caretComponent.getFeature(TextEditable.class);
        if (editable != null) {
            caret = editable.getTextCaret(event);
            proj.getFrame().viewComponentAttributes(circ, caretComponent);
        }
    }
    if (caret != null) {
        caretCanvas = canvas;
        caretCircuit = canvas.getCircuit();
        caret.addCaretListener(listener);
        caretCircuit.addCircuitListener(listener);
    }
    proj.repaintCanvas();
}
Also used : Project(com.cburch.logisim.proj.Project) AttributeSet(com.cburch.logisim.data.AttributeSet) ComponentUserEvent(com.cburch.logisim.comp.ComponentUserEvent) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

Example 10 with AttributeSet

use of com.cburch.logisim.data.AttributeSet in project logisim-evolution by reds-heig.

the class NumericConfigurator method keyEventReceived.

public KeyConfigurationResult keyEventReceived(KeyConfigurationEvent event) {
    if (event.getType() == KeyConfigurationEvent.KEY_TYPED) {
        KeyEvent e = event.getKeyEvent();
        int digit = Character.digit(e.getKeyChar(), radix);
        if (digit >= 0 && e.getModifiersEx() == modsEx) {
            long now = System.currentTimeMillis();
            long sinceLast = now - whenTyped;
            AttributeSet attrs = event.getAttributeSet();
            int min = getMinimumValue(attrs);
            int max = getMaximumValue(attrs);
            int val = 0;
            if (sinceLast < MAX_TIME_KEY_LASTS) {
                val = radix * curValue;
                if (val > max) {
                    val = 0;
                }
            }
            val += digit;
            if (val > max) {
                val = digit;
                if (val > max) {
                    return null;
                }
            }
            event.consume();
            whenTyped = now;
            curValue = val;
            if (val >= min) {
                Object valObj = createValue(val);
                return new KeyConfigurationResult(event, attr, valObj);
            }
        }
    }
    return null;
}
Also used : KeyEvent(java.awt.event.KeyEvent) AttributeSet(com.cburch.logisim.data.AttributeSet)

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