All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.alantea.swing.graph.GraphTransferHandler Maven / Gradle / Ivy

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