本文整理了Java中java.awt.datatransfer.Clipboard.getContents()
方法的一些代码示例,展示了Clipboard.getContents()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clipboard.getContents()
方法的具体详情如下:
包路径:java.awt.datatransfer.Clipboard
类名称:Clipboard
方法名:getContents
暂无
代码示例来源:origin: groovy/groovy-core
public boolean clipBoardAvailable() {
Transferable t = StructuredSyntaxResources.SYSTEM_CLIPBOARD.getContents(this);
return t.isDataFlavorSupported(DataFlavor.stringFlavor);
}
代码示例来源:origin: MovingBlocks/Terasology
@Override
public String getClipboardContentsAsString() {
return AccessController.doPrivileged(
(PrivilegedAction<String>) () -> {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null) {
return (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
return null;
}
return null;
});
}
代码示例来源:origin: libgdx/libgdx
@Override
public String getContents () {
try {
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null) {
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch (Exception ex) {
}
}
if (contents.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
List<File> files = (List)contents.getTransferData(DataFlavor.javaFileListFlavor);
StringBuilder buffer = new StringBuilder(128);
for (int i = 0, n = files.size(); i < n; i++) {
if (buffer.length() > 0) buffer.append('\n');
buffer.append(files.get(i).toString());
}
return buffer.toString();
} catch (RuntimeException ex) {
}
}
}
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
return "";
}
代码示例来源:origin: libgdx/libgdx
@Override
public String getContents () {
try {
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
if (contents != null) {
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
return (String)contents.getTransferData(DataFlavor.stringFlavor);
} catch (Exception ex) {
}
}
if (contents.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
try {
List<File> files = (List)contents.getTransferData(DataFlavor.javaFileListFlavor);
StringBuilder buffer = new StringBuilder(128);
for (int i = 0, n = files.size(); i < n; i++) {
if (buffer.length() > 0) buffer.append('\n');
buffer.append(files.get(i).toString());
}
return buffer.toString();
} catch (RuntimeException ex) {
}
}
}
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
return "";
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Get the current clipboard contents.
*
* @return The string currently in the clipboard
*/
protected String getClipboardContents() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
logger.warn("Failed to get data from clipboard", e);
}
return "";
}
代码示例来源:origin: JetBrains/ideavim
/**
* Returns the string currently on the system clipboard.
*
* @return The clipboard string or null if data isn't plain text
*/
@Nullable
public static String getClipboardText() {
String res = null;
try {
Clipboard board = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable trans = board.getContents(null);
Object data = trans.getTransferData(DataFlavor.stringFlavor);
if (data != null) {
res = data.toString();
}
}
catch (HeadlessException e) {
// ignore
}
catch (UnsupportedFlavorException e) {
// ignore
}
catch (IOException e) {
// ignore
}
return res;
}
代码示例来源:origin: skylot/jadx
private void process(MouseEvent e) {
textComponent.requestFocus();
boolean enabled = textComponent.isEnabled();
boolean editable = textComponent.isEditable();
boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals(""));
boolean marked = textComponent.getSelectedText() != null;
boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard()
.getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);
undoAction.setEnabled(enabled && editable && undoManager.canUndo());
redoAction.setEnabled(enabled && editable && undoManager.canRedo());
cutAction.setEnabled(enabled && editable && marked);
copyAction.setEnabled(enabled && marked);
pasteAction.setEnabled(enabled && editable && pasteAvailable);
deleteAction.setEnabled(enabled && editable && marked);
selectAllAction.setEnabled(enabled && nonempty);
int nx = e.getX();
if (nx > 500) {
nx = nx - popup.getSize().width;
}
popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
}
}
代码示例来源:origin: stackoverflow.com
Transferable t = c.getContents( null );
代码示例来源:origin: plantuml/plantuml
private String getClipboardText() {
final Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
final String text = (String) t.getTransferData(DataFlavor.stringFlavor);
return text;
}
} catch (UnsupportedFlavorException e) {
Log.error(e.toString());
} catch (IOException e) {
Log.error(e.toString());
}
return null;
}
代码示例来源:origin: looly/hutool
/**
* 获取剪贴板内容
*
* @param flavor 数据元信息,标识数据类型
* @param owner 所有者
* @return 剪贴板内容,类型根据flavor不同而不同
*/
public static Object get(DataFlavor flavor, ClipboardOwner owner) {
final Transferable content = getClipboard().getContents(null);
if (null != content && content.isDataFlavorSupported(flavor)) {
try {
return content.getTransferData(flavor);
} catch (UnsupportedFlavorException | IOException e) {
throw new UtilException(e);
}
}
return null;
}
代码示例来源:origin: looly/hutool
/**
* 获取剪贴板内容
*
* @param flavor 数据元信息,标识数据类型
* @param owner 所有者
* @return 剪贴板内容,类型根据flavor不同而不同
*/
public static Object get(DataFlavor flavor, ClipboardOwner owner) {
final Transferable content = getClipboard().getContents(null);
if (null != content && content.isDataFlavorSupported(flavor)) {
try {
return content.getTransferData(flavor);
} catch (UnsupportedFlavorException | IOException e) {
throw new UtilException(e);
}
}
return null;
}
代码示例来源:origin: plantuml/plantuml
public static BufferedImage getClipboard() {
final Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
if (t != null && t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
final BufferedImage text = (BufferedImage) t.getTransferData(DataFlavor.imageFlavor);
return text;
}
} catch (UnsupportedFlavorException e) {
Log.error(e.toString());
} catch (IOException e) {
Log.error(e.toString());
}
return null;
}
代码示例来源:origin: MovingBlocks/Terasology
/**
* Attempts to serialize the system clipboard's contents - if successful,
* sets the current state of the editor to the serialized {@link JsonTree}.
*/
protected void pasteJson() {
// Get the clipboard contents.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable t = clipboard.getContents(null);
// Attempt to convert them to a string.
String clipboardContents = null;
try {
if (t != null) {
clipboardContents = (String) t.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException | IOException e) {
logger.warn("Could not fetch clipboard contents.", e);
}
if (clipboardContents != null) {
try {
// Attempt to serialize them to a JsonTree and reset the editor state.
JsonElement json = new JsonParser().parse(clipboardContents);
JsonTree node = JsonTreeConverter.serialize(json);
resetState(node);
} catch (JsonSyntaxException | NullPointerException e) {
logger.warn("Could not construct a valid tree from clipboard contents.", e);
}
}
}
代码示例来源:origin: RipMeApp/ripme
boolean marked = textComponent.getSelectedText() != null;
boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);
代码示例来源:origin: vsch/flexmark-java
public static Image getImageFromClipboard() {
Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
return getImageFromTransferable(transferable);
}
代码示例来源:origin: RaiMan/SikuliX2
/**
* @return clipboard content
*/
public static String getClipboard() {
Transferable content = null;
try {
content = SXClipboard.getSystemClipboard().getContents(null);
} catch (Exception ex) {
log.error("getClipboard: clipboard not available:\n%s", ex.getMessage());
}
if (content != null) {
try {
if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return (String) content.getTransferData(DataFlavor.stringFlavor);
}
} catch (UnsupportedFlavorException ex) {
log.error("getClipboard: UnsupportedFlavorException: %s", content);
} catch (IOException ex) {
log.error("getClipboard: IOException:\n%s", ex.getMessage());
}
}
return "";
}
代码示例来源:origin: jline/jline
Transferable transferable = clipboard.getContents(null);
代码示例来源:origin: ron190/jsql-injection
Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
if (transferableFromClipboard != null) {
if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
代码示例来源:origin: ron190/jsql-injection
Transferable transferableFromClipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
if (transferableFromClipboard != null) {
if (transferableFromClipboard.isDataFlavorSupported(DataFlavor.stringFlavor)) {
代码示例来源:origin: bobbylight/RSyntaxTextArea
TransferHandler th = c.getTransferHandler();
if (th != null) {
Transferable trans = buffer.getContents(null);
if (trans != null) {
th.importData(c, trans);
内容来源于网络,如有侵权,请联系作者删除!