View Javadoc

1   package com.explosion.expfmodules.texteditor;
2   
3   /* =============================================================================
4    *       
5    *     Copyright 2004 Stephen Cowx
6    *
7    *     Licensed under the Apache License, Version 2.0 (the "License");
8    *     you may not use this file except in compliance with the License.
9    *     You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *     Unless required by applicable law or agreed to in writing, software
14   *     distributed under the License is distributed on an "AS IS" BASIS,
15   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *     See the License for the specific language governing permissions and
17   *     limitations under the License.
18   * 
19   * =============================================================================
20   */
21  
22  import java.awt.Component;
23  
24  import javax.swing.event.UndoableEditEvent;
25  
26  import com.explosion.expf.Application;
27  import com.explosion.expf.ExpConstants;
28  import com.explosion.utilities.UndoRedoBuffer;
29  /***
30   * @author Stephen Cowx
31   * Date created:@07-Feb-2003
32   */
33  public class MenuAwareUndoRedoBuffer extends UndoRedoBuffer
34  {
35     private Component highLevelParent;
36     private Component component;
37     
38     public MenuAwareUndoRedoBuffer(Component highLevelParent,Component component)
39     {
40     	this.highLevelParent = highLevelParent;
41     	this.component = component;
42     }
43  
44    /***
45     * @see com.explosion.utilities.UndoRedoBuffer#redo()
46     */
47    public void redo()
48    {
49      super.redo();
50      checkRedo();
51      checkUndo();
52    }
53  
54    /***
55     * @see com.explosion.utilities.UndoRedoBuffer#undo()
56     */
57    public void undo()
58    {
59      super.undo();
60      checkUndo();
61      checkRedo();
62    }
63    
64    
65    /***
66     * @see javax.swing.event.UndoableEditListener#undoableEditHappened(UndoableEditEvent)
67     */
68    public void undoableEditHappened(UndoableEditEvent e)
69    {
70      super.undoableEditHappened(e);
71      checkUndo();
72      checkRedo();
73    }
74      
75    private void checkUndo()
76    {
77    	if ( getUndoBuffer().size() > 0)
78         Application.ensureComponentCookie(ExpConstants.MENU_UNDO,1,highLevelParent,component);
79      else
80         Application.ensureComponentCookie(ExpConstants.MENU_UNDO,0,highLevelParent,component);
81    }
82    
83    private void checkRedo()
84    {
85      if ( getRedoBuffer().size() > 0)
86         Application.ensureComponentCookie(ExpConstants.MENU_REDO,1,highLevelParent,component);
87      else
88         Application.ensureComponentCookie(ExpConstants.MENU_REDO,0,highLevelParent,component);
89    }
90    
91  
92  }