Search in sources :

Example 1 with ModelRemoveAction

use of com.cburch.draw.actions.ModelRemoveAction 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 2 with ModelRemoveAction

use of com.cburch.draw.actions.ModelRemoveAction in project logisim-evolution by reds-heig.

the class TextTool method commitText.

private void commitText(Canvas canvas) {
    Text cur = curText;
    boolean isNew = isTextNew;
    String newText = field.getText();
    if (cur == null) {
        return;
    }
    cancelText(canvas);
    if (isNew) {
        if (!newText.equals("")) {
            cur.setText(newText);
            canvas.doAction(new ModelAddAction(canvas.getModel(), cur));
        }
    } else {
        String oldText = cur.getText();
        if (newText.equals("")) {
            canvas.doAction(new ModelRemoveAction(canvas.getModel(), cur));
        } else if (!oldText.equals(newText)) {
            canvas.doAction(new ModelEditTextAction(canvas.getModel(), cur, newText));
        }
    }
}
Also used : ModelAddAction(com.cburch.draw.actions.ModelAddAction) ModelRemoveAction(com.cburch.draw.actions.ModelRemoveAction) Text(com.cburch.draw.shapes.Text) ModelEditTextAction(com.cburch.draw.actions.ModelEditTextAction)

Aggregations

ModelRemoveAction (com.cburch.draw.actions.ModelRemoveAction)2 ModelAddAction (com.cburch.draw.actions.ModelAddAction)1 ModelEditTextAction (com.cburch.draw.actions.ModelEditTextAction)1 Selection (com.cburch.draw.canvas.Selection)1 CanvasModel (com.cburch.draw.model.CanvasModel)1 CanvasObject (com.cburch.draw.model.CanvasObject)1 Text (com.cburch.draw.shapes.Text)1 ArrayList (java.util.ArrayList)1