Search in sources :

Example 16 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class ComponentSelector method getSelectedItems.

public List<SelectionItem> getSelectedItems() {
    TreePath[] sel = getSelectionPaths();
    if (sel == null || sel.length == 0)
        return Collections.emptyList();
    ArrayList<SelectionItem> ret = new ArrayList<SelectionItem>();
    for (int i = 0; i < sel.length; i++) {
        TreePath path = sel[i];
        Object last = path.getLastPathComponent();
        ComponentNode n = null;
        Object opt = null;
        if (last instanceof OptionNode) {
            OptionNode o = (OptionNode) last;
            n = o.parent;
            opt = o.option;
        } else if (last instanceof ComponentNode) {
            n = (ComponentNode) last;
            if (n.opts != null)
                n = null;
        }
        if (n != null) {
            int count = 0;
            for (CircuitNode cur = n.parent; cur != null; cur = cur.parent) {
                count++;
            }
            Component[] nPath = new Component[count - 1];
            CircuitNode cur = n.parent;
            for (int j = nPath.length - 1; j >= 0; j--) {
                nPath[j] = cur.subcircComp;
                cur = cur.parent;
            }
            ret.add(new SelectionItem(logModel, nPath, n.comp, opt));
        }
    }
    return ret.size() == 0 ? null : ret;
}
Also used : TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) Component(com.cburch.logisim.comp.Component)

Example 17 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class EditTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    boolean wire = updateLocation(canvas, e);
    Location oldWireLoc = wireLoc;
    wireLoc = NULL_LOCATION;
    lastX = Integer.MIN_VALUE;
    if (wire) {
        current = wiring;
        Selection sel = canvas.getSelection();
        Circuit circ = canvas.getCircuit();
        Collection<Component> selected = sel.getAnchoredComponents();
        ArrayList<Component> suppress = null;
        for (Wire w : circ.getWires()) {
            if (selected.contains(w)) {
                if (w.contains(oldWireLoc)) {
                    if (suppress == null)
                        suppress = new ArrayList<Component>();
                    suppress.add(w);
                }
            }
        }
        sel.setSuppressHandles(suppress);
    } else {
        current = select;
    }
    pressX = e.getX();
    pressY = e.getY();
    current.mousePressed(canvas, g, e);
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 18 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class EditTool method attemptReface.

private void attemptReface(Canvas canvas, final Direction facing, KeyEvent e) {
    if (e.getModifiersEx() == 0) {
        final Circuit circuit = canvas.getCircuit();
        final Selection sel = canvas.getSelection();
        SetAttributeAction act = new SetAttributeAction(circuit, Strings.getter("selectionRefaceAction"));
        for (Component comp : sel.getComponents()) {
            if (!(comp instanceof Wire)) {
                Attribute<Direction> attr = getFacingAttribute(comp);
                if (attr != null) {
                    act.set(comp, attr, facing);
                }
            }
        }
        if (!act.isEmpty()) {
            canvas.getProject().doAction(act);
            e.consume();
        }
    }
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Direction(com.cburch.logisim.data.Direction)

Example 19 with Component

use of com.cburch.logisim.comp.Component in project logisim-evolution by reds-heig.

the class SelectTool method keyPressed.

@Override
public void keyPressed(Canvas canvas, KeyEvent e) {
    if (state == MOVING && e.getKeyCode() == KeyEvent.VK_SHIFT) {
        handleMoveDrag(canvas, curDx, curDy, e.getModifiersEx());
    } else {
        SortedSet<Component> comps = AutoLabel.Sort(canvas.getProject().getSelection().getComponents());
        int KeybEvent = e.getKeyCode();
        boolean KeyTaken = false;
        for (Component comp : comps) {
            SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
            KeyTaken |= GateKeyboardModifier.TookKeyboardStrokes(KeybEvent, comp, comp.getAttributeSet(), canvas, act, true);
            if (!act.isEmpty())
                canvas.getProject().doAction(act);
        }
        if (!KeyTaken) {
            for (Component comp : comps) {
                SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
                KeyTaken |= AutoLabler.LabelKeyboardHandler(KeybEvent, comp.getAttributeSet(), comp.getFactory().getDisplayName(), comp, comp.getFactory(), canvas.getCircuit(), act, true);
                if (!act.isEmpty())
                    canvas.getProject().doAction(act);
            }
        }
        if (!KeyTaken)
            switch(KeybEvent) {
                case KeyEvent.VK_BACK_SPACE:
                case KeyEvent.VK_DELETE:
                    if (!canvas.getSelection().isEmpty()) {
                        Action act = SelectionActions.clear(canvas.getSelection());
                        canvas.getProject().doAction(act);
                        e.consume();
                    }
                    break;
                default:
                    processKeyEvent(canvas, e, KeyConfigurationEvent.KEY_PRESSED);
            }
    }
}
Also used : Action(com.cburch.logisim.proj.Action) Component(com.cburch.logisim.comp.Component)

Example 20 with Component

use of com.cburch.logisim.comp.Component 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)

Aggregations

Component (com.cburch.logisim.comp.Component)97 Location (com.cburch.logisim.data.Location)26 ArrayList (java.util.ArrayList)20 Circuit (com.cburch.logisim.circuit.Circuit)19 AttributeSet (com.cburch.logisim.data.AttributeSet)13 Wire (com.cburch.logisim.circuit.Wire)12 Bounds (com.cburch.logisim.data.Bounds)11 HashMap (java.util.HashMap)11 HashSet (java.util.HashSet)11 SubcircuitFactory (com.cburch.logisim.circuit.SubcircuitFactory)8 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)8 EndData (com.cburch.logisim.comp.EndData)8 InstanceComponent (com.cburch.logisim.instance.InstanceComponent)8 Project (com.cburch.logisim.proj.Project)7 Pin (com.cburch.logisim.std.wiring.Pin)7 Graphics (java.awt.Graphics)7 CircuitState (com.cburch.logisim.circuit.CircuitState)6 Splitter (com.cburch.logisim.circuit.Splitter)6 Selection (com.cburch.logisim.gui.main.Selection)6 InstanceState (com.cburch.logisim.instance.InstanceState)5