Example usage for javax.swing.text Document removeUndoableEditListener

List of usage examples for javax.swing.text Document removeUndoableEditListener

Introduction

In this page you can find the example usage for javax.swing.text Document removeUndoableEditListener.

Prototype

public void removeUndoableEditListener(UndoableEditListener listener);

Source Link

Document

Unregisters the given observer from the notification list so it will no longer receive updates.

Usage

From source file:com.kstenschke.copypastestack.ToolWindow.java

/**
 * Add undoManager to clip pane//from w ww  . j  a  v a2 s. c o  m
 */
private void initInlineEditor() {
    Document document = this.form.textPanePreview.getDocument();
    if (this.undoManager != null) {
        document.removeUndoableEditListener(this.undoManager);
    }

    this.undoManager = new UndoManager();
    document.addUndoableEditListener(this.undoManager);

    final ToolWindow toolWindowFin = this;

    InputMap inputMap = this.form.textPanePreview.getInputMap();

    // CTRL + Z = undo ( + Z on Mac OS)
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
            new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (toolWindowFin.undoManager.canUndo()) {
                        toolWindowFin.undoManager.undo();
                    }
                }
            });

    // CTRL + SHIFT + Z = redo ( + SHIFT + Z on Mac OS)
    inputMap.put(
            KeyStroke.getKeyStroke(KeyEvent.VK_Z,
                    InputEvent.SHIFT_DOWN_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
            new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (toolWindowFin.undoManager.canRedo()) {
                        toolWindowFin.undoManager.redo();
                    }
                }
            });
}