@Override
 public boolean importData(TransferSupport support) {
   DataFlavor f = getStringFlavor(support.getDataFlavors());
   Object drop = null;
   String s = null;
   if (f != null) {
     try {
       drop = support.getTransferable().getTransferData(f);
     } catch (UnsupportedFlavorException e) {
       Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$
     } catch (IOException e) {
       Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$
     }
   } else {
     try {
       drop = support.getTransferable().getTransferData(DataFlavor.stringFlavor);
     } catch (UnsupportedFlavorException e) {
       Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$
     } catch (IOException e) {
       Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$
     }
   }
   if (drop != null) {
     s = String.valueOf(drop);
   }
   if (s != null) {
     return importString(s, support);
   }
   return false;
 }
 /** Move a block it's prior location to the drop location */
 @Override
 public boolean importData(TransferSupport supp) {
   if (canImport(supp)) {
     IconList list = (IconList) supp.getComponent().getParent().getParent().getParent();
     JViewport panel = (JViewport) supp.getComponent().getParent();
     try {
       Transferable t = supp.getTransferable();
       int from = (int) t.getTransferData(DataFlavor.imageFlavor);
       list.move(
           from,
           (int)
               (Math.ceil(
                   supp.getDropLocation().getDropPoint().getX()
                           * list.length()
                           / panel.getViewSize().getWidth()
                       - 1)),
           false);
     } catch (Exception e) {
       e.printStackTrace();
       return false;
     }
     return true;
   }
   return false;
 }
  @Override
  public boolean importData(TransferSupport support) {
    if (!isDataFlavorValid(support)) return false;

    DropLocation dl = support.getDropLocation();
    if (!(dl instanceof JTree.DropLocation)) return false;
    dropLocation = (JTree.DropLocation) dl;

    Transferable transferable = support.getTransferable();
    if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      try {
        LayerTreeModel model = layersTree.getLayerModel();

        List<?> files = (List<?>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
        int i = 0;
        for (Object o : files) {
          if (o instanceof File) {
            File file = (File) o;
            URL url = file.toURI().toURL();
            ILayerDefinition definition =
                new LayerDefinition(file.getName(), url, null, Icons.file.getURL(), true, false);
            INode node = LayerNode.createFromLayerDefinition(definition);
            addNodeToTree(dropLocation, model, node, false, i++);
          }
        }

        layersTree.getUI().relayout();
        dropLocation = null;
      } catch (Exception e) {
        return false;
      }
    }

    return true;
  }
    @Override
    @SuppressWarnings("unchecked")
    public boolean importData(TransferSupport support) {
      if (!this.canImport(support)) return false;

      if (support.getComponent() == mTextArea && mTextHandler.importData(support)) {
        // dropping text on text area was handled
        return true;
      }

      List<File> files;
      try {
        files =
            (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
      } catch (UnsupportedFlavorException | IOException ex) {
        // should never happen (or JDK is buggy)
        return false;
      }

      for (File file : files) {
        if (Utils.isAllowedAttachmentFile(file)) {
          mChatView.sendFile(file);
        }
      }
      return !files.isEmpty();
    }
Esempio n. 5
0
  /* (non-Javadoc)
   * @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport)
   */
  @Override
  public boolean importData(TransferSupport support) {
    try {
      if (support.getComponent() instanceof JTree) {
        JTree tree = (JTree) support.getComponent();
        Point dropPoint = support.getDropLocation().getDropPoint();
        TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y);
        Object node = path.getLastPathComponent();
        if (support.isDataFlavorSupported(ProcessVar.PvDataFlavors[0])) {
          ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject();
          ProcessVar chldPv =
              (ProcessVar) support.getTransferable().getTransferData(ProcessVar.PvDataFlavors[0]);

          Object chldKey = chldPv.getKeyValue();
          tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED);
          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
          model.nodeStructureChanged((TreeNode) model.getRoot());
          return true;
        }
      }
    } catch (UnsupportedFlavorException e) {
      ProcessVar.log.error(this.toString() + ":" + e.getMessage());
    } catch (IOException e) {
      ProcessVar.log.error(this.toString() + ":" + e.getMessage());
    }
    // anything else is handled by superclass
    return super.importData(support);
  }
 /**
  * Imports the drop data by going over the list of supported callbacks. This method will return
  * true if a callback could be found that could successfully import the drop data, or false
  * otherwise.
  *
  * @param support The TransferSupport describing the drop event.
  * @return true if a callback could be found that could successfully import the drop data, or
  *     false otherwise.
  */
 @Override
 public boolean importData(final TransferSupport support) {
   try {
     final DataFlavor[] flavors = support.getDataFlavors();
     for (DataFlavor flavor : flavors) {
       final LinkedList<DropHandlerCallback> callbacks = _callbackMapping.get(flavor);
       if (callbacks == null) continue;
       final Object data = support.getTransferable().getTransferData(flavor);
       for (DropHandlerCallback callback : callbacks)
         if (callback.importData(support.getComponent(), data)) return true;
     }
   } catch (Exception e) {
     return false;
   }
   return false;
 }
    public boolean importData(TransferSupport support) {
      if (!canImport(support)) {
        return false;
      }

      Transferable transferable = support.getTransferable();
      try {
        Object draggedImage = transferable.getTransferData(DATA_FLAVOUR);

        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
        DefaultListModel model = (DefaultListModel) playlist.getModel();
        int dropIndex = dl.getIndex();
        if (model.indexOf(draggedImage) < dropIndex) {
          dropIndex--;
        }
        model.removeElement(draggedImage);
        model.add(dropIndex, draggedImage);
        callback.notify(Command.NEW_QUEUE, Arrays.asList(model.toArray()), gui.getCurrentZone());
        return true;
      } catch (Exception e) {
        e.printStackTrace();
        return false;
      }
    }