java.awt.datatransfer.Transferable#isDataFlavorSupported ( )源码实例Demo

下面列出了java.awt.datatransfer.Transferable#isDataFlavorSupported ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk8u   文件: DataTransferer.java
private String getBestCharsetForTextFormat(Long lFormat,
    Transferable localeTransferable) throws IOException
{
    String charset = null;
    if (localeTransferable != null &&
        isLocaleDependentTextFormat(lFormat) &&
        localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
    {
        try {
            charset = new String(
                (byte[])localeTransferable.getTransferData(javaTextEncodingFlavor),
                "UTF-8"
            );
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(lFormat);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = getDefaultTextCharset();
    }
    return charset;
}
 
源代码2 项目: Bytecoder   文件: DataTransferer.java
protected String getBestCharsetForTextFormat(Long lFormat,
    Transferable localeTransferable) throws IOException
{
    String charset = null;
    if (localeTransferable != null &&
        isLocaleDependentTextFormat(lFormat) &&
        localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
        try {
            byte[] charsetNameBytes = (byte[])localeTransferable
                    .getTransferData(javaTextEncodingFlavor);
            charset = new String(charsetNameBytes, StandardCharsets.UTF_8);
        } catch (UnsupportedFlavorException cannotHappen) {
        }
    } else {
        charset = getCharsetForTextFormat(lFormat);
    }
    if (charset == null) {
        // Only happens when we have a custom text type.
        charset = Charset.defaultCharset().name();
    }
    return charset;
}
 
源代码3 项目: netbeans   文件: DnDSupport.java
private boolean handleDropImpl(Transferable t) {       
    try {
        Object o;
        if( t.isDataFlavorSupported( actionDataFlavor ) ) {
            o = t.getTransferData( actionDataFlavor );
            if( o instanceof Node ) {
                DataObject dobj = ((Node)o).getLookup().lookup( DataObject.class );
                return addButton( dobj, dropTargetButtonIndex, insertBefore );
            }
        } else {
            o = t.getTransferData( buttonDataFlavor );
            if( o instanceof DataObject ) {
                return moveButton( (DataObject)o, dropTargetButtonIndex, insertBefore );
            }
        }
    } catch( UnsupportedFlavorException e ) {
        log.log( Level.INFO, null, e );
    } catch( IOException ioE ) {
        log.log( Level.INFO, null, ioE );
    }
    return false;
}
 
源代码4 项目: netbeans   文件: DnDSupport.java
/**
 * Remove a toolbar button represented by the given Transferable.
 */
private void removeButton( Transferable t ) {
    try {
        Object o = null;
        if( t.isDataFlavorSupported(buttonDataFlavor) ) {
            o = t.getTransferData(buttonDataFlavor);
        }
        if( null != o && o instanceof DataObject ) {
            ((DataObject) o).delete();
            sourceToolbar.repaint();
        }
    } catch( UnsupportedFlavorException e ) {
        log.log( Level.INFO, null, e );
    } catch( IOException ioE ) {
        log.log( Level.INFO, null, ioE );
    }
}
 
源代码5 项目: AudioBookConverter   文件: ArtWorkController.java
public void pasteImage(ActionEvent actionEvent) {
    try {
        Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
        if (transferable != null) {
            if (transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                java.awt.Image image = (java.awt.Image) transferable.getTransferData(DataFlavor.imageFlavor);
                Image fimage = awtImageToFX(image);
                ConverterApplication.getContext().addPosterIfMissingWithDelay(new ArtWorkImage(fimage));
            } else if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                java.util.List<String> artFiles = (java.util.List<String>) transferable.getTransferData(DataFlavor.javaFileListFlavor);

                artFiles.stream().filter(s -> ArrayUtils.contains(ArtWork.IMAGE_EXTENSIONS, FilenameUtils.getExtension(s))).forEach(f -> {
                    ConverterApplication.getContext().addPosterIfMissingWithDelay(new ArtWorkBean(f));
                });
            }
        }
    } catch (Exception e) {
        logger.error("Failed to load from clipboard", e);
        e.printStackTrace();
    }
}
 
源代码6 项目: Open-Lowcode   文件: CImageChooser.java
private static java.awt.Image getImageFromClipboard() {
	Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
	if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
		try {
			return (java.awt.Image) transferable.getTransferData(DataFlavor.imageFlavor);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
源代码7 项目: jdk8u60   文件: SunDropTargetContextPeer.java
/**
 * @return if the flavor is supported
 */

public boolean isDataFlavorSupported(DataFlavor df) {
    Transferable localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.isDataFlavorSupported(df);
    } else {
        return DataTransferer.getInstance().getFlavorsForFormats
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap())).
            containsKey(df);
    }
}
 
源代码8 项目: markdown-image-kit   文件: ImageUtils.java
/**
 * Gets image from clipboard.
 *
 * @return the image from clipboard
 */
@Nullable
public static Image getImageFromClipboard() {
    Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        try {
            return (Image) transferable.getTransferData(DataFlavor.imageFlavor);
        } catch (IOException | UnsupportedFlavorException ignored) {
            // 如果 clipboard 没有图片, 不处理
        }
    }
    return null;
}
 
源代码9 项目: openjdk-jdk8u   文件: WDataTransferer.java
@Override
public byte[] translateTransferable(Transferable contents,
                                    DataFlavor flavor,
                                    long format) throws IOException
{
    byte[] bytes = null;
    if (format == CF_HTML) {
        if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
            // if a user provides data represented by
            // DataFlavor.selectionHtmlFlavor format, we use this
            // type to store the data in the native clipboard
            bytes = super.translateTransferable(contents,
                    DataFlavor.selectionHtmlFlavor,
                    format);
        } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
            // if we cannot get data represented by the
            // DataFlavor.selectionHtmlFlavor format
            // but the DataFlavor.allHtmlFlavor format is avialable
            // we belive that the user knows how to represent
            // the data and how to mark up selection in a
            // system specific manner. Therefor, we use this data
            bytes = super.translateTransferable(contents,
                    DataFlavor.allHtmlFlavor,
                    format);
        } else {
            // handle other html flavor types, including custom and
            // fragment ones
            bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
        }
    } else {
        // we handle non-html types basing on  their
        // flavors
        bytes = super.translateTransferable(contents, flavor, format);
    }
    return bytes;
}
 
源代码10 项目: jdk8u-jdk   文件: WDataTransferer.java
@Override
public byte[] translateTransferable(Transferable contents,
                                    DataFlavor flavor,
                                    long format) throws IOException
{
    byte[] bytes = null;
    if (format == CF_HTML) {
        if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
            // if a user provides data represented by
            // DataFlavor.selectionHtmlFlavor format, we use this
            // type to store the data in the native clipboard
            bytes = super.translateTransferable(contents,
                    DataFlavor.selectionHtmlFlavor,
                    format);
        } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
            // if we cannot get data represented by the
            // DataFlavor.selectionHtmlFlavor format
            // but the DataFlavor.allHtmlFlavor format is avialable
            // we belive that the user knows how to represent
            // the data and how to mark up selection in a
            // system specific manner. Therefor, we use this data
            bytes = super.translateTransferable(contents,
                    DataFlavor.allHtmlFlavor,
                    format);
        } else {
            // handle other html flavor types, including custom and
            // fragment ones
            bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
        }
    } else {
        // we handle non-html types basing on  their
        // flavors
        bytes = super.translateTransferable(contents, flavor, format);
    }
    return bytes;
}
 
源代码11 项目: dragonwell8_jdk   文件: WDataTransferer.java
@Override
public byte[] translateTransferable(Transferable contents,
                                    DataFlavor flavor,
                                    long format) throws IOException
{
    byte[] bytes = null;
    if (format == CF_HTML) {
        if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
            // if a user provides data represented by
            // DataFlavor.selectionHtmlFlavor format, we use this
            // type to store the data in the native clipboard
            bytes = super.translateTransferable(contents,
                    DataFlavor.selectionHtmlFlavor,
                    format);
        } else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
            // if we cannot get data represented by the
            // DataFlavor.selectionHtmlFlavor format
            // but the DataFlavor.allHtmlFlavor format is avialable
            // we belive that the user knows how to represent
            // the data and how to mark up selection in a
            // system specific manner. Therefor, we use this data
            bytes = super.translateTransferable(contents,
                    DataFlavor.allHtmlFlavor,
                    format);
        } else {
            // handle other html flavor types, including custom and
            // fragment ones
            bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
        }
    } else {
        // we handle non-html types basing on  their
        // flavors
        bytes = super.translateTransferable(contents, flavor, format);
    }
    return bytes;
}
 
源代码12 项目: openjdk-jdk9   文件: SunDropTargetContextPeer.java
/**
 * @return if the flavor is supported
 */

public boolean isDataFlavorSupported(DataFlavor df) {
    Transferable localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.isDataFlavorSupported(df);
    } else {
        return DataTransferer.getInstance().getFlavorsForFormats
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap())).
            containsKey(df);
    }
}
 
源代码13 项目: openjdk-jdk8u   文件: SunClipboard.java
/**
 * @see java.awt.Clipboard#isDataFlavorAvailable
 * @since 1.5
 */
public boolean isDataFlavorAvailable(DataFlavor flavor) {
    if (flavor == null) {
        throw new NullPointerException("flavor");
    }

    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.isDataFlavorSupported(flavor);
    }

    long[] formats = getClipboardFormatsOpenClose();

    return formatArrayAsDataFlavorSet(formats).contains(flavor);
}
 
源代码14 项目: CXTouch   文件: GUIUtil.java
/**
 * Return the file list on clipboard.
 */
public static java.util.List<File> getClipFile() {
    Transferable transfer = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    if (!transfer.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        return null;
    }
    java.util.List<File> fileList;
    try {
        fileList = (java.util.List<File>) transfer.getTransferData(DataFlavor.javaFileListFlavor);
        return fileList;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
 
/**
 * @return if the flavor is supported
 */

public boolean isDataFlavorSupported(DataFlavor df) {
    Transferable localTransferable = local;

    if (localTransferable != null) {
        return localTransferable.isDataFlavorSupported(df);
    } else {
        return DataTransferer.getInstance().getFlavorsForFormats
            (currentT, DataTransferer.adaptFlavorMap
                (currentDT.getFlavorMap())).
            containsKey(df);
    }
}
 
源代码16 项目: htmlunit   文件: DoTypeProcessor.java
private static String getClipboardContent() {
    String result = "";
    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    final Transferable contents = clipboard.getContents(null);
    if (contents != null && contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        }
        catch (final UnsupportedFlavorException | IOException ex) {
        }
    }
    return result;
}
 
源代码17 项目: jdk8u60   文件: SunClipboard.java
/**
 * @see java.awt.Clipboard#isDataFlavorAvailable
 * @since 1.5
 */
public boolean isDataFlavorAvailable(DataFlavor flavor) {
    if (flavor == null) {
        throw new NullPointerException("flavor");
    }

    Transferable cntnts = getContextContents();
    if (cntnts != null) {
        return cntnts.isDataFlavorSupported(flavor);
    }

    long[] formats = getClipboardFormatsOpenClose();

    return formatArrayAsDataFlavorSet(formats).contains(flavor);
}
 
源代码18 项目: constellation   文件: TypeDropper.java
@Override
public BiConsumer<Graph, DropInfo> drop(final DropTargetDropEvent dtde) {
    final Transferable transferable = dtde.getTransferable();
    if (transferable.isDataFlavorSupported(VX_DATA_FLAVOR) || transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            final String data;
            if (transferable.isDataFlavorSupported(VX_DATA_FLAVOR)) {
                final InputStream in = new ByteArrayInputStream(((ByteBuffer) transferable.getTransferData(VX_DATA_FLAVOR)).array());
                final ObjectInputStream oin = new ObjectInputStream(in);
                data = (String) oin.readObject();
            } else {
                final String t = (String) transferable.getTransferData(DataFlavor.stringFlavor);

                // Do we have the correct indicator?
                if (t != null && t.startsWith(INDICATOR)) {
                    // Skip the leading "indicator=".
                    data = t.substring(INDICATOR.length());
                } else {
                    data = null;
                }
            }

            if (data != null) {
                return (graph, dropInfo) -> {
                    PluginExecution.withPlugin(new SimpleEditPlugin("Drag and Drop: Type to Vertex") {
                        @Override
                        public void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                            final int ix = data.indexOf(':');
                            if (ix != -1) {
                                final String attrLabel = data.substring(0, ix);
                                final String value = data.substring(ix + 1);
                                final int attrId = wg.getAttribute(GraphElementType.VERTEX, attrLabel);
                                if (attrId != Graph.NOT_FOUND) {
                                    final int vxId;

                                    if (dropInfo.isIsVertex()) {
                                        vxId = dropInfo.id;

                                        // If the vertex is selected, modify all of the selected vertices.
                                        // Otherwise, just modify the dropped-on vertex.
                                        final int selectedId = VisualConcept.VertexAttribute.SELECTED.ensure(wg);
                                        if (wg.getBooleanValue(selectedId, vxId)) {
                                            final GraphIndexResult gir = GraphIndexUtilities.filterElements(wg, selectedId, true);
                                            while (true) {
                                                final int selVxId = gir.getNextElement();
                                                if (selVxId == Graph.NOT_FOUND) {
                                                    break;
                                                }

                                                wg.setStringValue(attrId, selVxId, data);
                                                if (graph.getSchema() != null) {
                                                    graph.getSchema().completeVertex(wg, selVxId);
                                                }
                                            }
                                        } else {
                                            wg.setStringValue(attrId, vxId, data);
                                            if (graph.getSchema() != null) {
                                                graph.getSchema().completeVertex(wg, vxId);
                                            }
                                        }
                                    } else {
                                        vxId = wg.addVertex();
                                        final int xId = VisualConcept.VertexAttribute.X.ensure(wg);
                                        final int yId = VisualConcept.VertexAttribute.Y.ensure(wg);
                                        final int zId = VisualConcept.VertexAttribute.Z.ensure(wg);
                                        wg.setStringValue(attrId, vxId, value);
                                        wg.setFloatValue(xId, vxId, dropInfo.location.getX());
                                        wg.setFloatValue(yId, vxId, dropInfo.location.getY());
                                        wg.setFloatValue(zId, vxId, dropInfo.location.getZ());

                                        if (graph.getSchema() != null) {
                                            graph.getSchema().newVertex(wg, vxId);
                                            graph.getSchema().completeVertex(wg, vxId);
                                        }
                                    }

                                    ConstellationLoggerHelper.importPropertyBuilder(
                                            this,
                                            Arrays.asList(data),
                                            null,
                                            ConstellationLoggerHelper.SUCCESS
                                    );
                                }
                            }
                        }
                    }).executeLater(graph);
                };
            }
        } catch (final UnsupportedFlavorException | IOException | ClassNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return null;
}
 
源代码19 项目: netbeans   文件: DragAndDropHandler.java
/**
 * Perform the drop operation and add the dragged item into the given category.
 *
 * @param targetCategory Lookup of the category that accepts the drop.
 * @param item Transferable holding the item being dragged.
 * @param dndAction Drag'n'drop action type.
 * @param dropIndex Zero-based position where the dragged item should be dropped.
 *
 * @return True if the drop has been successful, false otherwise.
 */
public boolean doDrop( Lookup targetCategory, Transferable item, int dndAction, int dropIndex ) {
    Node categoryNode = (Node)targetCategory.lookup( Node.class );
    try {
        //first check if we're reordering items within the same category
        if( item.isDataFlavorSupported( PaletteController.ITEM_DATA_FLAVOR ) ) {
            Lookup itemLookup = (Lookup)item.getTransferData( PaletteController.ITEM_DATA_FLAVOR );
            if( null != itemLookup ) {
                Node itemNode = (Node)itemLookup.lookup( Node.class );
                if( null != itemNode ) {
                    Index order = (Index)categoryNode.getCookie( Index.class );
                    if( null != order && order.indexOf( itemNode ) >= 0 ) {
                        //the drop item comes from the targetCategory so let's 
                        //just change the order of items
                        return moveItem( targetCategory, itemLookup, dropIndex );
                    }
                }
            }
        }
        PasteType paste = categoryNode.getDropType( item, dndAction, dropIndex );
        if( null != paste ) {
            Node[] itemsBefore = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
            paste.paste();
            Node[] itemsAfter = categoryNode.getChildren().getNodes( DefaultModel.canBlock() );
            
            if( itemsAfter.length == itemsBefore.length+1 ) {
                int currentIndex = -1;
                Node newItem = null;
                for( int i=itemsAfter.length-1; i>=0; i-- ) {
                    newItem = itemsAfter[i];
                    currentIndex = i;
                    for( int j=0; j<itemsBefore.length; j++ ) {
                        if( newItem.equals( itemsBefore[j] ) ) {
                            newItem = null;
                            break;
                        }
                    }
                    if( null != newItem ) {
                        break;
                    }
                }
                if( null != newItem && dropIndex >= 0 ) {
                    if( currentIndex < dropIndex )
                        dropIndex++;
                    moveItem( targetCategory, newItem.getLookup(), dropIndex );
                }
            }
            return true;
        }
        if( isTextDnDEnabled && null != DataFlavor.selectBestTextFlavor(item.getTransferDataFlavors()) ) {
            importTextIntoPalette( targetCategory, item, dropIndex );
            return false; //return false to retain the original dragged text in its source
        }
    } catch( IOException ioE ) {
        Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, ioE );
    } catch( UnsupportedFlavorException e ) {
        Logger.getLogger( DragAndDropHandler.class.getName() ).log( Level.INFO, null, e );
    }
    return false;
}
 
源代码20 项目: Logisim   文件: TableTabClip.java
public boolean canPaste() {
	Clipboard clip = table.getToolkit().getSystemClipboard();
	Transferable xfer = clip.getContents(this);
	return xfer.isDataFlavorSupported(binaryFlavor);
}