Package org.joshy.sketch.actions

Source Code of org.joshy.sketch.actions.DeleteSelectedNodeAction

package org.joshy.sketch.actions;

import org.joshy.sketch.modes.vector.VectorDocContext;
import org.joshy.sketch.model.SNode;
import org.joshy.sketch.model.SketchDocument;

import java.util.ArrayList;
import java.util.List;

import static org.joshy.gfx.util.localization.Localization.getString;

/**
* Created by IntelliJ IDEA.
* User: joshmarinacci
* Date: Apr 6, 2010
* Time: 7:50:03 PM
* To change this template use File | Settings | File Templates.
*/
public class DeleteSelectedNodeAction extends SAction {
    private VectorDocContext context;

    public DeleteSelectedNodeAction(VectorDocContext context) {
        this.context = context;
    }

    @Override
    public CharSequence getDisplayName() {
        return getString("menus.delete");
    }

    @Override
    public void execute() {
        final List<SNode> shp = new ArrayList<SNode>();
        final SketchDocument doc = (SketchDocument) context.getDocument();
        for(SNode node : context.getSelection().items()) {
            doc.getCurrentPage().remove(node);
            shp.add(node);
        }
        context.getSelection().clear();
        context.redraw();

        context.getUndoManager().pushAction(new UndoManager.UndoableAction(){
            public void executeUndo() {
                for(SNode shape : shp) {
                    doc.getCurrentPage().add(shape);
                }
                context.redraw();
            }
            public void executeRedo() {
                for(SNode shape : shp) {
                    doc.getCurrentPage().remove(shape);
                }
                context.redraw();
            }
            public String getName() {
                return "delete";
            }
        });

    }
}
TOP

Related Classes of org.joshy.sketch.actions.DeleteSelectedNodeAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.