Search in sources :

Example 1 with MoveGesture

use of com.cburch.logisim.tools.move.MoveGesture in project logisim-evolution by reds-heig.

the class SelectTool method handleMoveDrag.

private void handleMoveDrag(Canvas canvas, int dx, int dy, int modsEx) {
    boolean connect = shouldConnect(canvas, modsEx);
    drawConnections = connect;
    if (connect) {
        MoveGesture gesture = moveGesture;
        if (gesture == null) {
            gesture = new MoveGesture(new MoveRequestHandler(canvas), canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
            moveGesture = gesture;
        }
        if (dx != 0 || dy != 0) {
            boolean queued = gesture.enqueueRequest(dx, dy);
            if (queued) {
                canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
                // doesn't hurt to check to ensure the message belongs.
                if (gesture.findResult(dx, dy) != null) {
                    clearCanvasMessage(canvas, dx, dy);
                }
            }
        }
    }
    canvas.repaint();
}
Also used : MoveGesture(com.cburch.logisim.tools.move.MoveGesture)

Example 2 with MoveGesture

use of com.cburch.logisim.tools.move.MoveGesture 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)

Example 3 with MoveGesture

use of com.cburch.logisim.tools.move.MoveGesture in project logisim-evolution by reds-heig.

the class SelectTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, Graphics g, MouseEvent e) {
    Project proj = canvas.getProject();
    if (state == MOVING) {
        setState(proj, IDLE);
        computeDxDy(proj, e, g);
        int dx = curDx;
        int dy = curDy;
        if (dx != 0 || dy != 0) {
            if (!proj.getLogisimFile().contains(canvas.getCircuit())) {
                canvas.setErrorMessage(Strings.getter("cannotModifyError"));
            } else if (proj.getSelection().hasConflictWhenMoved(dx, dy)) {
                canvas.setErrorMessage(Strings.getter("exclusiveError"));
            } else {
                boolean connect = shouldConnect(canvas, e.getModifiersEx());
                drawConnections = false;
                ReplacementMap repl;
                if (connect) {
                    MoveGesture gesture = moveGesture;
                    if (gesture == null) {
                        gesture = new MoveGesture(new MoveRequestHandler(canvas), canvas.getCircuit(), canvas.getSelection().getAnchoredComponents());
                    }
                    canvas.setErrorMessage(new ComputingMessage(dx, dy), COLOR_COMPUTING);
                    MoveResult result = gesture.forceRequest(dx, dy);
                    clearCanvasMessage(canvas, dx, dy);
                    repl = result.getReplacementMap();
                } else {
                    repl = null;
                }
                Selection sel = proj.getSelection();
                proj.doAction(SelectionActions.translate(sel, dx, dy, repl));
            }
        }
        moveGesture = null;
        proj.repaintCanvas();
    } else if (state == RECT_SELECT) {
        Bounds bds = Bounds.create(start).add(start.getX() + curDx, start.getY() + curDy);
        Circuit circuit = canvas.getCircuit();
        Selection sel = proj.getSelection();
        Collection<Component> in_sel = sel.getComponentsWithin(bds, g);
        for (Component comp : circuit.getAllWithin(bds, g)) {
            if (!in_sel.contains(comp))
                sel.add(comp);
        }
        Action act = SelectionActions.drop(sel, in_sel);
        if (act != null) {
            proj.doAction(act);
        }
        setState(proj, IDLE);
        proj.repaintCanvas();
    }
    if (e.getClickCount() >= 2) {
        Set<Component> comps = canvas.getProject().getSelection().getComponents();
        if (comps.size() == 1) {
            for (Component comp : comps) {
                if (comp.getAttributeSet().containsAttribute(StdAttr.LABEL)) {
                    String OldLabel = comp.getAttributeSet().getValue(StdAttr.LABEL);
                    SetAttributeAction act = new SetAttributeAction(canvas.getCircuit(), Strings.getter("changeComponentAttributesAction"));
                    AutoLabler.AskAndSetLabel(comp.getFactory().getDisplayName(), OldLabel, canvas.getCircuit(), comp, comp.getFactory(), comp.getAttributeSet(), act, true);
                    if (!act.isEmpty())
                        canvas.getProject().doAction(act);
                }
            }
        }
    }
}
Also used : Action(com.cburch.logisim.proj.Action) Selection(com.cburch.logisim.gui.main.Selection) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Project(com.cburch.logisim.proj.Project) Collection(java.util.Collection) MoveGesture(com.cburch.logisim.tools.move.MoveGesture) MoveResult(com.cburch.logisim.tools.move.MoveResult) ReplacementMap(com.cburch.logisim.circuit.ReplacementMap) Component(com.cburch.logisim.comp.Component)

Example 4 with MoveGesture

use of com.cburch.logisim.tools.move.MoveGesture in project logisim-evolution by reds-heig.

the class SelectTool method getHiddenComponents.

@Override
public Set<Component> getHiddenComponents(Canvas canvas) {
    if (state == MOVING) {
        int dx = curDx;
        int dy = curDy;
        if (dx == 0 && dy == 0) {
            return null;
        }
        Set<Component> sel = canvas.getSelection().getComponents();
        MoveGesture gesture = moveGesture;
        if (gesture != null && drawConnections) {
            MoveResult result = gesture.findResult(dx, dy);
            if (result != null) {
                HashSet<Component> ret = new HashSet<Component>(sel);
                ret.addAll(result.getReplacementMap().getRemovals());
                return ret;
            }
        }
        return sel;
    } else {
        return null;
    }
}
Also used : MoveGesture(com.cburch.logisim.tools.move.MoveGesture) MoveResult(com.cburch.logisim.tools.move.MoveResult) Component(com.cburch.logisim.comp.Component) HashSet(java.util.HashSet)

Aggregations

MoveGesture (com.cburch.logisim.tools.move.MoveGesture)4 Component (com.cburch.logisim.comp.Component)3 MoveResult (com.cburch.logisim.tools.move.MoveResult)3 Circuit (com.cburch.logisim.circuit.Circuit)2 Bounds (com.cburch.logisim.data.Bounds)2 Project (com.cburch.logisim.proj.Project)2 ReplacementMap (com.cburch.logisim.circuit.ReplacementMap)1 Wire (com.cburch.logisim.circuit.Wire)1 Location (com.cburch.logisim.data.Location)1 Selection (com.cburch.logisim.gui.main.Selection)1 Action (com.cburch.logisim.proj.Action)1 Graphics (java.awt.Graphics)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1