use of java.awt.datatransfer.UnsupportedFlavorException in project cytoscape-impl by cytoscape.
the class DragHandler method drop.
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent event) {
JComponent target = getPrimaryView(view);
setCursor(null, view);
try {
List<Integer> path = (List<Integer>) event.getTransferable().getTransferData(PathDataFlavor.instance);
JComponent sourceView = controller.getChild(parent, path);
if (sourceView == target) {
event.rejectDrop();
return;
}
List<Integer> targetPath = controller.getPath(parent, target);
if (targetPath == null) {
event.rejectDrop();
return;
}
if (!controller.supportsDrop(parent, path, sourceView, targetPath, target) || isEquivalentLocation(path, targetPath, target)) {
event.rejectDrop();
return;
}
controller.handleDrop(parent, sourceView, path, target, targetPath);
event.acceptDrop(DnDConstants.ACTION_LINK);
event.dropComplete(true);
} catch (UnsupportedFlavorException e) {
logger.error("Unexpected error", e);
} catch (IOException e) {
logger.error("Unexpected error", e);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project Spark by igniterealtime.
the class ContactGroupTransferHandler method importData.
public boolean importData(JComponent comp, Transferable t) {
if (comp instanceof JList) {
JList list = (JList) comp;
ContactGroup group = getContactGroup(list);
if (t.isDataFlavorSupported(flavors[0])) {
try {
ContactItem item = (ContactItem) t.getTransferData(flavors[0]);
DefaultListModel model = (DefaultListModel) list.getModel();
int size = model.getSize();
for (int i = 0; i < size; i++) {
ContactItem it = (ContactItem) model.getElementAt(i);
if (it.getDisplayName().equals(item.getDisplayName())) {
return false;
}
}
addContactItem(group, item);
return true;
} catch (UnsupportedFlavorException ignored) {
} catch (IOException ignored) {
}
} else if (t.isDataFlavorSupported(flavors[1])) {
try {
Object o = t.getTransferData(flavors[1]);
if (o instanceof java.util.Collection) {
Collection<File> files = (Collection<File>) o;
ContactItem source = (ContactItem) list.getSelectedValue();
if (source == null || source.getJID() == null) {
return false;
}
// Otherwise fire files dropped event.
SparkManager.getWorkspace().getContactList().fireFilesDropped(files, source);
}
} catch (UnsupportedFlavorException e) {
Log.error(e);
} catch (IOException e) {
Log.error(e);
}
}
}
return false;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project financial by greatkendy123.
the class ClipBoardUtil method setClipboardImage.
/**
* 复制图片到剪切板。
*/
public static void setClipboardImage(final Image image) {
Transferable trans = new Transferable() {
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.imageFlavor };
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return DataFlavor.imageFlavor.equals(flavor);
}
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (isDataFlavorSupported(flavor))
return image;
throw new UnsupportedFlavorException(flavor);
}
};
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trans, null);
}
use of java.awt.datatransfer.UnsupportedFlavorException in project tetrad by cmu-phil.
the class SubsessionSelection method getTransferData.
/**
* @return an object which represents the data to be transferred. The class
* of the object returned is defined by the representation class of the
* flavor.
*
* @param flavor the requested flavor for the data
* @throws IOException if the data is no longer available in
* the requested flavor.
* @throws UnsupportedFlavorException if the requested data flavor is not
* supported.
* @see DataFlavor#getRepresentationClass
*/
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
try {
List returnList = (List) new MarshalledObject(sessionElements).get();
Point point = EditorUtils.getTopLeftPoint(returnList);
point.translate(50, 50);
// List returnList = this.sessionElements;
// this.sessionElements = null;
numPastes++;
return returnList;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project blue by kunstmusik.
the class CodeRepositoryDropTarget method drop.
@Override
public void drop(DropTargetDropEvent dtde) {
Point pt = dtde.getLocation();
DropTargetContext dtc = dtde.getDropTargetContext();
JTree tree = (JTree) dtc.getComponent();
TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();
ElementHolder elem = (ElementHolder) parent.getUserObject();
if (!elem.isGroup) {
dtde.rejectDrop();
return;
}
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
if (tr.isDataFlavorSupported(flavors[i])) {
dtde.acceptDrop(dtde.getDropAction());
TreePath p = (TreePath) tr.getTransferData(flavors[i]);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.insertNodeInto(node, parent, 0);
dtde.dropComplete(true);
return;
}
}
dtde.rejectDrop();
} catch (UnsupportedFlavorException | IOException e) {
e.printStackTrace();
dtde.rejectDrop();
}
}
Aggregations