OS: Windows 10 64bit. Processing 3.3.7.
I am looking for a solution on how to get text from the copy/paste system buffer (aka CTRL+C CTRL+V buffer).
So far I have this code compiled from examples and such from other people:
//This next set of code is dumped from:
//https://forum.processing.org/two/discussion/8950/pasted-image-from-clipboard-is-black
//https://forum.processing.org/two/discussion/17270/why-this-getx-method-is-missing-in-processing-3-1-1
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
String GetTextFromClipboard (){
String text = (String) GetFromClipboard(DataFlavor.stringFlavor);
return text;
}
static final javax.swing.JFrame getJFrame(final PSurface surf) {
return
(javax.swing.JFrame)
((processing.awt.PSurfaceAWT.SmoothCanvas) //Gives error: ClassCastException: com.jogamp.newt.opengl.GLWindow cannot be cast to processing.awt.PSurfaceAWT$SmoothCanvas
surf.getNative()).getFrame();
}
Object GetFromClipboard (DataFlavor flavor) {
Clipboard clipboard = getJFrame(getSurface()).getToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
Object object = null;
if (contents != null && contents.isDataFlavorSupported(flavor))
{
try
{
object = contents.getTransferData(flavor);
println("Clipboard.GetFromClipboard() >> Object transferred from clipboard.");
}
catch (UnsupportedFlavorException e1) // Unlikely but we must catch it
{
println("Clipboard.GetFromClipboard() >> Unsupported flavor: " + e1);
//~ e1.printStackTrace();
}
catch (java.io.IOException e2)
{
println("Clipboard.GetFromClipboard() >> Unavailable data: " + e2);
//~ e2.printStackTrace();
}
}
return object;
}
But, when function GetTextFromClipboard() is run, the 19th string, as noted by a really long comment, gives an error:
ClassCastException: com.jogamp.newt.opengl.GLWindow cannot be cast to processing.awt.PSurfaceAWT$SmoothCanvas
What do?