The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit a6475449 authored by JxDannyxJ's avatar JxDannyxJ
Browse files

The Undo/Redo action has thrown exceptions when no more items

were part of the stack. This exceptions are caught in the actionPerformed method
and logged to the console on Log Level "Debug" with a simple "beep" sound for the user
to notify an empty stack
parent f1738014
package org.vadere.gui.topographycreator.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.*;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.UndoManager;
/**
......@@ -15,6 +20,7 @@ public class ActionRedo extends AbstractAction {
private static final long serialVersionUID = 4975524648404524891L;
private final UndoManager undoManager;
private final TopographyAction action;
private static Logger logger = LogManager.getLogger(ActionRedo.class);
public ActionRedo(final String name, final ImageIcon icon, final UndoManager undoManager,
final TopographyAction action) {
......@@ -25,7 +31,12 @@ public class ActionRedo extends AbstractAction {
@Override
public void actionPerformed(ActionEvent arg0) {
undoManager.redo();
try {
undoManager.redo();
} catch (CannotRedoException e) {
logger.log(Priority.DEBUG, "Cannot redo! List of edits is empty!");
Toolkit.getDefaultToolkit().beep();
}
action.actionPerformed(arg0);
}
}
package org.vadere.gui.topographycreator.control;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.*;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
/**
......@@ -16,6 +21,7 @@ public class ActionUndo extends AbstractAction {
private static final long serialVersionUID = 6022031098257929748L;
private final UndoManager undoManager;
private final TopographyAction action;
private static Logger logger = LogManager.getLogger(ActionUndo.class);
public ActionUndo(final String name, final ImageIcon icon, UndoManager undoManager, final TopographyAction action) {
super(name, icon);
......@@ -25,7 +31,13 @@ public class ActionUndo extends AbstractAction {
@Override
public void actionPerformed(ActionEvent arg0) {
undoManager.undo();
try {
undoManager.undo();
} catch (CannotUndoException e) {
logger.log(Priority.DEBUG, "Cannot undo! List of edits is empty!");
Toolkit.getDefaultToolkit().beep();
}
action.actionPerformed(arg0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment