当前位置: 首页>>代码示例>>Java>>正文


Java DataFlavor.selectBestTextFlavor方法代码示例

本文整理汇总了Java中java.awt.datatransfer.DataFlavor.selectBestTextFlavor方法的典型用法代码示例。如果您正苦于以下问题:Java DataFlavor.selectBestTextFlavor方法的具体用法?Java DataFlavor.selectBestTextFlavor怎么用?Java DataFlavor.selectBestTextFlavor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.datatransfer.DataFlavor的用法示例。


在下文中一共展示了DataFlavor.selectBestTextFlavor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: canDrop

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * @param targetCategory Lookup of the category under the drop cursor.
 * @param flavors Supported DataFlavors.
 * @param dndAction Drop action type.
 *
 * @return True if the given category can accept the item being dragged.
 */
public boolean canDrop( Lookup targetCategory, DataFlavor[] flavors, int dndAction ) {
    for( int i=0; i<flavors.length; i++ ) {
        if( PaletteController.ITEM_DATA_FLAVOR.equals( flavors[i] ) ) {
            return true;
        }
    }
    return (isTextDnDEnabled && DataFlavor.selectBestTextFlavor(flavors) != null);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:DragAndDropHandler.java

示例2: importTextIntoPalette

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
private boolean importTextIntoPalette( Lookup targetCategory, Transferable item, int dropIndex ) 
        throws IOException, UnsupportedFlavorException {
    
    DataFlavor flavor = DataFlavor.selectBestTextFlavor( item.getTransferDataFlavors() );
    if( null == flavor )
        return false;
    
    String textToImport = extractText( item, flavor );
    SwingUtilities.invokeLater( new TextImporter( textToImport, targetCategory, dropIndex ) );
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:DragAndDropHandler.java

示例3: getPasteTypes

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public PasteType[] getPasteTypes(final Object node, final Transferable t) throws UnknownTypeException {
    if (node != TreeModel.ROOT && getWatch(node) == null) {
        return null;
    }
    DataFlavor[] flavors = t.getTransferDataFlavors();
    final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors);
    if (textFlavor != null) {
        return new PasteType[] { new PasteType() {

            public Transferable paste() {
                try {
                    java.io.Reader r = textFlavor.getReaderForText(t);
                    java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000);
                    r.read(cb);
                    cb.flip();
                    Watch w = getWatch(node);
                    if (w != null) {
                        w.setExpression(cb.toString());
                        //fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node));
                    } else {
                        // Root => add a new watch
                        DebuggerManager.getDebuggerManager().createWatch(cb.toString());
                    }
                } catch (Exception ex) {}
                return null;
            }
        } };
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:WatchesNodeModel.java

示例4: main

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public static void main(String[] args) {

        DataFlavor flavor1 = new DataFlavor("text/plain; charset=unicode; class=java.io.InputStream",
                "Flavor 1");
        DataFlavor flavor2 = new DataFlavor("text/plain; class=java.io.InputStream", "Flavor 2");
        DataFlavor[] flavors = new DataFlavor[]{flavor1, flavor2};
        try {
            DataFlavor best = DataFlavor.selectBestTextFlavor(flavors);
            System.out.println("best=" + best);
        } catch (NullPointerException e1) {
            throw new RuntimeException("Test FAILED because of NPE in selectBestTextFlavor");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:SelectBestFlavorNPETest.java

示例5: main

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public static void main(String[] args) {
    final String[] failureMessages = {
        "DataFlavor.selectBestTextFlavor(null) doesn't return null.",
        "DataFlavor.selectBestTextFlavor() doesn't return null for an empty array.",
        "DataFlavor.selectBestTextFlavor() shouldn't return flavor in an unsupported encoding."
    };
    Stack<String> failures = new Stack<>();

    DataFlavor flavor = DataFlavor.selectBestTextFlavor(null);
    if (flavor != null) {
        failures.push(failureMessages[0]);
    }
    flavor = DataFlavor.selectBestTextFlavor(new DataFlavor[0]);
    if (flavor != null) {
        failures.push(failureMessages[1]);
    }

    try {
        flavor = DataFlavor.selectBestTextFlavor(new DataFlavor[]
            { new DataFlavor("text/plain; charset=unsupported; class=java.io.InputStream") });
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        failures.push("Exception thrown: " + e.toString());
    }
    if (flavor != null) {
        failures.push(failureMessages[2]);
    }

    if (failures.size() > 0) {
        String failureReport = failures.stream().collect(Collectors.joining("\n"));
        throw new RuntimeException("TEST FAILED: \n" + failureReport);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:SelectBestTextFlavorBadArrayTest.java

示例6: doDrop

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:DragAndDropHandler.java

示例7: getDropType

import java.awt.datatransfer.DataFlavor; //导入方法依赖的package包/类
public PasteType getDropType(final Object node, final Transferable t, int action,
                             final int index) throws UnknownTypeException {
    //System.err.println("\n\ngetDropType("+node+", "+t+", "+action+", "+index+")");
    DataFlavor[] flavors = t.getTransferDataFlavors();
    final DataFlavor textFlavor = DataFlavor.selectBestTextFlavor(flavors);
    //System.err.println("Text Flavor = "+textFlavor);
    if (textFlavor != null) {
        return new PasteType() {

            public Transferable paste() {
                String watchExpression;
                try {
                    java.io.Reader r = textFlavor.getReaderForText(t);
                    java.nio.CharBuffer cb = java.nio.CharBuffer.allocate(1000);
                    r.read(cb);
                    cb.flip();
                    watchExpression = cb.toString();
                } catch (Exception ex) {
                    return t;
                }
                Watch w = getWatch(node);
                if (w != null) {
                    w.setExpression(watchExpression);
                    //fireModelChange(new ModelEvent.NodeChanged(WatchesNodeModel.this, node));
                } else {
                    // Root => add a new watch
                    if (index < 0) {
                        DebuggerManager.getDebuggerManager().createWatch(watchExpression);
                    } else {
                        DebuggerManager.getDebuggerManager().createWatch(
                                Math.min(index, DebuggerManager.getDebuggerManager().getWatches().length),
                                watchExpression);
                    }
                }
                return t;
            }
        };
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:WatchesNodeModel.java


注:本文中的java.awt.datatransfer.DataFlavor.selectBestTextFlavor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。