KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > actions > Undo


1 /*
2  * Authors:
3  * Stefanovic Nenad chupo@iis.ns.ac.yu
4  * Bojanic Sasa sasaboy@neobee.net
5  * Puskas Vladimir vpuskas@eunet.yu
6  * Pilipovic Goran zboniek@uns.ac.yu
7  *
8  */

9
10 package org.enhydra.jawe.actions;
11
12 import org.enhydra.jawe.*;
13
14 import java.util.*;
15 import java.awt.event.ActionEvent JavaDoc;
16 import javax.swing.Action JavaDoc;
17 import javax.swing.undo.*;
18
19 /**
20  * Class that realizes <B>undo</B> action
21  */

22 public class Undo extends ActionBase {
23    public Undo (AbstractEditor editor) {
24       super(editor);
25       setEnabled(false);
26    }
27
28    public void actionPerformed(ActionEvent JavaDoc e) {
29       try {
30          Set s1=JaWEGraphModel.getAllCellsInModel(editor.getGraph().getModel());
31          editor.getUndoManager().undo(editor.getGraph().getGraphLayoutCache());
32          Set s2=JaWEGraphModel.getAllCellsInModel(editor.getGraph().getModel());
33          editor.refreshCollections(s1,s2);
34       } catch (CannotUndoException ex) {
35          System.err.println("Unable to undo: " + ex);
36          ex.printStackTrace();
37       }
38       editor.update();
39       editor.getRedo().update();
40       editor.getGraph().repaint();
41       //graph.getUI().paint(graph.getGraphics(),graph);
42
}
43
44    public void update() {
45       if(editor.getUndoManager().canUndo(editor.getGraph().getGraphLayoutCache())) {
46          setEnabled(true);
47          putValue(Action.NAME, editor.getUndoManager().getUndoPresentationName());
48          editor.getToolbarComponent("Undo").setToolTipText(editor.getUndoManager().getUndoPresentationName());
49       }
50       else {
51          setEnabled(false);
52          putValue(Action.NAME,ResourceManager.getLanguageDependentString("UndoLabel"));
53       }
54    }
55 }
56
Popular Tags