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


Java Transferable.getTransferData方法代码示例

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


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

示例1: addDataFlavors

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
public Transferable addDataFlavors(Transferable transferable) {
    try {
        if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR)) {
            Object data = transferable.getTransferData(ConsumerFlavorProvider.CUSTOM_METHOD_FLAVOR);
            if (data instanceof CustomSaasMethod) {
                CustomSaasMethod method = (CustomSaasMethod) data;
                ExTransferable t = ExTransferable.create(transferable);
                CustomClientEditorDrop editorDrop = new CustomClientEditorDrop(method);
                ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
                t.put(s);
                return t;
            }
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    return transferable;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CustomClientFlavorProvider.java

示例2: testCut

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Test of cut method, of class org.netbeans.modules.palette.Item.
 */
public void testCut() throws Exception {
    PaletteActions actions = new DummyActions();
    PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), actions );
    Model model = pc.getModel();

    Category[] categories = model.getCategories();
    
    for( int i=0; i<categories.length; i++ ) {
        Item[] items = categories[i].getItems();
        for( int j=0; j<items.length; j++ ) {
            Transferable t = items[j].cut();
            assertNotNull( t );
            assertTrue( t.isDataFlavorSupported( PaletteController.ITEM_DATA_FLAVOR ) );
            Lookup lookup = (Lookup)t.getTransferData( PaletteController.ITEM_DATA_FLAVOR );
            assertNotNull( lookup );
            Node node = (Node)lookup.lookup( Node.class );
            assertEquals( itemNames[i][j], node.getName() );
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ItemTest.java

示例3: getClipboardString

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Returns a string stored in the system clipboard.
 */
public static String getClipboardString()
{
    try
    {
        Transferable transferable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents((Object)null);

        if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
        {
            return (String)transferable.getTransferData(DataFlavor.stringFlavor);
        }
    }
    catch (Exception var1)
    {
        ;
    }

    return "";
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:22,代码来源:GuiScreen.java

示例4: removeButton

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

示例5: handleDropImpl

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

示例6: getClipboardContents

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Get the String residing on the clipboard.
 *
 * @return any text found on the Clipboard; if none found, return an empty String. Código copiado da internet.
 */
public static String getClipboardContents() {
    String result = "";
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    //odd: the Object param of getContents is not currently used
    Transferable contents = clipboard.getContents(null);
    boolean hasTransferableText = (contents != null)
            && contents.isDataFlavorSupported(DataFlavor.stringFlavor);
    if (hasTransferableText) {
        try {
            result = (String) contents.getTransferData(DataFlavor.stringFlavor);
        } catch (UnsupportedFlavorException | IOException ex) {
            util.BrLogger.Logger("ERROR_DIAGRAMA_CLIPBOARD", ex.getMessage());
        }
    }
    return result;
}
 
开发者ID:chcandido,项目名称:brModelo,代码行数:22,代码来源:Diagrama.java

示例7: importData

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
@Override
public boolean importData(TransferSupport support) {
	if (!canImport(support)) {
		return false;
	}

	try {
		if (currentValueSource != null) {

			// fetch data table column
			Transferable transferable = support.getTransferable();
			DataTableColumnCollection dataTableColumnCollection = (DataTableColumnCollection) transferable
					.getTransferData(DataTableColumnCollection.DATATABLE_COLUMN_COLLECTION_FLAVOR);

			currentValueSource.setDataTableColumn(seriesUsageType, dataTableColumnCollection.getDataTableColumns()
					.get(0));

		}
	} catch (Exception e) {
		e.printStackTrace();
	}

	return false;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:25,代码来源:DataTableColumnDropTextFieldTransferHandler.java

示例8: importData

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param c Description of the Parameter
 * @param t Description of the Parameter
 * @return Description of the Return Value
 */
public boolean importData(JComponent c, Transferable t) {
    if (canImport(c, t.getTransferDataFlavors())) {
        try {
            String str = (String) t.getTransferData(DataFlavor.stringFlavor);
            importString(c, str);
            return true;
        } catch (UnsupportedFlavorException | IOException ignored) {
        }
    }

    return false;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:20,代码来源:YassStringTransferHandler.java

示例9: getStringFromClipboard

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
public static String getStringFromClipboard() { 
	String text = null;
	Transferable trf = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
	if (trf != null && trf.isDataFlavorSupported(DataFlavor.stringFlavor)) {
		try {
			text = (String) trf.getTransferData(DataFlavor.stringFlavor);
		}  catch (Exception e) {};
	}
	return text; 
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:11,代码来源:Clipboard.java

示例10: drop

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
@Override
public void drop(DnDEvent event) {
    event.setDropPossible(true);
    try {
        DnDNativeTarget.EventInfo eventInfo = (DnDNativeTarget.EventInfo) event.getTransferData(DataFlavor.javaFileListFlavor);
        Transferable transferable = eventInfo.getTransferable();
        List data = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
        for (Object aData : data) {
            dnDListener.onFileDropped((File) aData);
            break;
        }
    } catch (Exception ignored) {
    }
}
 
开发者ID:josesamuel,项目名称:logviewer,代码行数:15,代码来源:DnDHandler.java

示例11: drop

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param dropTargetDropEvent Description of the Parameter
 */
public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
    try {
        Transferable tr = dropTargetDropEvent.getTransferable();
        if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            dropTargetDropEvent
                    .acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

            java.util.List fileList = (java.util.List) tr
                    .getTransferData(DataFlavor.javaFileListFlavor);
            Iterator<?> iterator = fileList.iterator();
            while (iterator.hasNext()) {
                File file = (File) iterator.next();
                String fn = file.getAbsolutePath();

                if (fn.endsWith(".kar") || fn.endsWith(".mid")) {
                    filename = fn;
                    if (sequencer.isOpen()) {
                        sequencer.close();
                    }
                    init();
                    openGUI();
                    dropTargetDropEvent.getDropTargetContext()
                            .dropComplete(true);
                    return;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    dropTargetDropEvent.dropComplete(true);
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:38,代码来源:YassMIDIConverter.java

示例12: importData

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
@Override public boolean importData(TransferHandler.TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }

    JList list = (JList) info.getComponent();
    DefaultListModel listModel = (DefaultListModel) list.getModel();
    JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
    int index = dl.getIndex();
    boolean insert = dl.isInsert();

    // Get the string that is being dropped.
    Transferable t = info.getTransferable();
    String data;
    try {
        data = (String) t.getTransferData(DataFlavor.stringFlavor);
    } catch (Exception e) {
        return false;
    }

    // Perform the actual import.
    if (insert) {
        listModel.add(index, data);
    } else {
        listModel.set(index, data);
    }
    return true;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:29,代码来源:ListTransferHandler.java

示例13: getContents

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
/**
 * Gets the contents of the system clipboard
 *
 * @return The text contents of the system clipboard
 */
public String getContents() {
    String contents = null;
    Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable data = c.getContents(null);
    if (data != null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        try {
            contents = ((String) (data.getTransferData(DataFlavor.stringFlavor)));
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed getting tranfer data: " + e.getMessage(), e);
        }
    }
    return contents;
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:19,代码来源:ClipboardHandlerAWT.java

示例14: translateBytes

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
@Override
public Object translateBytes(byte[] bytes, DataFlavor flavor, long format,
    Transferable localeTransferable) throws IOException
{


    if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
        if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
            throw new IOException("data translation failed");
        }
        String st = new String(bytes, 0, bytes.length, "UTF-16LE");
        String[] filenames = st.split("\0");
        if( 0 == filenames.length ){
            return null;
        }

        // Convert the strings to File objects
        File[] files = new File[filenames.length];
        for (int i = 0; i < filenames.length; ++i) {
            files[i] = new File(filenames[i]);
            //They are temp-files from memory Stream, so they have to be removed on exit
            files[i].deleteOnExit();
        }
        // Turn the list of Files into a List and return
        return Arrays.asList(files);
    }

    if (format == CFSTR_INETURL &&
            URL.class.equals(flavor.getRepresentationClass()))
    {
        String charset = getDefaultTextCharset();
        if (localeTransferable != null && localeTransferable.
                                                                isDataFlavorSupported(javaTextEncodingFlavor))
        {
            try {
                charset = new String((byte[])localeTransferable.
                    getTransferData(javaTextEncodingFlavor), "UTF-8");
            } catch (UnsupportedFlavorException cannotHappen) {
            }
        }
        return new URL(new String(bytes, charset));
    }

    return super.translateBytes(bytes , flavor, format,
                                    localeTransferable);

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:WDataTransferer.java

示例15: translateBytes

import java.awt.datatransfer.Transferable; //导入方法依赖的package包/类
@Override
public Object translateBytes(byte[] bytes, DataFlavor flavor, long format,
    Transferable localeTransferable) throws IOException
{


    if (format == CF_FILEGROUPDESCRIPTORA || format == CF_FILEGROUPDESCRIPTORW) {
        if (bytes == null || !DataFlavor.javaFileListFlavor.equals(flavor)) {
            throw new IOException("data translation failed");
        }
        String st = new String(bytes, 0, bytes.length, "UTF-16LE");
        String[] filenames = st.split("\0");
        if( 0 == filenames.length ){
            return null;
        }

        // Convert the strings to File objects
        File[] files = new File[filenames.length];
        for (int i = 0; i < filenames.length; ++i) {
            files[i] = new File(filenames[i]);
            //They are temp-files from memory Stream, so they have to be removed on exit
            files[i].deleteOnExit();
        }
        // Turn the list of Files into a List and return
        return Arrays.asList(files);
    }

    if (format == CFSTR_INETURL &&
            URL.class.equals(flavor.getRepresentationClass()))
    {
        String charset = Charset.defaultCharset().name();
        if (localeTransferable != null
                && localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor))
        {
            try {
                charset = new String((byte[])localeTransferable.
                    getTransferData(javaTextEncodingFlavor), "UTF-8");
            } catch (UnsupportedFlavorException cannotHappen) {
            }
        }
        return new URL(new String(bytes, charset));
    }

    return super.translateBytes(bytes , flavor, format,
                                    localeTransferable);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:WDataTransferer.java


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