View Javadoc

1   /*
2    * $Id: RedoAction.java,v 1.8 2007/07/04 19:42:49 edankert Exp $
3    *
4    * The contents of this file are subject to the Mozilla Public License 
5    * Version 1.1 (the "License"); you may not use this file except in 
6    * compliance with the License. You may obtain a copy of the License at 
7    * http://www.mozilla.org/MPL/ 
8    *
9    * Software distributed under the License is distributed on an "AS IS" basis, 
10   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
11   * for the specific language governing rights and limitations under the License.
12   *
13   * The Original Code is XML Hammer code. (org.xmlhammer.*)
14   *
15   * The Initial Developer of the Original Code is Edwin Dankert. Portions created 
16   * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. 
17   * All Rights Reserved.
18   *
19   * Contributor(s): Edwin Dankert <edankert@gmail.com>
20   */
21  package org.xmlhammer.gui.actions;
22  
23  import java.awt.Toolkit;
24  import java.awt.event.KeyEvent;
25  
26  import javax.swing.ImageIcon;
27  import javax.swing.KeyStroke;
28  import javax.swing.event.ChangeEvent;
29  import javax.swing.event.ChangeListener;
30  
31  import org.bounce.RunnableAction;
32  import org.xmlhammer.gui.ProjectView;
33  
34  /***
35   * An action that can be used to redo a previous undo.
36   *
37   * @version	$Revision: 1.8 $, $Date: 2007/07/04 19:42:49 $
38   * @author Edwin Dankert <edankert@gmail.com>
39   */
40   public class RedoAction extends RunnableAction implements ChangeListener {
41   	private static final long serialVersionUID = 7167701120878218434L;
42  
43      private ProjectView view = null;
44  
45      /***
46       * @param parent the XMLHammer parent.
47       */
48      public RedoAction() {
49  		super( "Redo");
50  		
51          putValue( MNEMONIC_KEY, new Integer( 'R'));
52  		putValue( ACCELERATOR_KEY, KeyStroke.getKeyStroke( KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
53  		putValue( SMALL_ICON, new ImageIcon( getClass().getResource( "/org/xmlhammer/gui/icons/etool16/redo_edit.gif")));
54  		putValue( SHORT_DESCRIPTION, "Redo");
55  		
56  		setEnabled( false);
57   	}
58  	 	
59      public void setView(ProjectView view) {
60          if (this.view != null) {
61              this.view.getUndoManager().removeChangeListener(this);
62          }
63          
64          this.view = view;
65          
66          if (this.view != null) {
67              this.view.getUndoManager().addChangeListener(this);
68              setEnabled(this.view.getUndoManager().canRedo());
69          } else {
70              setEnabled(false);
71          }
72      }
73  
74      /***
75  	 * The implementation of the redo action, called 
76  	 * after a user action.
77  	 */
78   	public void run() {
79          if (view != null && view.getUndoManager().canRedo()) {
80              view.getUndoManager().redo();
81              setEnabled(view.getUndoManager().canRedo());
82          }
83      }
84  
85      public void stateChanged(ChangeEvent event) {
86          setEnabled(view.getUndoManager().canRedo());
87  
88          if (view.getUndoManager().isMark()) {
89              view.getFieldManager().setFieldsChanged(false);
90          }
91      }
92  }