Example usage for javax.swing.undo CannotRedoException printStackTrace

List of usage examples for javax.swing.undo CannotRedoException printStackTrace

Introduction

In this page you can find the example usage for javax.swing.undo CannotRedoException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:UndoRedoTextArea.java

public UndoRedoTextArea() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from  w  w  w  . j a  va2 s .c om
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:Main.java

public Main() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from w  ww . j  av  a2s  .  com
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    JScrollPane scroller = new JScrollPane(textArea);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(scroller, BorderLayout.CENTER);

    textArea.getDocument().addUndoableEditListener(new UndoableEditListener() {
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
            updateButtons();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            updateButtons();
        }
    });

    setSize(400, 300);
    setVisible(true);
}

From source file:UndoManagerDemo.java

public UndoManagerDemo() {
    super("Undo/Redo Demo");

    undoButton.setEnabled(false);//from  w  w w. j av  a2s  . com
    redoButton.setEnabled(false);

    JPanel buttonPanel = new JPanel(new GridLayout());
    buttonPanel.add(undoButton);
    buttonPanel.add(redoButton);

    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    getContentPane().add(canvas, BorderLayout.CENTER);

    canvas.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point point = new Point(e.getX(), e.getY());
            pointVector.addElement(point);

            undoManager.undoableEditHappened(
                    new UndoableEditEvent(canvas, new UndoablePaintSquare(point, pointVector)));

            undoButton.setText(undoManager.getUndoPresentationName());
            redoButton.setText(undoManager.getRedoPresentationName());
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
            canvas.repaint();
        }
    });

    undoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.undo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    redoButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                undoManager.redo();
            } catch (CannotRedoException cre) {
                cre.printStackTrace();
            }
            canvas.repaint();
            undoButton.setEnabled(undoManager.canUndo());
            redoButton.setEnabled(undoManager.canRedo());
        }
    });

    setSize(400, 300);
    setVisible(true);
}