Example usage for javax.swing.undo UndoManager canUndo

List of usage examples for javax.swing.undo UndoManager canUndo

Introduction

In this page you can find the example usage for javax.swing.undo UndoManager canUndo.

Prototype

public synchronized boolean canUndo() 

Source Link

Document

Returns true if edits may be undone.

Usage

From source file:org.pmedv.blackboard.commands.RotateCCWCommand.java

@Override
public void execute(ActionEvent e) {

    ApplicationContext ctx = AppContext.getContext();
    BoardEditor editor = EditorUtils.getCurrentActiveEditor();
    UndoManager undoManager = editor.getUndoManager();

    if (editor.getSelectedItem() != null) {
        if (editor.getSelectedItem() instanceof Rotateable) {
            Rotateable part = (Rotateable) editor.getSelectedItem();
            part.rotateCCW();//from   w ww.  ja v a  2 s.c om
            if (!undoManager.addEdit(new RotateCCWEdit(part))) {
                log.info("Could not add edit : " + this.getClass());
            }
            editor.refresh();
        }
    }

    ctx.getBean(RedoCommand.class).setEnabled(undoManager.canRedo());
    ctx.getBean(UndoCommand.class).setEnabled(undoManager.canUndo());

}

From source file:org.pmedv.blackboard.commands.RotateCWCommand.java

@Override
public void execute(ActionEvent evt) {

    ApplicationContext ctx = AppContext.getContext();
    BoardEditor editor = EditorUtils.getCurrentActiveEditor();
    UndoManager undoManager = editor.getUndoManager();

    if (editor.getSelectedItem() != null) {
        if (editor.getSelectedItem() instanceof Rotateable) {

            if (editor.getSelectedItem() instanceof Part) {
                //               BoardUtil.findConnectionsToItem(editor.getSelectedItem(), editor.getModel());
                //               Part part = (Part)editor.getSelectedItem();            
                //               if (editor.isMagnetic()) {
                //                  
                //                  for (WireConnection wc : part.getWireConnections()) {
                //                     
                //                     if (wc.getType().equals(WireConnectionType.START)) {                     
                //                        Point s = BoardUtil.rotatePoint(wc.getLine().getStart().getX(), wc.getLine().getStart().getY(), part.getXLoc(), part.getYLoc(), -90);
                //                        wc.getLine().getStart().setLocation(BoardUtil.snap(s.x, editor.getRaster()),BoardUtil.snap(s.y, editor.getRaster()));                     
                //                     }
                //                     else if (wc.getType().equals(WireConnectionType.END)) {
                //                        Point e = BoardUtil.rotatePoint(wc.getLine().getEnd().getX(), wc.getLine().getEnd().getY(), part.getXLoc(), part.getYLoc(), -90);
                //                        wc.getLine().getEnd().setLocation(BoardUtil.snap(e.x, editor.getRaster()),BoardUtil.snap(e.y, editor.getRaster()));                                          
                //                     }
                //                     
                //                  }
                //                  
                //               }
                //               
            }//from   w ww. j a  v a 2s  .c om

            Rotateable r = (Rotateable) editor.getSelectedItem();
            r.rotateCW();

            if (!undoManager.addEdit(new RotateCWEdit(r))) {
                log.info("Could not add edit " + this.getClass());
            }
            editor.refresh();
        }
    }

    ctx.getBean(RedoCommand.class).setEnabled(undoManager.canRedo());
    ctx.getBean(UndoCommand.class).setEnabled(undoManager.canUndo());

}

From source file:org.pmedv.blackboard.commands.UndoCommand.java

@Override
public void execute(ActionEvent e) {
    ApplicationContext ctx = AppContext.getContext();
    ApplicationWindow win = ctx.getBean(ApplicationWindow.class);
    BoardEditor editor = EditorUtils.getCurrentActiveEditor();
    UndoManager undoManager = editor.getUndoManager();

    try {/*from   ww w  .j a  v  a2  s . c om*/

        try {
            undoManager.undo();
        } catch (CannotUndoException c) {
            JOptionPane.showMessageDialog(win, resources.getResourceByKey("msg.cantundo"),
                    resources.getResourceByKey("msg.error"), JOptionPane.ERROR_MESSAGE);
        }

    } catch (CannotUndoException e1) {
        log.warn("Cannot undo.");
        e1.printStackTrace();
    }

    ctx.getBean(RedoCommand.class).setEnabled(undoManager.canRedo());
    ctx.getBean(UndoCommand.class).setEnabled(undoManager.canUndo());
}