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

  1. //
  2. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  3. //
  4. import FileControl;
  5. import java.awt.datatransfer.*;
  6. import java.awt.*;
  7. import com.ms.ui.*;
  8.  
  9. /**
  10. *    Encapsulates the system Clipboard into a FileControl. Allows
  11. *    one to have the Clipboard appear as a tab in the file list. The
  12. *    contents of the clipboard are read in whenever the Clipboard tab is
  13. *    selected.
  14. *
  15. *    @see    FileControl
  16. *    @see    TabFileViewer
  17. *
  18. *    @version    1.0, 7/28/97
  19. */
  20.  
  21. public class ClipboardControl extends FileControl
  22. {
  23.     /**
  24.     *    System clipboard object
  25.     */
  26.     protected Clipboard clipBoard;
  27.     
  28.     /**
  29.     *    Creates a new ClipboardControl. 
  30.     *
  31.     *    @param    control    the edit control which will hold the clipboard contents
  32.     *    @param    parent    the parent UIFrame
  33.     */
  34.     public ClipboardControl(ITextOperationTargetExt control, UIFrame parent)
  35.     {
  36.         super(control, parent);
  37.         init(null, null);
  38.     }
  39.     
  40.     /**
  41.     *    Public init function. Inherited from FileControl.
  42.     *    Called to create the object and load any data it needs to.
  43.     *
  44.     *    @param    filepath    Not needed for ClipboardControl objects
  45.     *    @param    filename    Not needed for ClipboardControl objects
  46.     */
  47.     public boolean init(String filepath, String filename)
  48.     {
  49.         setFile(null, null);
  50.         
  51.         // clipboard is read only and never dirty
  52.         setReadOnly(true);
  53.         setDirtyFlag(false);
  54.         
  55.         // load er up
  56.         newFile();
  57.         
  58.         return true;
  59.     }
  60.     
  61.     /**
  62.     *    Returns the name that should be displayed on
  63.     *    a UITabViewer tab. Inherited from FileControl. Clipboards return "[Clipboard]"
  64.     *    if they are running as an application and "[Local clipboard]" when they are
  65.     *    running as applets (since security prevents us from making a system clipboard
  66.     *    as applets).
  67.     */
  68.     public String getDisplayFileName()
  69.     {                
  70.         if (JNoteAppletObject.isApplet())
  71.         {
  72.             // return local clipboard text
  73.             return JNotePad.loadString(ResourceIDs.IDS_LOCALCLIPBOARD);
  74.         }
  75.         else
  76.         {
  77.             // return clipboard text
  78.             return JNotePad.loadString(ResourceIDs.IDS_CLIPBOARD);
  79.         }
  80.     }
  81.     
  82.     /**
  83.     *    Called when a new file is to be created. For ClipboardControls, this loads
  84.     *    data in from the clipboard and puts it onto the edit control. Inherited from FileControl.
  85.     */
  86.     public void newFile()
  87.     {    
  88.         String data = JNoteClipboard.get(this);
  89.         
  90.         if (data == null)
  91.         {
  92.             data = JNotePad.loadString(ResourceIDs.IDS_INVALIDCLIPBOARDDATA);
  93.         }
  94.         else if (data.length() == 0)
  95.         {
  96.             data = JNotePad.loadString(ResourceIDs.IDS_EMPTYCLIPBOARD);
  97.         }
  98.         
  99.         // set the text in the edit control
  100.         editControl.setText(data);                        
  101.     }
  102.     
  103.     /**
  104.     *    Called when a file is to be loaded. Inherited from FileControl. 
  105.     *    This simply calls newFile() to refresh the clipboard contents.
  106.     */
  107.     public boolean openFile()
  108.     {
  109.         // reload clipboard
  110.         newFile();
  111.         
  112.         return true;
  113.     }
  114.     
  115.     /**
  116.     *    Called when the file needs to be saved.
  117.     *    This does nothing since we never save the clipboard contents. Inherited from FileControl. 
  118.     *
  119.     *    @see    #shouldSave
  120.     */
  121.     public boolean saveFile()
  122.     {
  123.         return true;
  124.     }
  125.     
  126.     /**
  127.     *    Called when the file needs to be saved under
  128.     *    a different name. Calls saveFile(). Inherited from FileControl. 
  129.     *
  130.     *    @see    saveFile
  131.     */
  132.     public boolean saveFileAs()
  133.     {
  134.         return saveFile();
  135.     }
  136.     
  137.     /**
  138.     *    Called when the file control receives focus.
  139.     *    Reloads the clipboard contents by calling newFile(). Inherited from FileControl. 
  140.     */
  141.     public void gotFocus()
  142.     {
  143.         // reload clipboard data
  144.         newFile();
  145.     }
  146.     
  147.     /**
  148.     *    Returns whether a file control is capable
  149.     *    of being saved to disk. ClipboardControls are not, so this returns false. Inherited from FileControl. 
  150.     */
  151.     public boolean shouldSave()
  152.     {
  153.         return false;
  154.     }
  155.     
  156.     /**
  157.     *    Called to get the name of the image that is
  158.     *    displayed on the UITab with the file name. We return a clipboard-style image. Inherited from FileControl. 
  159.     */
  160.     public String getImageName()
  161.     {
  162.         return "Images\\clip.gif";
  163.     }
  164.     
  165. }
  166.  
  167.