本文整理了Java中java.awt.datatransfer.Clipboard.isDataFlavorAvailable()
方法的一些代码示例,展示了Clipboard.isDataFlavorAvailable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clipboard.isDataFlavorAvailable()
方法的具体详情如下:
包路径:java.awt.datatransfer.Clipboard
类名称:Clipboard
方法名:isDataFlavorAvailable
暂无
代码示例来源:origin: org.exbin.deltahex/deltahex-swing
private void updateCanPaste() {
try {
canPaste = clipboard.isDataFlavorAvailable(binaryDataFlavor) || clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor);
} catch (IllegalStateException ex) {
canPaste = false;
}
}
代码示例来源:origin: scruel/ClipIt
public static Clipboard getClipboard() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
while (true) {
Throwable throwable = null;
try {
clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor);
} catch (IllegalStateException e) {
throwable = e;
}
if (throwable == null) {
break;
}
}
return clipboard;
}
}
代码示例来源:origin: stackoverflow.com
final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) {
final Image screenshot = (Image) clipboard.getData(DataFlavor.imageFlavor);
...
}
代码示例来源:origin: raydac/netbeans-mmd-plugin
public static boolean isDataFlavorAvailable(@Nonnull final Clipboard clipboard, @Nonnull final DataFlavor flavor) {
boolean result = false;
try {
result = clipboard.isDataFlavorAvailable(flavor);
} catch (final IllegalStateException ex) {
LOGGER.warn("Can't get access to clipboard : " + ex.getMessage());
}
return result;
}
代码示例来源:origin: mucommander/mucommander
/**
* Toggle the action depending on the clipboard contents.
*/
private void toggleActionState() {
try {
action.setEnabled(ClipboardSupport.getClipboard().isDataFlavorAvailable(DataFlavor.javaFileListFlavor));
}
catch(Exception e) {
// Works around "java.lang.IllegalStateException: cannot open system clipboard" thrown when the clipboard
// is currently unavailable (ticket #164).
LOGGER.debug("Caught an exception while querying the clipboard for files", e);
}
}
代码示例来源:origin: stackoverflow.com
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
if (cb.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) {
try {
List files = (List) cb.getData(DataFlavor.javaFileListFlavor);
boolean found = false;
for (Object o : files) {
if (o instanceof File) {
File f = (File) o;
if (f.getName().toLowerCase().endsWith(".mp3")) {
System.out.println("I haz MP3");
found = true;
}
}
}
if (!found) {
System.out.println("I notz haz MP3");
}
} catch (UnsupportedFlavorException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core
public static JMeterTreeNode[] getCopiedNodes() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if (clipboard.isDataFlavorAvailable(JMeterTreeNodeTransferable.JMETER_TREE_NODE_ARRAY_DATA_FLAVOR)) {
try {
return (JMeterTreeNode[]) clipboard.getData(JMeterTreeNodeTransferable.JMETER_TREE_NODE_ARRAY_DATA_FLAVOR);
} catch (Exception ex) {
log.error("Clipboard node read error: {}", ex.getMessage(), ex);
JOptionPane.showMessageDialog(GuiPackage.getInstance().getMainFrame(),
JMeterUtils.getResString("clipboard_node_read_error")+":\n" + ex.getLocalizedMessage(), //$NON-NLS-1$ //$NON-NLS-2$
JMeterUtils.getResString("error_title"), JOptionPane.ERROR_MESSAGE); //$NON-NLS-1$
}
}
return null;
}
代码示例来源:origin: comtel2000/fx-experience
private void clipboardTransfer(Robot robot, char ch) {
try {
StringSelection stringSelection = new StringSelection(Character.toString(ch));
java.awt.datatransfer.Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
Object recover = clpbrd.isDataFlavorAvailable(DataFlavor.stringFlavor) ? clpbrd.getData(DataFlavor.stringFlavor) : null;
clpbrd.setContents(stringSelection, null);
robot.keyPress(controlKeyEvent);
robot.keyPress(VK_V);
robot.keyRelease(VK_V);
robot.keyRelease(controlKeyEvent);
robot.delay(50);
StringSelection recoverSelection = new StringSelection(recover != null ? recover.toString() : "");
clpbrd.setContents(recoverSelection, null);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
代码示例来源:origin: monster860/FastDMM
public static FloatingSelection fromClipboard(ObjectTree objTree, DMM map) {
FloatingSelection floatSel = new FloatingSelection();
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
if(!clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor))
return null;
String clipboardVal = null;
代码示例来源:origin: tulskiy/musique
item.setEnabled(Toolkit.getDefaultToolkit().getSystemClipboard().isDataFlavorAvailable(SongsSelection.getFlavor()));
item.addActionListener(listener);
item.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME));
代码示例来源:origin: org.jclarion/clarion-runtime
if (!Toolkit.getDefaultToolkit().getSystemClipboard().isDataFlavorAvailable(DataFlavor.stringFlavor)) {
paste.setEnabled(false);
代码示例来源:origin: org.gosu-lang.gosu/gosu-editor
public void captureState()
{
try
{
if( !EditorUtilities.getClipboard().isDataFlavorAvailable( DataFlavor.stringFlavor ) )
{
return;
}
}
catch( Exception e )
{
// sometimes the clipboard doesn't open
return;
}
Transferable contents = editor.util.EditorUtilities.getClipboard().getContents( this );
addToCopyBuffer( contents );
}
代码示例来源:origin: org.gosu-lang.gosu/gosu-lab
public void captureState()
{
try
{
if( !EditorUtilities.getClipboard().isDataFlavorAvailable( DataFlavor.stringFlavor ) )
{
return;
}
}
catch( Exception e )
{
// sometimes the clipboard doesn't open
return;
}
Transferable contents = editor.util.EditorUtilities.getClipboard().getContents( this );
addToCopyBuffer( contents );
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-mobility-svgcore
public void actionPerformed(ActionEvent e) {
Clipboard clipboard = getClipboard();
if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
try {
String text = (String) clipboard.getData(DataFlavor.stringFlavor);
final String id = m_svgDataObject.getModel().mergeImage(text, false);
getSceneManager().setSelection(id, true);
} catch (Exception ex) {
SceneManager.error("Paste failed.", ex); //NOI18N
}
return;
}
}
};
代码示例来源:origin: uk.ac.gate.plugins/annie
String valueCopied = null;
try {
if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
valueCopied = (String) clipboard.getContents(null)
.getTransferData(DataFlavor.stringFlavor);
代码示例来源:origin: stackoverflow.com
DataFlavor dataFlavor = DataFlavor.stringFlavor;
if (systemClipboard.isDataFlavorAvailable(dataFlavor))
代码示例来源:origin: org.jdesktop.bsaf/bsaf
private void updateTextActions(JTextComponent text) {
Caret caret = text.getCaret();
final int dot = caret.getDot();
final int mark = caret.getMark();
boolean selection = (dot != mark);
boolean editable = text.isEditable();
setCopyEnabled(selection);
setCutEnabled(editable && selection);
setDeleteEnabled(editable && selection);
final int length = text.getDocument().getLength();
setSelectAllEnabled(editable && (Math.abs(mark - dot) != length));
try {
boolean data = getClipboard().isDataFlavorAvailable(DataFlavor.stringFlavor);
setPasteEnabled(editable && data);
} catch (IllegalStateException e) {
//ignore
setPasteEnabled(editable);
}
}
代码示例来源:origin: scruel/ClipIt
public void process() {
this.tipsFrame.initJLabelTitle(getTitle());
Clipboard clipboard = ClipboardUtils.getClipboard();
try {
if (this.tipsFrame.needTips()) {
this.tipsFrame.setVisible(true);
}
if (clipboard.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) {
fileListProcess((List<File>) clipboard.getData(DataFlavor.javaFileListFlavor));
}
else if (clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor)) {
imageProcess((Image) clipboard.getData(DataFlavor.imageFlavor));
}
else if (clipboard.isDataFlavorAvailable(DataFlavor.allHtmlFlavor)) {
htmlProcess((String) clipboard.getData(DataFlavor.allHtmlFlavor));
}
else {
this.action.actionCompleted();
return;
}
if (this.action.getTotalSum() == 0) {
this.action.actionCompleted();
}
} catch (Exception ignore) {
// e.printStackTrace();
}
}
代码示例来源:origin: net.java.dev.appframework/appframework
private void updateTextActions(JTextComponent text) {
Caret caret = text.getCaret();
boolean selection = (caret.getDot() != caret.getMark());
boolean editable = text.isEditable();
boolean data = getClipboard().isDataFlavorAvailable(DataFlavor.stringFlavor);
setCopyEnabled(selection);
setCutEnabled(editable && selection);
setDeleteEnabled(editable && selection);
setPasteEnabled(editable && data);
}
代码示例来源:origin: org.exbin.deltahex/deltahex-swing
if (clipboard.isDataFlavorAvailable(binaryDataFlavor)) {
if (codeArea.hasSelection()) {
deleteSelection();
Logger.getLogger(DefaultCodeAreaCommandHandler.class.getName()).log(Level.SEVERE, null, ex);
} else if (clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)) {
if (codeArea.hasSelection()) {
deleteSelection();
内容来源于网络,如有侵权,请联系作者删除!