r.setEnabled(undo.canRedo());
}
public static void main(final String[] args) throws Exception {
EventQueue.invokeLater(new Runnable() { public void run() {
final RegionOverlay overlay = new RegionOverlay();
overlay.setCookie(new Object(), false, true);
Dimension size = new Dimension(400, 400);
overlay.setPreferredSize(size);
// // Useful for making icons out of screenshots:
// overlay.setTransform(AffineTransform.getScaleInstance(4, 4));
undo = new UndoManager() {
public boolean addEdit(UndoableEdit edit) {
boolean result = super.addEdit(edit);
updateButtons();
return result;
}
};
overlay.addUndoableEditListener(undo);
u = new JButton("Undo");
u.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (undo.canUndo()) {
undo.undo();
overlay.repaint();
}
updateButtons();
}
}
);
r = new JButton("Redo");
r.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
if (undo.canRedo()) {
undo.redo();
overlay.repaint();
}
updateButtons();
}
}
);