Search in sources :

Example 1 with Selection

use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.

the class AppearanceEditHandler method duplicate.

@Override
public void duplicate() {
    Selection sel = canvas.getSelection();
    int n = sel.getSelected().size();
    List<CanvasObject> select = new ArrayList<CanvasObject>(n);
    List<CanvasObject> clones = new ArrayList<CanvasObject>(n);
    for (CanvasObject o : sel.getSelected()) {
        if (o.canRemove()) {
            CanvasObject copy = o.clone();
            copy.translate(10, 10);
            clones.add(copy);
            select.add(copy);
        } else {
            select.add(o);
        }
    }
    if (!clones.isEmpty()) {
        canvas.getProject().doAction(new SelectionAction(canvas, Strings.getter("duplicateSelectionAction"), null, clones, select, null, null));
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ArrayList(java.util.ArrayList)

Example 2 with Selection

use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.

the class AppearanceEditHandler method computeEnabled.

@Override
public void computeEnabled() {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    Selection sel = canvas.getSelection();
    boolean selEmpty = sel.isEmpty();
    boolean canChange = proj.getLogisimFile().contains(circ);
    boolean clipExists = !Clipboard.isEmpty();
    boolean selHasRemovable = false;
    for (CanvasObject o : sel.getSelected()) {
        if (!(o instanceof AppearanceElement)) {
            selHasRemovable = true;
        }
    }
    boolean canRaise;
    boolean canLower;
    if (!selEmpty && canChange) {
        Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
        int zmin = Integer.MAX_VALUE;
        int zmax = Integer.MIN_VALUE;
        int count = 0;
        for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
            if (!(entry.getKey() instanceof AppearanceElement)) {
                count++;
                int z = entry.getValue().intValue();
                if (z < zmin)
                    zmin = z;
                if (z > zmax)
                    zmax = z;
            }
        }
        int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
        if (count > 0 && count <= maxPoss) {
            canRaise = zmin <= maxPoss - count;
            canLower = zmax >= count;
        } else {
            canRaise = false;
            canLower = false;
        }
    } else {
        canRaise = false;
        canLower = false;
    }
    boolean canAddCtrl = false;
    boolean canRemCtrl = false;
    Handle handle = sel.getSelectedHandle();
    if (handle != null && canChange) {
        CanvasObject o = handle.getObject();
        canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
        canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
    }
    setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.COPY, !selEmpty);
    setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
    setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
    setEnabled(LogisimMenuBar.SELECT_ALL, true);
    setEnabled(LogisimMenuBar.RAISE, canRaise);
    setEnabled(LogisimMenuBar.LOWER, canLower);
    setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
    setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
    setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
    setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
Also used : Project(com.cburch.logisim.proj.Project) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement) Map(java.util.Map) Handle(com.cburch.draw.model.Handle)

Example 3 with Selection

use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.

the class SelectionAction method doIt.

@Override
public void doIt(Project proj) {
    Selection sel = canvas.getSelection();
    sel.clearSelected();
    if (toRemove != null)
        canvasModel.removeObjects(toRemove.keySet());
    int dest = AppearanceCanvas.getMaxIndex(canvasModel) + 1;
    if (toAdd != null)
        canvasModel.addObjects(dest, toAdd);
    AppearanceAnchor anchor = findAnchor(canvasModel);
    if (anchor != null && anchorNewLocation != null) {
        anchorOldLocation = anchor.getLocation();
        anchor.translate(anchorNewLocation.getX() - anchorOldLocation.getX(), anchorNewLocation.getY() - anchorOldLocation.getY());
    }
    if (anchor != null && anchorNewFacing != null) {
        anchorOldFacing = anchor.getFacing();
        anchor.setValue(AppearanceAnchor.FACING, anchorNewFacing);
    }
    sel.setSelected(newSelection, true);
    canvas.repaint();
}
Also used : Selection(com.cburch.draw.canvas.Selection) AppearanceAnchor(com.cburch.logisim.circuit.appear.AppearanceAnchor)

Example 4 with Selection

use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.

the class SelectTool method keyTyped.

@Override
public void keyTyped(Canvas canvas, KeyEvent e) {
    char ch = e.getKeyChar();
    Selection selected = canvas.getSelection();
    if ((ch == '\u0008' || ch == '\u007F') && !selected.isEmpty()) {
        ArrayList<CanvasObject> toRemove = new ArrayList<CanvasObject>();
        for (CanvasObject shape : selected.getSelected()) {
            if (shape.canRemove()) {
                toRemove.add(shape);
            }
        }
        if (!toRemove.isEmpty()) {
            e.consume();
            CanvasModel model = canvas.getModel();
            canvas.doAction(new ModelRemoveAction(model, toRemove));
            selected.clearSelected();
            repaintArea(canvas);
        }
    } else if (ch == '\u001b' && !selected.isEmpty()) {
        selected.clearSelected();
        repaintArea(canvas);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ArrayList(java.util.ArrayList) ModelRemoveAction(com.cburch.draw.actions.ModelRemoveAction) CanvasModel(com.cburch.draw.model.CanvasModel)

Example 5 with Selection

use of com.cburch.draw.canvas.Selection in project logisim-evolution by reds-heig.

the class AttrTableSelectionModel method getTitle.

@Override
public String getTitle() {
    Selection sel = canvas.getSelection();
    Class<? extends CanvasObject> commonClass = null;
    int commonCount = 0;
    CanvasObject firstObject = null;
    int totalCount = 0;
    for (CanvasObject obj : sel.getSelected()) {
        if (firstObject == null) {
            firstObject = obj;
            commonClass = obj.getClass();
            commonCount = 1;
        } else if (obj.getClass() == commonClass) {
            commonCount++;
        } else {
            commonClass = null;
        }
        totalCount++;
    }
    if (firstObject == null) {
        return null;
    } else if (commonClass == null) {
        return Strings.get("selectionVarious", "" + totalCount);
    } else if (commonCount == 1) {
        return Strings.get("selectionOne", firstObject.getDisplayName());
    } else {
        return Strings.get("selectionMultiple", firstObject.getDisplayName(), "" + commonCount);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection)

Aggregations

Selection (com.cburch.draw.canvas.Selection)14 CanvasObject (com.cburch.draw.model.CanvasObject)9 Handle (com.cburch.draw.model.Handle)7 HandleGesture (com.cburch.draw.model.HandleGesture)3 AppearanceAnchor (com.cburch.logisim.circuit.appear.AppearanceAnchor)3 Location (com.cburch.logisim.data.Location)3 ArrayList (java.util.ArrayList)3 CanvasModel (com.cburch.draw.model.CanvasModel)2 ModelDeleteHandleAction (com.cburch.draw.actions.ModelDeleteHandleAction)1 ModelInsertHandleAction (com.cburch.draw.actions.ModelInsertHandleAction)1 ModelMoveHandleAction (com.cburch.draw.actions.ModelMoveHandleAction)1 ModelRemoveAction (com.cburch.draw.actions.ModelRemoveAction)1 ModelTranslateAction (com.cburch.draw.actions.ModelTranslateAction)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1 Bounds (com.cburch.logisim.data.Bounds)1 Direction (com.cburch.logisim.data.Direction)1 Project (com.cburch.logisim.proj.Project)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1