home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / afc11 / JNotepad / src / DirtyFlagFeature.java < prev    next >
Encoding:
Java Source  |  2000-05-04  |  2.7 KB  |  111 lines

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. import com.ms.ui.event.*;
  5. import com.ms.ui.*;
  6.  
  7. /**
  8. *    Class to detect keystrokes on clean files and mark them as dirty.
  9. *    It's best to attach these to clean files only, cause it's useless otherwise...
  10. *    When a keystroke is detected inside an edit control, the file attached to
  11. *    that edit control is marked as dirty.
  12. *    This feature plugin module uses the ITextFeature and IUIKeyListener interfaces.
  13. *
  14. *    @see    ITextFeature
  15. *    @see    IFeature
  16. *    @see    JNoteKeyFeature
  17. *
  18. *    @version    1.0, 8/9/97
  19. */
  20.  
  21. public class DirtyFlagFeature extends JNoteKeyFeature
  22. {
  23. /**
  24. *    The object we notify when the dirty flag changes    
  25.     */
  26.     FeatureTabFileViewer tabTarget;
  27.     
  28.     /**
  29.     *    Determines whether the dirty flag listener has unloaded itself yet or not
  30.     */
  31.     boolean bStillLoaded;
  32.     
  33.     /**
  34.     *    Creates a new DirtyFlagFeature which notifies the specified object when
  35.     *    a clean file is made dirty.
  36.     *
  37.     *    @param    tabtarget Object to notify
  38.     */
  39.     public DirtyFlagFeature(FeatureTabFileViewer tabtarget)
  40.     {
  41.         super();
  42.         tabTarget = tabtarget;
  43.         bStillLoaded = false;
  44.     }
  45.     
  46.     /**
  47.     *    Called when this feature is attached to
  48.     *    an edit control. Part of the ITextFeature interface. 
  49.     *
  50.     *    @param    ttarget    The edit control to be attached to
  51.     */
  52.     public void init(ITextOperationTargetExt ttarget)
  53.     {
  54.         textTarget = ttarget;
  55.         bStillLoaded = false;
  56.     }
  57.     
  58.     /**
  59.     *    Called when this feature needs to attach
  60.     *    itself to the edit control. This is done using listeners. Part of the IFeature interface. 
  61.     */
  62.     public void register()
  63.     {
  64.         super.register();            
  65.         bStillLoaded = true;
  66.     }
  67.     
  68.     /**
  69.     *    Called when the feature is detached from
  70.     *    the edit control. Removes listeners from the edit control. Part of the IFeature interface. 
  71.     */
  72.     public void unregister()
  73.     {
  74.         super.unregister();
  75.         bStillLoaded = false;
  76.     }
  77.     
  78.     /**
  79.     *    Called when a key is typed. 
  80.     *    When a key comes in, sets the dirty flag on the current file in the
  81.     *    TabFileViewer object passed in the init() method and then unregisters
  82.     *    itself. Once a file is dirty, there's no need to keep marking it dirty
  83.     *    on every keystroke. Part of the IUIKeyListener interface. 
  84.     *    
  85.     *    @param    ke    Key event which is being processed.
  86.     */
  87.     public synchronized void keyTyped(UIKeyEvent ke)
  88.     {
  89.         IFileOperationTargetExt fileTarget = tabTarget.getCurrentFile();
  90.         fileTarget.setDirtyFlag(true);
  91.         
  92.         tabTarget.refreshCurrentTab();
  93.         
  94.         unregister();
  95.     }
  96.     
  97.     /**
  98.     *    Called when the feature plugin needs to
  99.     *    be reset. This method does nothing in this class. Part of the IFeature interface. 
  100.     */
  101.     public void reset()
  102.     {
  103.         if (bStillLoaded)
  104.         {
  105.             unregister();
  106.         }
  107.     }
  108.     
  109. }
  110.  
  111.