當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。