Implemented default AWT implementation of Sys.getClipboard()
This commit is contained in:
parent
7f28edb980
commit
483f03a4ec
|
@ -266,6 +266,20 @@ public final class Sys {
|
||||||
* Otherwise we return a String, which may be the empty string "".
|
* Otherwise we return a String, which may be the empty string "".
|
||||||
* @return a String, or null if there is no system clipboard.
|
* @return a String, or null if there is no system clipboard.
|
||||||
*/
|
*/
|
||||||
public static native String getClipboard();
|
public static String getClipboard() {
|
||||||
|
try {
|
||||||
|
java.awt.datatransfer.Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
|
java.awt.datatransfer.Transferable transferable = clipboard.getContents(null);
|
||||||
|
if (transferable.isDataFlavorSupported(java.awt.datatransfer.DataFlavor.stringFlavor)) {
|
||||||
|
return (String)transferable.getTransferData(java.awt.datatransfer.DataFlavor.stringFlavor);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignore exception and use native implementation
|
||||||
|
return nGetClipboard();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native String nGetClipboard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
||||||
(JNIEnv *, jclass, jstring);
|
(JNIEnv *, jclass, jstring);
|
||||||
|
|
||||||
|
/*
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getClipboard
|
* Class: org_lwjgl_Sys
|
||||||
|
* Method: nGetClipboard
|
||||||
|
* Signature: ()Ljava/lang/String;
|
||||||
|
*/
|
||||||
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
|
||||||
(JNIEnv *, jclass);
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -167,7 +167,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getClipboard
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -105,7 +105,10 @@ bool checkXError(JNIEnv *env) {
|
||||||
XSync(getDisplay(), False);
|
XSync(getDisplay(), False);
|
||||||
if (async_x_error) {
|
if (async_x_error) {
|
||||||
async_x_error = false;
|
async_x_error = false;
|
||||||
throwException(env, error_message);
|
if (env != NULL)
|
||||||
|
throwException(env, error_message);
|
||||||
|
else
|
||||||
|
printfDebug(error_message);
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
return true;
|
return true;
|
||||||
|
@ -132,7 +135,10 @@ Display *incDisplay(JNIEnv *env) {
|
||||||
XSetErrorHandler(errorHandler);
|
XSetErrorHandler(errorHandler);
|
||||||
display_connection = XOpenDisplay(NULL);
|
display_connection = XOpenDisplay(NULL);
|
||||||
if (display_connection == NULL) {
|
if (display_connection == NULL) {
|
||||||
throwException(env, "Could not open X display");
|
if (env != NULL)
|
||||||
|
throwException(env, "Could not open X display connection");
|
||||||
|
else
|
||||||
|
printfDebug("Could not open X display connection\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
warp_atom = XInternAtom(getDisplay(), "ignore_warp_atom", False);
|
warp_atom = XInternAtom(getDisplay(), "ignore_warp_atom", False);
|
||||||
|
|
|
@ -202,7 +202,7 @@ const void * getClipboard(int type)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_getClipboard
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
// Check to see if there's text available in the clipboard
|
// Check to see if there's text available in the clipboard
|
||||||
|
|
Loading…
Reference in New Issue