moved clipboard stuff to PlatformAdapter
This commit is contained in:
parent
d9830aff06
commit
e6feeb3d5c
|
@ -48,5 +48,13 @@ public interface PlatformAdapter {
|
|||
* @param title
|
||||
* @param message
|
||||
*/
|
||||
void alert(String title, String message);
|
||||
public void alert(String title, String message);
|
||||
|
||||
/**
|
||||
* Get the contents of the system clipboard. The system might not have a clipboard
|
||||
* (particularly if it doesn't even have a keyboard) in which case we return null.
|
||||
* Otherwise we return a String, which may be the empty string "".
|
||||
* @return a String, or null if there is no system clipboard.
|
||||
*/
|
||||
public String getClipboard();
|
||||
}
|
||||
|
|
|
@ -66,4 +66,23 @@ final class SwingAdapter implements PlatformAdapter {
|
|||
}
|
||||
JOptionPane.showMessageDialog(null, message, title, JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the contents of the system clipboard. The system might not have a clipboard
|
||||
* (particularly if it doesn't even have a keyboard) in which case we return null.
|
||||
* Otherwise we return a String, which may be the empty string "".
|
||||
* @return a String, or null if there is no system clipboard.
|
||||
*/
|
||||
public 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);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Sys.log("Exception while getting clipboard: " + e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -277,18 +277,14 @@ public final class Sys {
|
|||
*/
|
||||
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;
|
||||
}
|
||||
PlatformAdapter adapter = (PlatformAdapter) Class.forName(PLATFORM).newInstance(); // This avoids a Jet error message
|
||||
return adapter.getClipboard();
|
||||
} catch (Exception e) {
|
||||
Sys.log("Unable to get clipboard contents: " + e);
|
||||
// ignore exception and use native implementation
|
||||
return nGetClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static native String nGetClipboard();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue