本文整理汇总了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;
}
示例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() );
}
}
}
示例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 "";
}
示例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 );
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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) {
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}