Java 类java.awt.datatransfer.Transferable 实例源码

项目:jdk8u-jdk    文件:SunClipboard.java   
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);
    }
}
项目:incubator-netbeans    文件:ActionPasteType.java   
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;
}
项目:incubator-netbeans    文件:DataTransferSupport.java   
/** 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);
}
项目:CustomWorldGen    文件:GuiScreen.java   
/**
 * 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 "";
}
项目:incubator-netbeans    文件:OutputOperatorTest.java   
/** 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();
}
项目:incubator-netbeans    文件:WsdlSaasNode.java   
@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);
}
项目:openjdk-jdk10    文件:SunClipboard.java   
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);
    }
}
项目:jdk8u-jdk    文件: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;
}
项目:incubator-netbeans    文件:PropertiesLocaleNode.java   
/** 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;
}
项目:freecol    文件:TradeRouteInputPanel.java   
/**
 * {@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());
    }
}
项目:incubator-netbeans    文件:FavoritesNode.java   
@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;
}
项目:UaicNlpToolkit    文件:MyDragHandler.java   
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;
}
项目:Pogamut3    文件:ExplorerFactory.java   
@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);
            }
        }
    };
}
项目:Neukoelln_SER316    文件:HTMLEditor.java   
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();
    }
}
项目:jdk8u-jdk    文件:WDragSourceContextPeer.java   
/**
 * downcall into native code
 */

native long createDragSource(Component component,
                             Transferable transferable,
                             InputEvent nativeTrigger,
                             int actions,
                             long[] formats,
                             Map formatMap);
项目:incubator-netbeans    文件:ItemNode.java   
public Transferable drag() throws IOException {
    ExTransferable t = ExTransferable.create( super.drag() );//NodeTransfer.transferable(this, NodeTransfer.DND_MOVE) );

    customizeTransferable( t );
    t.put( createTransferable() );

    return t;
}
项目:FreeCol    文件:DefaultTransferHandler.java   
/**
 * {@inheritDoc}
 */
@Override
public Transferable createTransferable(JComponent comp) {
    return (comp instanceof JLabel && comp instanceof Draggable)
        ? new ImageSelection((JLabel) comp)
        : null;
}
项目:incubator-netbeans    文件:HyperCompoundModel.java   
int getAllowedDropActions(Transferable t) {
    int actions = 0;
    for (Models.CompoundModel m : models) {
        actions |= m.getAllowedDropActions(t);
    }
    return actions;
}
项目:incubator-netbeans    文件:TreeRootNode.java   
@Override public Transferable clipboardCut() throws IOException {
    DataFolder top = topPackage();
    if (top != null) {
        return top.getNodeDelegate().clipboardCut();
    } else {
        return super.clipboardCut();
    }
}
项目:jdk8u-jdk    文件:XClipboard.java   
@Override
public synchronized Transferable getContents(Object requestor) {
    if (contents != null) {
        return contents;
    }
    return new ClipboardTransferable(this);
}
项目:incubator-netbeans    文件:PackageViewChildren.java   
@Override
public Transferable clipboardCut () throws IOException {
    try {
        return new PackageTransferable (this, DnDConstants.ACTION_MOVE);
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
项目:incubator-netbeans    文件:EditorTestCase.java   
protected ValueResolver getClipboardResolver(final JEditorPaneOperator txtOper, final Transferable oldClipValue){

    ValueResolver clipboardValueResolver = new ValueResolver(){
        public Object getValue(){
            Transferable newClipValue = txtOper.getToolkit().getSystemClipboard().getContents(txtOper);
            log("newClipValue:"+newClipValue);
            return (newClipValue == oldClipValue) ? Boolean.TRUE : Boolean.FALSE;
        }
    };

    return clipboardValueResolver;
}
项目:Tarski    文件:mxGraphTransferHandler.java   
/**
 * Counts the number of times that the given transferable has been imported.
 */
protected void updateImportCount(Transferable t) {
  if (lastImported != t) {
    importCount = initialImportCount;
  } else {
    importCount++;
  }

  lastImported = t;
}
项目:Pogamut3    文件:ExplorerFactory.java   
@Override
public Transferable createTransferable(PrimitiveData data) {
    if (data == null) {
        return null;
    }
    String actionName = data.classFQN;
    return new NodeTransferable<TriggeredAction>(LapElementsFactory.createAction(actionName));
}
项目:imagingbook-common    文件:Clipboard.java   
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; 
}
项目:openjdk-jdk10    文件:LastNodeLowerHalfDrop.java   
@Override
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree) c;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies = new ArrayList<>();
        List<DefaultMutableTreeNode> toRemove = new ArrayList<>();
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for (int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next = (DefaultMutableTreeNode) paths[i]
                    .getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if (next.getLevel() < node.getLevel()) {
                break;
            } else if (next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes = copies
                .toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove = toRemove.toArray(
                new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
项目:Pogamut3    文件:Explorer.java   
@Override
protected Transferable createTransferable(JComponent c) {
    if (selectedIndex != 0) {
        return createItemTransferable(getSelected());
    }
    // Create transferable for creation of new item
    return newItemTransferable;
}
项目:openjdk-jdk10    文件:ImageTransferTest.java   
void checkImage(DropTargetDropEvent dtde) {
    final Transferable t = dtde.getTransferable();
    if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY);
        Image im;
        try {
            im = (Image) t.getTransferData(DataFlavor.imageFlavor);
            System.err.println("getTransferData was successful");
        } catch (Exception e) {
            System.err.println("Can't getTransferData: " + e);
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
            return;
        }

        if (im == null) {
            System.err.println("getTransferData returned null");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        } else if (areImagesIdentical(image, im)) {
            dtde.dropComplete(true);
            notifyTransferSuccess(true);
        } else {
            System.err.println("transferred image is different from initial image");
            dtde.dropComplete(false);
            notifyTransferSuccess(false);
        }

    } else {
        System.err.println("imageFlavor is not supported by Transferable");
        dtde.rejectDrop();
        notifyTransferSuccess(false);
    }
}
项目:incubator-netbeans    文件:AbstractNode.java   
/** Determine which paste operations are allowed when a given transferable is in the clipboard.
* Subclasses should override {@link #createPasteTypes}.
*
* @param t the transferable in the clipboard
* @return array of operations that are allowed
*/
public final PasteType[] getPasteTypes(Transferable t) {
    List<PasteType> s = new LinkedList<PasteType>();
    createPasteTypes(t, s);

    return s.toArray(NO_PASTE_TYPES);
}
项目:jdk8u-jdk    文件:WDataTransferer.java   
@Override
public Object translateStream(InputStream str,
                             DataFlavor flavor, long format,
                             Transferable localeTransferable)
    throws IOException
{
    if (format == CF_HTML && flavor.isFlavorTextType()) {
        str = new HTMLCodec(str,
                             EHTMLReadMode.getEHTMLReadMode(flavor));

    }
    return super.translateStream(str, flavor, format,
                                    localeTransferable);

}
项目:freecol    文件:BuildQueuePanel.java   
/**
 * {@inheritDoc}
 */
@Override
protected void exportDone(JComponent source, Transferable data, 
                          int action) {
    //this.indices = null;
    this.numberOfItems = 0;
    updateAllLists();
}
项目:incubator-netbeans    文件:Models.java   
@Override
public PasteType getDropType(Object node, Transferable t, int action,
                             int index) throws UnknownTypeException {
    if (dndfilter != null) {
        return dndfilter.getDropType(model, node, t, action, index);
    } else {
        return model.getDropType(node, t, action, index);
    }
}
项目:incubator-netbeans    文件:WadlMethodNode.java   
@Override
public Transferable clipboardCopy() throws IOException {
    if (method.getSaas().getState() != Saas.State.READY) {
        method.getSaas().toStateReady(false);
        return super.clipboardCopy();
    }
    return SaasTransferable.addFlavors(transferable);
}
项目:JAddOn    文件:TreeTransferHandler.java   
protected Transferable createTransferable(JComponent c) {
    JTree tree = (JTree)c;
    TreePath[] paths = tree.getSelectionPaths();
    if(paths != null) {
        // Make up a node array of copies for transfer and
        // another for/of the nodes that will be removed in
        // exportDone after a successful drop.
        List<DefaultMutableTreeNode> copies =
            new ArrayList<DefaultMutableTreeNode>();
        List<DefaultMutableTreeNode> toRemove =
            new ArrayList<DefaultMutableTreeNode>();
        DefaultMutableTreeNode node =
            (DefaultMutableTreeNode)paths[0].getLastPathComponent();
        DefaultMutableTreeNode copy = copy(node);
        copies.add(copy);
        toRemove.add(node);
        for(int i = 1; i < paths.length; i++) {
            DefaultMutableTreeNode next =
                (DefaultMutableTreeNode)paths[i].getLastPathComponent();
            // Do not allow higher level nodes to be added to list.
            if(next.getLevel() < node.getLevel()) {
                break;
            } else if(next.getLevel() > node.getLevel()) {  // child node
                copy.add(copy(next));
                // node already contains child
            } else {                                        // sibling
                copies.add(copy(next));
                toRemove.add(next);
            }
        }
        DefaultMutableTreeNode[] nodes =
            copies.toArray(new DefaultMutableTreeNode[copies.size()]);
        nodesToRemove =
            toRemove.toArray(new DefaultMutableTreeNode[toRemove.size()]);
        return new NodesTransferable(nodes);
    }
    return null;
}
项目:openjdk-jdk10    文件:XClipboard.java   
@Override
public synchronized Transferable getContents(Object requestor) {
    if (contents != null) {
        return contents;
    }
    return new ClipboardTransferable(this);
}
项目:ramus    文件:RowTreeTable.java   
public Transferable createTransferable() {
    exporting = true;
    final int[] is = getSelectedRows();
    final ArrayList<Integer> al = new ArrayList<Integer>();
    Rows rows = new Rows();
    for (final int i : is) {
        al.add(i);
        TreeTableNode node = (TreeTableNode) getPathForRow(i)
                .getLastPathComponent();
        if ((node != null) && (node.getRow() != null))
            rows.add(node.getRow());
    }
    return new ArrayTransferable(al, rows);
}
项目:OpenJSharp    文件:SunClipboard.java   
public synchronized void setContents(Transferable contents,
                                     ClipboardOwner owner) {
    // 4378007 : Toolkit.getSystemClipboard().setContents(null, null)
    // should throw NPE
    if (contents == null) {
        throw new NullPointerException("contents");
    }

    initContext();

    final ClipboardOwner oldOwner = this.owner;
    final Transferable oldContents = this.contents;

    try {
        this.owner = owner;
        this.contents = new TransferableProxy(contents, true);

        setContentsNative(contents);
    } finally {
        if (oldOwner != null && oldOwner != owner) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    oldOwner.lostOwnership(SunClipboard.this, oldContents);
                }
            });
        }
    }
}
项目:incubator-netbeans    文件:CategoryTest.java   
private Transferable createTransferable( final Item item ) {
    return new ExTransferable.Single( PaletteController.ITEM_DATA_FLAVOR ) {
        protected Object getData() throws IOException, UnsupportedFlavorException {
            return item.getLookup();
        }
    };
}
项目:jdk8u-jdk    文件:XClipboard.java   
protected synchronized void setContentsNative(Transferable contents) {
    SortedMap<Long,DataFlavor> formatMap =
        DataTransferer.getInstance().getFormatsForTransferable
            (contents, DataTransferer.adaptFlavorMap(getDefaultFlavorTable()));
    long[] formats = DataTransferer.keysToLongArray(formatMap);

    if (!selection.setOwner(contents, formatMap, formats,
                            XToolkit.getCurrentServerTime())) {
        this.owner = null;
        this.contents = null;
    }
}
项目:incubator-netbeans    文件:ExplorerDnDManager.java   
void setDraggedTransferable(Transferable trans, boolean isCut) {
    if (isCut) {
        draggedTransForCut = trans;
    } else {
        draggedTransForCopy = trans;
    }
}