本文整理匯總了Java中java.awt.datatransfer.Transferable.isDataFlavorSupported方法的典型用法代碼示例。如果您正苦於以下問題:Java Transferable.isDataFlavorSupported方法的具體用法?Java Transferable.isDataFlavorSupported怎麽用?Java Transferable.isDataFlavorSupported使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.datatransfer.Transferable
的用法示例。
在下文中一共展示了Transferable.isDataFlavorSupported方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addDataFlavors
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
public Transferable addDataFlavors(Transferable transferable) {
try {
if (transferable.isDataFlavorSupported(ConsumerFlavorProvider.WADL_METHOD_FLAVOR)) {
Object data = transferable.getTransferData(ConsumerFlavorProvider.WADL_METHOD_FLAVOR);
if (data instanceof WadlSaasMethod) {
WadlSaasMethod method = (WadlSaasMethod) data;
ExTransferable t = ExTransferable.create(transferable);
RestClientEditorDrop editorDrop = new RestClientEditorDrop(method);
ActiveEditorDropTransferable s = new ActiveEditorDropTransferable(editorDrop);
t.put(s);
return t;
}
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
return transferable;
}
示例2: 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 );
}
}
示例3: 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();
}
示例4: 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;
}
示例5: processTransferable
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
/**
* Processes given <code>transferable</code> and returns the corresponding
* <code>NewComponentDrop</code>.
*
* @param formModel corresponding form model.
* @param transferable description of transferred data.
* @return <code>NewComponentDrop</code> that corresponds to given
* <code>transferable</code> or <code>null</code> if this provider
* don't understand to or don't want to process this data transfer.
*/
@Override
public NewComponentDrop processTransferable(FormModel formModel, Transferable transferable) {
if (J2EEUtils.supportsJPA(formModel)) {
try {
if (transferable.isDataFlavorSupported(DatabaseMetaDataTransfer.CONNECTION_FLAVOR)) {
DatabaseMetaDataTransfer.Connection connection = (DatabaseMetaDataTransfer.Connection)transferable.getTransferData(DatabaseMetaDataTransfer.CONNECTION_FLAVOR);
return new DBConnectionDrop(formModel, connection);
} else if (transferable.isDataFlavorSupported(DatabaseMetaDataTransfer.COLUMN_FLAVOR)) {
DatabaseMetaDataTransfer.Column column = (DatabaseMetaDataTransfer.Column)transferable.getTransferData(DatabaseMetaDataTransfer.COLUMN_FLAVOR);
return new DBColumnDrop(formModel, column);
} else if (transferable.isDataFlavorSupported(DatabaseMetaDataTransfer.TABLE_FLAVOR)) {
DatabaseMetaDataTransfer.Table table = (DatabaseMetaDataTransfer.Table)transferable.getTransferData(DatabaseMetaDataTransfer.TABLE_FLAVOR);
return new DBTableDrop(formModel, table);
}
} catch (Exception ex) {
// should not happen
Logger.getLogger(getClass().getName()).log(Level.INFO, ex.getMessage(), ex);
}
}
return null;
}
示例6: getBestCharsetForTextFormat
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
protected String getBestCharsetForTextFormat(Long lFormat,
Transferable localeTransferable) throws IOException
{
String charset = null;
if (localeTransferable != null &&
isLocaleDependentTextFormat(lFormat) &&
localeTransferable.isDataFlavorSupported(javaTextEncodingFlavor)) {
try {
byte[] charsetNameBytes = (byte[])localeTransferable
.getTransferData(javaTextEncodingFlavor);
charset = new String(charsetNameBytes, StandardCharsets.UTF_8);
} catch (UnsupportedFlavorException cannotHappen) {
}
} else {
charset = getCharsetForTextFormat(lFormat);
}
if (charset == null) {
// Only happens when we have a custom text type.
charset = Charset.defaultCharset().name();
}
return charset;
}
示例7: drop
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent dtde) {
try {
Transferable t = dtde.getTransferable();
List<File> files = null;
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
files = (List<File>) t
.getTransferData(DataFlavor.javaFileListFlavor);
} else if (uriFlavor != null && t.isDataFlavorSupported(uriFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_REFERENCE);
files = textURIListToFileList((String) t
.getTransferData(uriFlavor));
} else
dtde.rejectDrop();
if (files != null && files.size() == 1) {
openFile(files.get(0));
dtde.dropComplete(true);
} else
dtde.dropComplete(false);
} catch (UnsupportedFlavorException ex) {
dtde.rejectDrop();
} catch (IOException e) {
dtde.rejectDrop();
}
}
示例8: getContents
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
/**
* Gets the contents of the system clipboard
*
* @return The text system clipboad contents
*/
public String getContents() {
String contents = null;
try {
ClipboardService cs = (ClipboardService) ServiceManager.lookup(ClipboardService.class.getName());
Transferable data = cs.getContents();
if (data != null && data.isDataFlavorSupported(DataFlavor.stringFlavor)) {
contents = ((String) (data.getTransferData(DataFlavor.stringFlavor)));
}
} catch (Exception e) {
logger.log(Level.WARNING, "Failed getting the clipboard contents: " + e.getMessage(), e);
}
return contents;
}
示例9: translateTransferable
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
@Override
public byte[] translateTransferable(Transferable contents,
DataFlavor flavor,
long format) throws IOException
{
byte[] bytes = null;
if (format == CF_HTML) {
if (contents.isDataFlavorSupported(DataFlavor.selectionHtmlFlavor)) {
// if a user provides data represented by
// DataFlavor.selectionHtmlFlavor format, we use this
// type to store the data in the native clipboard
bytes = super.translateTransferable(contents,
DataFlavor.selectionHtmlFlavor,
format);
} else if (contents.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
// if we cannot get data represented by the
// DataFlavor.selectionHtmlFlavor format
// but the DataFlavor.allHtmlFlavor format is avialable
// we belive that the user knows how to represent
// the data and how to mark up selection in a
// system specific manner. Therefor, we use this data
bytes = super.translateTransferable(contents,
DataFlavor.allHtmlFlavor,
format);
} else {
// handle other html flavor types, including custom and
// fragment ones
bytes = HTMLCodec.convertToHTMLFormat(super.translateTransferable(contents, flavor, format));
}
} else {
// we handle non-html types basing on their
// flavors
bytes = super.translateTransferable(contents, flavor, format);
}
return bytes;
}
示例10: checkImage
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
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);
}
}
示例11: getAllowedDropActions
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
public int getAllowedDropActions(Transferable t) {
if (t != null && t.isDataFlavorSupported(new DataFlavor(Watch.class, null))) {
return DnDConstants.ACTION_COPY_OR_MOVE;
} else {
return DnDConstants.ACTION_COPY;
}
}
示例12: isAcceptable
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
/**
* Does @transferable support {@link #dataFlavor}?
*
* @param transferable Transferable that is being tested if it supports the
* data flavor that is accepted by this action.
* @return True if transferable can be dropped on this.
*/
@Override
public final ConnectorState isAcceptable(Widget arg0, Point arg1, Transferable transferable) {
if (transferable.isDataFlavorSupported(dataFlavor)) {
return ConnectorState.ACCEPT;
}
return ConnectorState.REJECT;
}
示例13: 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;
}
示例14: getDropType
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
@Override
public PasteType getDropType(Transferable t, int action, int index) {
if( t.isDataFlavorSupported( PaletteController.ITEM_DATA_FLAVOR ) )
return super.getDropType(t, action, index);
return null;
}
示例15: canPaste
import java.awt.datatransfer.Transferable; //導入方法依賴的package包/類
public boolean canPaste() {
Clipboard clip = editor.getToolkit().getSystemClipboard();
Transferable xfer = clip.getContents(this);
return xfer.isDataFlavorSupported(binaryFlavor);
}