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


Java Transferable类代码示例

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


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

示例1: lostOwnershipNow

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
protected void lostOwnershipNow(final AppContext disposedContext) {
    final SunClipboard sunClipboard = SunClipboard.this;
    ClipboardOwner owner = null;
    Transferable contents = null;

    synchronized (sunClipboard) {
        final AppContext context = sunClipboard.contentsContext;

        if (context == null) {
            return;
        }

        if (disposedContext == null || context == disposedContext) {
            owner = sunClipboard.owner;
            contents = sunClipboard.contents;
            sunClipboard.contentsContext = null;
            sunClipboard.owner = null;
            sunClipboard.contents = null;
            sunClipboard.clearNativeContext();
            context.removePropertyChangeListener
                    (AppContext.DISPOSED_PROPERTY_NAME, sunClipboard);
        } else {
            return;
        }
    }
    if (owner != null) {
        owner.lostOwnership(sunClipboard, contents);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:SunClipboard.java

示例2: paste

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
public Transferable paste() throws IOException {
    if (targetFolder != null) {
        for (Iterator iterator = sourceDataObjects.iterator(); iterator.hasNext();) {
            DataObject dataObject = (DataObject) iterator.next();
            boolean isValid = dataObject != null && dataObject.isValid();
            
            if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_COPY) {
                dataObject.createShadow(targetFolder);
            } 
            
            if (isValid && pasteOperation == LoaderTransfer.CLIPBOARD_CUT) {
                dataObject.move(targetFolder);
            }
                                
        }                
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ActionPasteType.java

示例3: createPasteTypes

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
/** Fills in the list of paste types available for given set to transfered
 * DataObjects.
 * @param t clipboard Transferable object, list of transfered DataObjects with their flavors
 * @param s list of paste types supported for transfered objects
 */
public final void createPasteTypes (Transferable t, java.util.List<PasteType> s) {
    /** All supported operations. */
    int [] ops = defineOperations ();

    for (int i = 0; i < ops.length; i++) {
        DataObject objs [] = LoaderTransfer.getDataObjects (t, ops[i]);
        PasteTypeExt pts [];

        if (objs == null || objs.length == 0)
            continue;

        pts = definePasteTypes (ops[i]);

        for (int j = 0; j < pts.length; j++) {
            pts[j].setDataObjects (objs);
            if (pts[j].canPaste ())
                s.add (pts[j]);
        }
    }

    handleCreatePasteTypes (t, s);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:DataTransferSupport.java

示例4: 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:F1r3w477,项目名称:CustomWorldGen,代码行数:22,代码来源:GuiScreen.java

示例5: getClipboardText

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
/** Wait until clipboard contains string data and returns the text. */
private String getClipboardText() throws Exception {
    Waiter waiter = new Waiter(new Waitable() {

        @Override
        public Object actionProduced(Object obj) {
            Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
            if (contents == null) {
                return null;
            } else {
                return contents.isDataFlavorSupported(DataFlavor.stringFlavor) ? Boolean.TRUE : null;
            }
        }

        @Override
        public String getDescription() {
            return ("Wait clipboard contains string data");
        }
    });
    waiter.waitAction(null);
    return Toolkit.getDefaultToolkit().getSystemClipboard().
            getContents(null).getTransferData(DataFlavor.stringFlavor).toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:OutputOperatorTest.java

示例6: clipboardCopy

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
@Override
public Transferable clipboardCopy() throws IOException {
    if (getSaas().getState() != Saas.State.READY) {
        getSaas().toStateReady(true);
        return super.clipboardCopy();
    }
    if (! portAdded) {
        final WsdlSaasPort port = getDefaultPort(getSaas());
        if (port != null) {
            transferable.put(new Single(ConsumerFlavorProvider.PORT_FLAVOR) {
                @Override
                protected Object getData() throws IOException, UnsupportedFlavorException {
                    return port;
                }

            });
        }
        portAdded = true;
    }
    return SaasTransferable.addFlavors(transferable);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:WsdlSaasNode.java

示例7: getBestCharsetForTextFormat

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:DataTransferer.java

示例8: paste

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
/** Performs the paste action.
 * @return <code>Transferable</code> which should be inserted into the clipboard after
 * paste action. It can be null, which means that clipboard content
 * should stay the same
 */
public Transferable paste() throws IOException {
    PropertiesStructure ps = ((PropertiesFileEntry)getFileEntry()).getHandler().getStructure();
    String value;
    if (mode == MODE_PASTE_WITH_VALUE) {
        value = item.getValue();
    } else {
        value = "";
    }
    if (ps != null) {
        Element.ItemElem newItem = ps.getItem(item.getKey());
        if (newItem == null) {
            ps.addItem(item.getKey(), value, item.getComment());
        }
        else {
            newItem.setValue(value);
            newItem.setComment(item.getComment());
        }
        if (node != null) {
            node.destroy();
        }
    }

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

示例9: exportDone

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void exportDone(JComponent source, Transferable data,
                          int action) {
    try {
        if (source instanceof JList && action == MOVE) {
            JList stopList = (JList)source;
            DefaultListModel listModel
                = (DefaultListModel)stopList.getModel();
            for (Object o : (List) data.getTransferData(STOP_FLAVOR)) {
                listModel.removeElement(o);
            }
        }
    } catch (Exception e) {
        logger.warning(e.toString());
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:20,代码来源:TradeRouteInputPanel.java

示例10: paste

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
@Override
public Transferable paste() throws IOException {
    Tab.RP.post(new Runnable () {
        @Override
        public void run() {
            Set<FileObject> fos = new HashSet<FileObject>(files.size());
            for (File f : files) {
                FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(f));
                if (fo != null) {
                    fos.add(fo);
                }
            }
            if (!fos.isEmpty()) {
                try {
                    Favorites.getDefault().add(fos.toArray(new FileObject[fos.size()]));
                } catch (DataObjectNotFoundException ex) {
                    Logger.getLogger(FavoritesNode.class.getName()).log(Level.INFO, null, ex);
                }
            }
        }
    });
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:FavoritesNode.java

示例11: importData

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
public boolean importData(JComponent comp, Transferable t) {
    if (GrammarEditor.theEditor.shouldSave) {
        int answer = JOptionPane.showConfirmDialog(GrammarEditor.theEditor.frame, "Save before opening a new grammar?", null, JOptionPane.YES_NO_CANCEL_OPTION);
        if (answer == JOptionPane.YES_OPTION)
            GrammarEditor.theEditor.save.doClick();
        else if (answer == JOptionPane.CANCEL_OPTION)
            return false;
    }

    File f = null;
    try {
        f = ((List<File>) t.getTransferData(DataFlavor.javaFileListFlavor)).get(0);
        GrammarEditor.theEditor.openGrammar(f);
        return true;
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(GrammarEditor.theEditor.frame, ex.getMessage(), "Can't drag file", JOptionPane.ERROR_MESSAGE);
    }

    return false;
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:21,代码来源:MyDragHandler.java

示例12: createNewTransferable

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
@Override
public Transferable createNewTransferable() {
    return new ExTransferable.Single(Competence.dataFlavor) {

        @Override
        protected Object getData() throws IOException, UnsupportedFlavorException {
            String competenceName = PGSupport.getIdentifierFromDialog("Name of competence");
            if (competenceName == null) {
                return null;
            }

            String elementName = PGSupport.getIdentifierFromDialog("Name of competence atom");
            if (elementName == null) {
                return null;
            }
            try {
                return LapElementsFactory.createCompetence(competenceName, elementName);
            } catch (DuplicateNameException ex) {
                throw new FubarException("Creating new competence with only one name, what duplicate?", ex);
            }
        }
    };
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:24,代码来源:ExplorerFactory.java

示例13: doPaste

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
private void doPaste() {
	Clipboard clip =
		java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
	try {
		Transferable content = clip.getContents(this);
		if (content == null)
			return;
		String txt =
			content
				.getTransferData(new DataFlavor(String.class, "String"))
				.toString();
		document.replace(
			editor.getSelectionStart(),
			editor.getSelectionEnd() - editor.getSelectionStart(),
			txt,
			editorKit.getInputAttributes());
		//editor.replaceSelection(content.getTransferData(new
		// DataFlavor(String.class, "String")).toString());
		//editor.paste();
		//insertHTML(content.getTransferData(new DataFlavor(String.class,
		// "String")).toString(), editor.getCaretPosition());
		/*
		 * Element el =
		 * document.getParagraphElement(editor.getCaretPosition());
		 * insertTextInElement(el, content.getTransferData(new
		 * DataFlavor(String.class, "String")).toString(),
		 */

	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:33,代码来源:HTMLEditor.java

示例14: createDragSource

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
/**
 * downcall into native code
 */

native long createDragSource(Component component,
                             Transferable transferable,
                             InputEvent nativeTrigger,
                             int actions,
                             long[] formats,
                             Map formatMap);
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:WDragSourceContextPeer.java

示例15: drag

import java.awt.datatransfer.Transferable; //导入依赖的package包/类
public Transferable drag() throws IOException {
    ExTransferable t = ExTransferable.create( super.drag() );//NodeTransfer.transferable(this, NodeTransfer.DND_MOVE) );
    
    customizeTransferable( t );
    t.put( createTransferable() );
    
    return t;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ItemNode.java


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