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

  1. /*
  2.  * (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3.  */
  4. import com.ms.ui.*;
  5. import com.ms.ui.event.*;
  6. import java.util.*;
  7. /**
  8.  *    JNotepad specific extension of CommandFeature. Using the ICommandFeature
  9.  *    and ICommandFeedback interfaces, this module allows a program to handle
  10.  *    command processing and routing quickly and easily, as well as command item 
  11.  *    enabling and disabling. 
  12.  *
  13.  *    @see    IFeature
  14.  *    @see    ICommandFeedback
  15.  *    @see    IComponentFeature
  16.  *    @see    CommandFeature
  17.  *
  18.  *    @version    1.0, 8/6/97
  19.  */
  20. public class JNoteCommandFeature extends CommandFeature{        
  21. /**
  22.  *    Creates a new JNoteCommandFeature.
  23.  */
  24.     public JNoteCommandFeature(){
  25.         super();
  26.     }
  27. /**
  28.  *    Private function. Goes through all of the known general file commands
  29.  *    (those defined in the IFileOperationTarget
  30.  *    interface) and calls appropriate methods in that interface
  31.  *    if the command is found. If none of these are found, it calls the
  32.  *    otherCommand() method to see if the command is an application-specific one.
  33.  *
  34.  *    @param    name    Name of command
  35.  *    @param    evt        Event object which generated this command
  36.  *    @returns    true if the command was handled, false if not
  37.  */
  38.     private boolean checkFileCommands(String name, UIActionEvent evt){
  39.         IUIComponent comp=evt.getActionItem();
  40.         switch( comp.getID() ){
  41.         case ResourceIDs.ID_FILE_NEW:
  42.             return doFileNew();
  43.         case ResourceIDs.ID_FILE_OPEN:
  44.             return doFileOpen();
  45.         case ResourceIDs.ID_FILE_SAVE:
  46.             return doFileSave();
  47.         case ResourceIDs.ID_FILE_SAVEAS:
  48.             return doFileSaveAs();
  49.         case ResourceIDs.ID_FILE_CLOSE:
  50.             return doFileClose();
  51.         case ResourceIDs.ID_FILE_PRINT:
  52.             return doFilePrint();
  53.         case ResourceIDs.ID_EDIT_FIND:
  54.             return doEditFind();
  55.         case ResourceIDs.ID_EDIT_REPLACE:
  56.             return doEditReplace();
  57.         } 
  58.         return fileTarget.otherCommand(name, evt);                        
  59.     }
  60. /**
  61.  *    Private function. Goes through all of the known general text commands
  62.  *    (those defined in the ITextOperationTarget 
  63.  *    interface) and calls appropriate methods in that interface
  64.  *    if the command is found. If none of these are found, it calls the
  65.  *    otherCommand() method to see if the command is an application-specific one.
  66.  *
  67.  *    @param    name    Name of command
  68.  *    @param    evt        Event object which generated this command
  69.  *    @returns    true if the command was handled, false if not
  70.  */
  71.     private boolean checkTextCommands(String name, UIActionEvent evt){
  72.         IUIComponent comp=evt.getActionItem();
  73.         switch( comp.getID() ){
  74.         case ResourceIDs.ID_EDIT_UNDO:
  75.             return doEditUndo();
  76.         case ResourceIDs.ID_EDIT_REDO:
  77.             return doEditRedo();
  78.         case ResourceIDs.ID_EDIT_CUT:
  79.             return doEditCut();
  80.         case ResourceIDs.ID_EDIT_COPY:
  81.             return doEditCopy();
  82.         case ResourceIDs.ID_EDIT_PASTE:
  83.             return doEditPaste();
  84.         case ResourceIDs.ID_EDIT_DELETE:
  85.             return doEditDelete();
  86.         case ResourceIDs.ID_EDIT_SELECT_ALL:
  87.             return doEditSelectAll();
  88.         case ResourceIDs.ID_FONT:
  89.             return doFont();
  90.         case ResourceIDs.ID_TEXTCOLOR:
  91.             return doTextColor();
  92.         case ResourceIDs.ID_BGCOLOR:
  93.             return doBackgroundColor();
  94.         }
  95.         return textTarget.otherCommand(name, evt);                        
  96.     }
  97. /**
  98.  *    Called when an action event
  99.  *    occurs in one of the talker components. Processes the command through
  100.  *    <a href="#checkTextCommands">checkTextCommands</a> and
  101.  *    <a href="#checkFileCommands">checkFileCommands</a>. 
  102.  *    Part of the IUIActionListener interface. 
  103.  *
  104.  *    @param    evt    UIActionEvent which occurred.
  105.  */
  106.     public void actionPerformed(UIActionEvent evt){
  107.         String name = evt.getActionCommand();
  108.         if (name == null)
  109.             return;
  110.         boolean ret = false;
  111.         if (fileTarget != null)
  112.             ret = checkFileCommands(name, evt);
  113.         if ((textTarget != null) && (ret == false))
  114.             checkTextCommands(name, evt);
  115.         textTarget.requestFocus();
  116.     }
  117.  
  118.     protected boolean doFileNew(){
  119.         fileTarget.newFile();
  120.         return true;
  121.     }
  122.  
  123.     protected boolean doFileOpen(){
  124.         fileTarget.openFile();
  125.         return true;
  126.     }
  127.  
  128.     protected boolean doFileSave(){
  129.         fileTarget.saveFile();
  130.         return true;
  131.     }
  132.  
  133.     protected boolean doFileSaveAs(){
  134.         fileTarget.saveFileAs();
  135.         return true;
  136.     }
  137.  
  138.     protected boolean doFileClose(){
  139.  
  140.         fileTarget.closeFile();
  141.         return true;
  142.     }
  143.  
  144.     protected boolean doEditFind(){
  145.         fileTarget.searchReplace(true);
  146.         return true;
  147.     }
  148.  
  149.     protected boolean doEditReplace(){
  150.         fileTarget.searchReplace(false);
  151.         return true;
  152.     }
  153.  
  154.     protected boolean doFilePrint(){
  155.         fileTarget.printFile();
  156.         return true;
  157.     }
  158.  
  159.     protected boolean doEditUndo(){
  160.         textTarget.undo();
  161.         return true;
  162.     }
  163.  
  164.     protected boolean doEditRedo(){
  165.         textTarget.redo();
  166.         return true;
  167.     }
  168.  
  169.     protected boolean doEditCut(){
  170.         textTarget.cut();
  171.         return true;
  172.     }
  173.  
  174.     protected boolean doEditCopy(){
  175.         textTarget.copy();
  176.         return true;
  177.     }
  178.  
  179.     protected boolean doEditPaste(){
  180.         textTarget.paste();
  181.         return true;
  182.     }
  183.  
  184.     protected boolean doEditDelete(){
  185.         textTarget.delete();
  186.         return true;
  187.     }
  188.  
  189.     protected boolean doEditSelectAll()    {
  190.         textTarget.selectAll();
  191.         return true;
  192.     }
  193.  
  194.     protected boolean doFont(){
  195.         textTarget.changeFont();
  196.         return true;
  197.     }
  198.  
  199.     protected boolean doTextColor(){
  200.         textTarget.changeTextColor();        
  201.         return true;
  202.     }
  203.  
  204.     protected boolean doBackgroundColor(){
  205.         textTarget.changeBackColor();
  206.         return true;
  207.     }
  208. }