use of java.awt.datatransfer.UnsupportedFlavorException in project blue by kunstmusik.
the class InstrumentTreeDropTarget 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);
Object node = parentpath.getLastPathComponent();
if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_CAT_FLAVOR)) {
if (!(node instanceof InstrumentCategory)) {
dtde.rejectDrop();
return;
}
if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
dtde.acceptDrop(dtde.getDropAction());
Transferable tr = dtde.getTransferable();
try {
Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_CAT_FLAVOR);
InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
InstrumentCategory parentNode = (InstrumentCategory) node;
InstrumentCategory instrumentCategory = (InstrumentCategory) transferNode;
// iLibrary.removeCategory(instrumentCategory);
iLibrary.addCategory(parentNode, instrumentCategory);
dtde.dropComplete(true);
} catch (UnsupportedFlavorException | IOException e) {
dtde.dropComplete(false);
}
} else {
dtde.rejectDrop();
}
} else if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_FLAVOR)) {
dtde.acceptDrop(dtde.getDropAction());
try {
Transferable tr = dtde.getTransferable();
Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_FLAVOR);
Instrument instrument = (Instrument) transferNode;
InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
if (instrument instanceof BlueSynthBuilder) {
((BlueSynthBuilder) instrument).clearParameters();
}
// iLibrary.removeInstrument(instrument);
if (node instanceof InstrumentCategory) {
InstrumentCategory parentNode = (InstrumentCategory) node;
iLibrary.addInstrument(parentNode, instrument);
} else if (node instanceof Instrument) {
InstrumentCategory parentNode = (InstrumentCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
int index = ListUtil.indexOfByRef(parentNode.getInstruments(), node);
int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
Rectangle bounds = tree.getRowBounds(closestRow);
if (pt.y > bounds.y + bounds.height) {
iLibrary.addInstrument(parentNode, instrument);
} else {
iLibrary.addInstrument(parentNode, index, instrument);
}
}
dtde.dropComplete(true);
} catch (UnsupportedFlavorException | IOException e) {
dtde.dropComplete(false);
}
} else {
dtde.rejectDrop();
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project AndrOBD by fr3ts0n.
the class PvTransferHandler method exportDone.
/* (non-Javadoc)
* @see javax.swing.TransferHandler#exportDone(javax.swing.JComponent, java.awt.datatransfer.Transferable, int)
*/
@Override
protected void exportDone(JComponent c, Transferable t, int action) {
try {
if (action == MOVE) {
ProcessVar pv = (ProcessVar) t.getTransferData(processVarFlavor);
pv.firePvChanged(new PvChangeEvent(pv, pv.getKeyAttribute(), pv, PvChangeEvent.PV_ELIMINATED));
}
} catch (UnsupportedFlavorException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
} catch (IOException e) {
ProcessVar.log.severe(this.toString() + ":" + e.getMessage());
}
}
use of java.awt.datatransfer.UnsupportedFlavorException in project gephi by gephi.
the class DragNDropFrameAdapter method register.
public static void register() {
JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
frame.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return false;
}
// Impossible to get data here and look if compatible format
return true;
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
try {
List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
File file = (File) data.get(0);
FileObject fileObject = FileUtil.toFileObject(file);
if (!file.exists()) {
return false;
}
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ew) {
Exceptions.printStackTrace(ew);
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
importController.importFile(fileObject);
} else {
return false;
}
}
return true;
} catch (UnsupportedFlavorException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return false;
}
});
}
use of java.awt.datatransfer.UnsupportedFlavorException in project gephi by gephi.
the class SlotNode method getDropType.
@Override
public PasteType getDropType(final Transferable t, int action, int index) {
final Node dropNode = NodeTransfer.node(t, DnDConstants.ACTION_COPY_OR_MOVE);
if (dropNode != null && dropNode instanceof QueryNode) {
Query q = ((QueryNode) dropNode).getQuery();
if (!Arrays.asList(q.getDescendantsAndSelf()).contains(parent)) {
// Check if not parent
return new PasteType() {
@Override
public Transferable paste() throws IOException {
QueryNode queryNode = (QueryNode) dropNode;
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
filterController.setSubQuery(parent, queryNode.getQuery());
return null;
}
};
}
} else if (t.isDataFlavorSupported(FilterBuilderNode.DATA_FLAVOR)) {
return new PasteType() {
@Override
public Transferable paste() throws IOException {
try {
FilterBuilder builder = (FilterBuilder) t.getTransferData(FilterBuilderNode.DATA_FLAVOR);
FilterController filterController = Lookup.getDefault().lookup(FilterController.class);
Query query = filterController.createQuery(builder);
filterController.setSubQuery(parent, query);
} catch (UnsupportedFlavorException ex) {
Exceptions.printStackTrace(ex);
}
return null;
}
};
}
return null;
}
use of java.awt.datatransfer.UnsupportedFlavorException in project pivot by apache.
the class LocalManifestAdapter method getTransferData.
@Override
public Object getTransferData(DataFlavor dataFlavor) throws UnsupportedFlavorException {
Object transferData = null;
int index = transferDataFlavors.indexOf(dataFlavor);
if (index == -1) {
throw new UnsupportedFlavorException(dataFlavor);
}
if (dataFlavor.equals(DataFlavor.stringFlavor)) {
transferData = localManifest.getText();
} else if (dataFlavor.equals(DataFlavor.imageFlavor)) {
Picture picture = (Picture) localManifest.getImage();
transferData = picture.getBufferedImage();
} else if (dataFlavor.equals(DataFlavor.javaFileListFlavor)) {
FileList fileList = localManifest.getFileList();
transferData = fileList.getList();
} else if (dataFlavor.getMimeType().equals(URI_LIST_MIME_TYPE)) {
FileList fileList = localManifest.getFileList();
StringBuilder buf = new StringBuilder();
for (File file : fileList) {
buf.append(file.toURI().toString()).append("\r\n");
}
transferData = buf.toString();
}
return transferData;
}
Aggregations