View Javadoc

1   /*
2    * UndoAction.java
3    *
4    * Created on 27. mai 2005, 22:08
5    */
6   
7   package com.vikash.firsttool.UI;
8   import com.vikash.firsttool.Diagram.*;
9   import java.awt.event.*;
10  import java.net.URL;
11  import javax.swing.*;
12  
13  /***
14   *
15   * @author  studajb
16   */
17  public class UndoAction extends AbstractAction {
18      ToolInternalFrame internalframe;
19      MainFrame frame;
20      ToolGraph graph;
21      EditorPanel panel;
22      static UndoAction instance;
23      
24      
25      public static UndoAction getinstance(final MainFrame frame,boolean flag){
26          if(flag)
27              instance=null;
28          if(instance==null){
29              instance=new UndoAction(frame);
30          }
31              return instance;
32          }
33      
34      /*** Creates a new instance of UndoAction */
35      protected UndoAction(MainFrame frame) {
36          URL icon=getClass().getClassLoader().getResource("com/vikash/firsttool/resources/undo.gif");
37          putValue(Action.SMALL_ICON,new ImageIcon(icon));
38          putValue(Action.SHORT_DESCRIPTION,"Undo");
39          putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_Z,InputEvent.CTRL_MASK));
40          this.frame=frame;
41          setEnabled(false);
42      }
43      
44      public void actionPerformed(ActionEvent e) {
45                 internalframe=(ToolInternalFrame)frame.getDesktopPane().getSelectedFrame();
46                  if(internalframe!=null){
47                  panel=internalframe.getPanel();
48                  graph=internalframe.getGraph();
49                  ToolUndo undomanager=panel.getUndoManager();
50          	try {
51  		     undomanager.undo(graph.getGraphLayoutCache());
52  		} catch (Exception ex) {
53                      
54                      System.err.println("error in undo"+ex);
55  		} finally {
56  	        
57                   //update undo redo buttons   
58  		panel.updateundoredobuttons();
59  		}
60                  }
61      }
62      
63  }