INTERNAL: Importing/exporting strings from clipboard
Anonym
Topic:
One things users might want to do is import strings from the system clipboard into IDL. One trick might use Java to copy the string to/from the clipboard.
Discussion:
If you need to copy and paste strings from the clipboard, you may able to use java to accomplish this tasks. An example Java program that can be used to read data from the clipboard is shown below:
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
public class getFromClipboard{
public static void main(String[] args) {
//get the string form the first argument
System.out.println("Hello!");
}
public static void send_contents2clip(String[] args){
String[] str = args;
int s_size = str.length;
int i = 0;
String out_string;
out_string = "";
//"TEST STRING NOW";
while (i < s_size) {
out_string=out_string+" // "+str[i];
i=i+1;
}
//out_string = str.toString();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(out_string);
clipboard.setContents(strSel, null);
}
public String get_contentsFromClip() throws UnsupportedFlavorException, IOException {
String[] str = null;
String out_string;
out_string = "";
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
out_string = (String) clipboard.getData(DataFlavor.stringFlavor);
clipboard.getContents(str);
return out_string;
}
}
This program requires the AWT tookkit. You can compile "getFromClipboard.java" into an executable JAR file and add it to the CLASSPATH. After it has been added to the classpath, you can open IDL and then use it with the following commands:
IDL> o = obj_new('IDLjavaObject$getFromClipboard', "getFromClipboard")
IDL> o.send_contents2clip, ["hello","there"]
IDL> // hello // there
IDL> f = o.get_contentsFromClip()
IDL> print, f
// hello // there
UPDATE: IDL 8.3 includes a CLIPBOARD object that can be used instead
Reviewed by DS 4/24/2014