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