Search in sources :

Example 81 with Component

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

the class SelectionItem method circuitChanged.

public void circuitChanged(CircuitEvent event) {
    int action = event.getAction();
    if (action == CircuitEvent.ACTION_CLEAR || action == CircuitEvent.ACTION_REMOVE) {
        Circuit circ = event.getCircuit();
        Component circComp = null;
        if (circ == model.getCircuitState().getCircuit()) {
            circComp = path != null && path.length > 0 ? path[0] : comp;
        } else if (path != null) {
            for (int i = 0; i < path.length; i++) {
                SubcircuitFactory circFact = (SubcircuitFactory) path[i].getFactory();
                if (circ == circFact.getSubcircuit()) {
                    circComp = i + 1 < path.length ? path[i + 1] : comp;
                }
            }
        }
        if (circComp == null)
            return;
        if (action == CircuitEvent.ACTION_REMOVE && event.getData() != circComp) {
            return;
        }
        int index = model.getSelection().indexOf(this);
        if (index < 0)
            return;
        model.getSelection().remove(index);
    }
}
Also used : SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component)

Example 82 with Component

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

the class MenuTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    Location pt = Location.create(x, y);
    JPopupMenu menu;
    Project proj = canvas.getProject();
    Selection sel = proj.getSelection();
    Collection<Component> in_sel = sel.getComponentsContaining(pt, g);
    if (!in_sel.isEmpty()) {
        Component comp = in_sel.iterator().next();
        if (sel.getComponents().size() > 1) {
            menu = new MenuSelection(proj);
        } else {
            menu = new MenuComponent(proj, canvas.getCircuit(), comp);
            MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
            if (extender != null)
                extender.configureMenu(menu, proj);
        }
    } else {
        Collection<Component> cl = canvas.getCircuit().getAllContaining(pt, g);
        if (!cl.isEmpty()) {
            Component comp = cl.iterator().next();
            menu = new MenuComponent(proj, canvas.getCircuit(), comp);
            MenuExtender extender = (MenuExtender) comp.getFeature(MenuExtender.class);
            if (extender != null)
                extender.configureMenu(menu, proj);
        } else {
            menu = null;
        }
    }
    if (menu != null) {
        canvas.showPopupMenu(menu, x, y);
    }
}
Also used : Project(com.cburch.logisim.proj.Project) Selection(com.cburch.logisim.gui.main.Selection) Component(com.cburch.logisim.comp.Component) JPopupMenu(javax.swing.JPopupMenu) Location(com.cburch.logisim.data.Location)

Example 83 with Component

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

the class PokeTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    int x = e.getX();
    int y = e.getY();
    Location loc = Location.create(x, y);
    boolean dirty = false;
    canvas.setHighlightedWires(WireSet.EMPTY);
    if (pokeCaret != null && !pokeCaret.getBounds(g).contains(loc)) {
        dirty = true;
        removeCaret(true);
    }
    if (pokeCaret == null) {
        ComponentUserEvent event = new ComponentUserEvent(canvas, x, y);
        Circuit circ = canvas.getCircuit();
        for (Component c : circ.getAllContaining(loc, g)) {
            if (pokeCaret != null)
                break;
            if (c instanceof Wire) {
                Caret caret = new WireCaret(canvas, (Wire) c, x, y, canvas.getProject().getOptions().getAttributeSet());
                setPokedComponent(circ, c, caret);
                canvas.setHighlightedWires(circ.getWireSet((Wire) c));
            } else {
                Pokable p = (Pokable) c.getFeature(Pokable.class);
                if (p != null) {
                    Caret caret = p.getPokeCaret(event);
                    setPokedComponent(circ, c, caret);
                    AttributeSet attrs = c.getAttributeSet();
                    if (attrs != null && attrs.getAttributes().size() > 0) {
                        Project proj = canvas.getProject();
                        proj.getFrame().viewComponentAttributes(circ, c);
                    }
                }
            }
        }
    }
    if (pokeCaret != null) {
        dirty = true;
        pokeCaret.mousePressed(e);
    }
    if (dirty)
        canvas.getProject().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) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 84 with Component

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

the class SelectTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    Selection sel = proj.getSelection();
    Circuit circuit = canvas.getCircuit();
    start = Location.create(e.getX(), e.getY());
    curDx = 0;
    curDy = 0;
    moveGesture = null;
    // if the user clicks into the selection,
    // selection is being modified
    Collection<Component> in_sel = sel.getComponentsContaining(start, g);
    if (!in_sel.isEmpty()) {
        if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
            setState(proj, MOVING);
            proj.repaintCanvas();
            return;
        } else {
            Action act = SelectionActions.drop(sel, in_sel);
            if (act != null) {
                proj.doAction(act);
            }
        }
    }
    // if the user clicks into a component outside selection, user
    // wants to add/reset selection
    Collection<Component> clicked = circuit.getAllContaining(start, g);
    if (!clicked.isEmpty()) {
        if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
            if (sel.getComponentsContaining(start).isEmpty()) {
                Action act = SelectionActions.dropAll(sel);
                if (act != null) {
                    proj.doAction(act);
                }
            }
        }
        for (Component comp : clicked) {
            if (!in_sel.contains(comp)) {
                sel.add(comp);
            }
        }
        setState(proj, MOVING);
        proj.repaintCanvas();
        return;
    }
    // selection (maybe with the shift key down).
    if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
        Action act = SelectionActions.dropAll(sel);
        if (act != null) {
            proj.doAction(act);
        }
    }
    setState(proj, RECT_SELECT);
    proj.repaintCanvas();
}
Also used : Project(com.cburch.logisim.proj.Project) Action(com.cburch.logisim.proj.Action) Selection(com.cburch.logisim.gui.main.Selection) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component)

Example 85 with Component

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

the class SelectTool method draw.

@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
    Project proj = canvas.getProject();
    int dx = curDx;
    int dy = curDy;
    if (state == MOVING) {
        proj.getSelection().drawGhostsShifted(context, dx, dy);
        MoveGesture gesture = moveGesture;
        if (gesture != null && drawConnections && (dx != 0 || dy != 0)) {
            MoveResult result = gesture.findResult(dx, dy);
            if (result != null) {
                Collection<Wire> wiresToAdd = result.getWiresToAdd();
                Graphics g = context.getGraphics();
                GraphicsUtil.switchToWidth(g, 3);
                g.setColor(Color.GRAY);
                for (Wire w : wiresToAdd) {
                    Location loc0 = w.getEnd0();
                    Location loc1 = w.getEnd1();
                    g.drawLine(loc0.getX(), loc0.getY(), loc1.getX(), loc1.getY());
                }
                GraphicsUtil.switchToWidth(g, 1);
                g.setColor(COLOR_UNMATCHED);
                for (Location conn : result.getUnconnectedLocations()) {
                    int connX = conn.getX();
                    int connY = conn.getY();
                    g.fillOval(connX - 3, connY - 3, 6, 6);
                    g.fillOval(connX + dx - 3, connY + dy - 3, 6, 6);
                }
            }
        }
    } else if (state == RECT_SELECT) {
        int left = start.getX();
        int right = left + dx;
        if (left > right) {
            int i = left;
            left = right;
            right = i;
        }
        int top = start.getY();
        int bot = top + dy;
        if (top > bot) {
            int i = top;
            top = bot;
            bot = i;
        }
        Graphics gBase = context.getGraphics();
        int w = right - left - 1;
        int h = bot - top - 1;
        if (w > 2 && h > 2) {
            gBase.setColor(BACKGROUND_RECT_SELECT);
            gBase.fillRect(left + 1, top + 1, w - 1, h - 1);
        }
        Circuit circ = canvas.getCircuit();
        Bounds bds = Bounds.create(left, top, right - left, bot - top);
        for (Component c : circ.getAllWithin(bds)) {
            Location cloc = c.getLocation();
            Graphics gDup = gBase.create();
            context.setGraphics(gDup);
            c.getFactory().drawGhost(context, COLOR_RECT_SELECT, cloc.getX(), cloc.getY(), c.getAttributeSet());
            gDup.dispose();
        }
        gBase.setColor(COLOR_RECT_SELECT);
        GraphicsUtil.switchToWidth(gBase, 2);
        if (w < 0)
            w = 0;
        if (h < 0)
            h = 0;
        gBase.drawRect(left, top, w, h);
    }
}
Also used : Graphics(java.awt.Graphics) Project(com.cburch.logisim.proj.Project) Bounds(com.cburch.logisim.data.Bounds) MoveGesture(com.cburch.logisim.tools.move.MoveGesture) Circuit(com.cburch.logisim.circuit.Circuit) MoveResult(com.cburch.logisim.tools.move.MoveResult) Wire(com.cburch.logisim.circuit.Wire) 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