javauis/lcdui_akn/javalcdui/javasrc.nokialcdui/com/nokia/mid/ui/Clipboard.java
branchRCL_3
changeset 21 4376525cdefb
parent 14 04becd199f91
child 23 e5618cc85d74
equal deleted inserted replaced
19:71c436fe3ce0 21:4376525cdefb
    20 
    20 
    21 // EXTERNAL IMPORTS
    21 // EXTERNAL IMPORTS
    22 import com.nokia.mj.impl.rt.legacy.NativeError;
    22 import com.nokia.mj.impl.rt.legacy.NativeError;
    23 import com.nokia.mj.impl.rt.legacy.ToolkitInvoker;
    23 import com.nokia.mj.impl.rt.legacy.ToolkitInvoker;
    24 
    24 
    25 
       
    26 /**
    25 /**
    27  * Class to provide extra functionality that is related to text-editing
    26  * Class to provide extra functionality that is related to text-editing
    28  *
    27  *
    29  * @since 1.4
    28  * @since 1.4
    30  */
    29  */
    35     private Clipboard()
    34     private Clipboard()
    36     {
    35     {
    37     }
    36     }
    38 
    37 
    39     /**
    38     /**
    40      * Copies characters into the system-clipboard
    39      * Copies characters into the system clipboard.
       
    40      * <P>
       
    41      * If <code>text</code> parameter is <code>null</code> or empty string,
       
    42      * it clears the system clipboard.
    41      *
    43      *
    42      * @param text the text to be copied
    44      * @param text the text to be copied
    43      */
    45      */
    44     public static void copyToClipboard(String text)
    46     public static void copyToClipboard(String text)
    45     {
    47     {
    46         // Toolkit invoker is needed for accessing javax.microedition.lcdui
    48         // Toolkit invoker is needed for accessing javax.microedition.lcdui
    47         // package
    49         // package
    48         ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker();
    50         ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker();
    49 
    51 
    50         Object toolkit = toolkitInvoker.getToolkit();
    52         Object toolkit = toolkitInvoker.getToolkit();
       
    53 
    51         synchronized (toolkit)
    54         synchronized (toolkit)
    52         {
    55         {
       
    56             if ((text != null) && (text.length() == 0))
       
    57             {
       
    58                 text = null;
       
    59             }
    53             NativeError.check(_copyToClipboard(
    60             NativeError.check(_copyToClipboard(
    54                                   toolkitInvoker.toolkitGetHandle(toolkit), text));
    61                                   toolkitInvoker.toolkitGetHandle(toolkit), text));
    55         }
    62         }
       
    63     }
       
    64 
       
    65     /**
       
    66      * Copies characters from the system clipboard.
       
    67      * <P>
       
    68      * Returns empty string when there is nothing in the system clipboard.
       
    69      * <P>
       
    70      * This method is not supported on S40 platform, returns <code>null</code>.
       
    71      * <P>
       
    72      * @return the content in clipboard
       
    73      */
       
    74     public static String copyFromClipboard()
       
    75     {
       
    76         String text = null;
       
    77 
       
    78         int[] error = new int[1];
       
    79         // Toolkit invoker is needed for accessing javax.microedition.lcdui
       
    80         // package
       
    81         ToolkitInvoker toolkitInvoker = ToolkitInvoker.getToolkitInvoker();
       
    82 
       
    83         Object toolkit = toolkitInvoker.getToolkit();
       
    84 
       
    85         synchronized (toolkit)
       
    86         {
       
    87             text = _copyFromClipboard(
       
    88                        toolkitInvoker.toolkitGetHandle(toolkit),
       
    89                        error);
       
    90         }
       
    91 
       
    92         NativeError.check(error[0]);
       
    93         if (text == null)
       
    94         {
       
    95             text = "";
       
    96         }
       
    97         return text;
    56     }
    98     }
    57 
    99 
    58     /*
   100     /*
    59      * Stores the text into the clipboard.
   101      * Stores the text into the clipboard.
    60      *
   102      *
    65      * @return NativeError.KErrNone if the operation was successful. Otherwise,
   107      * @return NativeError.KErrNone if the operation was successful. Otherwise,
    66      * a system-wide error code is returned.
   108      * a system-wide error code is returned.
    67      */
   109      */
    68     private static native int _copyToClipboard(int toolkit, String text);
   110     private static native int _copyToClipboard(int toolkit, String text);
    69 
   111 
       
   112     /*
       
   113      * Copies characters from the system-clipboard.
       
   114      *
       
   115      * @param toolkit A handle to the LCDUI toolkit.
       
   116      *
       
   117      * @param error On return contains the error code for the operation.
       
   118      *
       
   119      * @return The content of clipboard.
       
   120      */
       
   121     private static native String _copyFromClipboard(
       
   122         int toolkit,
       
   123         int[] error);
       
   124 
    70 }
   125 }
    71 
   126 
    72 // END OF FILE
   127 // END OF FILE