net.alantea.swing.graph.GraphTransferHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swingplus Show documentation
Show all versions of swingplus Show documentation
Addons over swing package.
The newest version!
package net.alantea.swing.graph;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import javax.swing.TransferHandler;
import javax.swing.tree.DefaultMutableTreeNode;
import net.alantea.swing.tree.TreeTransferHandler;
@SuppressWarnings("serial")
public abstract class GraphTransferHandler extends TransferHandler
{
public boolean canImport(TransferHandler.TransferSupport support)
{
for (DataFlavor flavor : support.getDataFlavors()) {
if (flavor.isMimeTypeEqual(TreeTransferHandler.mimeType)) {
return true;
}
}
return false;
}
public boolean importData(TransferHandler.TransferSupport support) {
if(!canImport(support)) {
return false;
}
Transferable t = support.getTransferable();
try
{
Object data = t.getTransferData(new DataFlavor(TreeTransferHandler.mimeType));
Object[] objects = (Object[]) data;
Object object = objects[0];
if (object instanceof DefaultMutableTreeNode)
{
return doImportData(((DefaultMutableTreeNode)object).getUserObject(), support);
}
}
catch (ClassNotFoundException | UnsupportedFlavorException | IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
protected abstract boolean doImportData(Object data, TransferHandler.TransferSupport support);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy