本文整理汇总了Java中java.awt.datatransfer.UnsupportedFlavorException类的典型用法代码示例。如果您正苦于以下问题:Java UnsupportedFlavorException类的具体用法?Java UnsupportedFlavorException怎么用?Java UnsupportedFlavorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnsupportedFlavorException类属于java.awt.datatransfer包,在下文中一共展示了UnsupportedFlavorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClipboard
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
public void testClipboard() throws Exception {
MockServices.setServices(Cnv.class);
Clipboard c = Lookup.getDefault().lookup(Clipboard.class);
ExClipboard ec = Lookup.getDefault().lookup(ExClipboard.class);
assertEquals("Clipboard == ExClipboard", c, ec);
assertNotNull(Lookup.getDefault().lookup(ExClipboard.Convertor.class));
assertEquals(Cnv.class, Lookup.getDefault().lookup(ExClipboard.Convertor.class).getClass());
c.setContents(new ExTransferable.Single(DataFlavor.stringFlavor) {
protected Object getData() throws IOException, UnsupportedFlavorException {
return "17";
}
}, null);
Transferable t = c.getContents(null);
assertTrue("still supports stringFlavor", t.isDataFlavorSupported(DataFlavor.stringFlavor));
assertEquals("correct string in clipboard", "17", t.getTransferData(DataFlavor.stringFlavor));
assertTrue("support Integer too", t.isDataFlavorSupported(MYFLAV));
assertEquals("correct Integer", new Integer(17), t.getTransferData(MYFLAV));
}
示例2: getBestCharsetForTextFormat
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的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;
}
示例3: ExTransferable
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
/** Creates new support.
* @param t transferable to to copy values from
* @param o clipobard owner (or null)
*/
private ExTransferable(final Transferable t) {
map = new LinkedHashMap<DataFlavor,Single>();
final DataFlavor[] df = t.getTransferDataFlavors();
if (df != null) {
for (int i = 0; i < df.length; i++) {
try {
final int fi = i;
map.put(
df[i],
new Single(df[i]) {
public Object getData() throws IOException, UnsupportedFlavorException {
return t.getTransferData(df[fi]);
}
}
);
} catch (Exception ex) {
// ignore if the data cannot be retrived
}
}
}
}
示例4: reorderProjects
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
private Boolean reorderProjects(TransferHandler.TransferSupport support) {
JList list = (JList) support.getComponent();
try {
int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES);
DefaultListModel model = (DefaultListModel) list.getModel();
JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
if (dl.getIndex() != -1) {
for (int selectedIndex : selectedIndices) {
Object value = model.get(selectedIndex);
model.removeElement(value);
model.add(dl.getIndex(), value);
}
return true;
} else {
LOG.warning("Invalid Drop Location");
}
} catch (UnsupportedFlavorException | IOException ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
return false;
}
示例5: removeButton
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的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 );
}
}
示例6: handleDropImpl
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的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;
}
示例7: getTransferData
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException
{
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
Object ret = flavorsToData.get(flavor);
if (ret instanceof IOException) {
// rethrow IOExceptions generated while fetching data
throw (IOException)ret;
} else if (ret instanceof DataFactory) {
// Now we can render the data
DataFactory factory = (DataFactory)ret;
ret = factory.getTransferData(flavor);
}
return ret;
}
示例8: clipboardChanged
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
@Override
public void clipboardChanged(ClipboardEvent ev) {
ExClipboard clipboard = ev.getClipboard();
Transferable transferable = null;
String clipboardContent = null;
try {
transferable = clipboard.getContents(null);
if (transferable != null && transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
clipboardContent = (String) transferable.getTransferData(DataFlavor.stringFlavor);
}
} catch (OutOfMemoryError oom) {
NotificationDisplayer.getDefault().notify( NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom"),NotificationDisplayer.Priority.NORMAL.getIcon(), NbBundle.getBundle(ClipboardHistory.class).getString("clipboard-history-oom-details"), null);
return;
} catch (IOException ioe) {
//ignored for bug #218255
} catch (UnsupportedFlavorException ufe) {
}
if (clipboardContent != null) {
addHistory(transferable, clipboardContent);
}
}
示例9: getTransferData
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(LOCAL_TRANSFERRED_OPERATORS_FLAVOR)) {
return this.clonedOperators;
}
if (flavor.equals(DataFlavor.stringFlavor)) {
StringBuilder b = new StringBuilder();
for (Operator op : clonedOperators) {
b.append(op.getXML(false));
}
return b.toString();
} else {
throw new UnsupportedFlavorException(flavor);
}
}
示例10: valueSourceDrop
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
/**
* Is called if a {@link ValueSourceTreeNode} is dropped on the {@link PlotConfigurationTree}.
*/
private void valueSourceDrop(final ValueSourceTreeNode valueSourceTreeNode, TreePath path, final int childIndex,
boolean importDataTableColumn) throws UnsupportedFlavorException, IOException, ChartConfigurationException {
// fetch dropped value source and parent
final ValueSource valueSource = valueSourceTreeNode.getUserObject();
Object lastPathComponent = path.getLastPathComponent();
if (lastPathComponent instanceof RangeAxisConfigTreeNode) {
valueSourceDropOnRangeAxisConfig(valueSourceTreeNode, childIndex, valueSource, lastPathComponent);
} else {
valueSourceDropOnPlotConfiguration(valueSourceTreeNode, childIndex, valueSource, lastPathComponent,
importDataTableColumn);
}
}
示例11: getTransferData
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor == binaryFlavor) {
return this;
} else if (flavor == DataFlavor.stringFlavor) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
buf.append(headers[i]);
buf.append(i == headers.length - 1 ? '\n' : '\t');
}
for (int i = 0; i < contents.length; i++) {
for (int j = 0; j < contents[i].length; j++) {
buf.append(contents[i][j]);
buf.append(j == contents[i].length - 1 ? '\n' : '\t');
}
}
return buf.toString();
} else {
throw new UnsupportedFlavorException(flavor);
}
}
示例12: drop
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
@Override
public void drop(DropTargetDropEvent dtde) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
try {
Transferable t = dtde.getTransferable();
DataFlavor[] dataFlavors = t.getTransferDataFlavors();
for (DataFlavor df : dataFlavors) {
if (df.isFlavorJavaFileListType()) {
File[] filesArray = (File[]) ((List<File>) t.getTransferData(df)).toArray();
pathNameTextField.setText(getFilesName(filesArray));
}
}
} catch (UnsupportedFlavorException e2) {
} catch (IOException ex) {
Logger.getLogger(SubtitleDownloaderUI.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例13: isSrcComponentSameAsTargetComponent
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
/**
* Returns true if the drag came from the same component as we are testing for drop. Used to
* prevent drops on the src file list.
*/
public boolean isSrcComponentSameAsTargetComponent(TransferHandler.TransferSupport info)
throws UnsupportedFlavorException, IOException {
boolean result = false;
// First get where we are putting this file
String myPanelDir = profilePanel.getCurrentDirectory().getPath();
// Don't accept drags from current panel.
if (info.isDataFlavorSupported(ArrayListTransferrable.flavor)) {
// Get the Array of items being dropped.
Transferable t = info.getTransferable();
ArrayList arrayList = (ArrayList) t.getTransferData(ArrayListTransferrable.flavor);
ArcMoverFile fileBeingMoved = (ArcMoverFile) arrayList.get(2);
String fileBeingMovedDir = fileBeingMoved.getParent().getPath();
if (myPanelDir.equals(fileBeingMovedDir)) {
result = true;
}
}
return result;
}
示例14: getBestCharsetForTextFormat
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的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;
}
示例15: getTransferData
import java.awt.datatransfer.UnsupportedFlavorException; //导入依赖的package包/类
@Override
public Object getTransferData(DataFlavor flavor)
throws UnsupportedFlavorException, IOException
{
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
Object ret = flavorsToData.get(flavor);
if (ret instanceof IOException) {
// rethrow IOExceptions generated while fetching data
throw new IOException("Exception fetching data: ", (IOException)ret);
} else if (ret instanceof DataFactory) {
// Now we can render the data
DataFactory factory = (DataFactory)ret;
ret = factory.getTransferData(flavor);
}
return ret;
}