/** 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;
  }
Esempio n. 3
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);
  }
    public boolean canImport(TransferSupport support) {
      if (!inDrag || !support.isDataFlavorSupported(DATA_FLAVOUR)) {
        return false;
      }

      JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
      if (dl.getIndex() == -1) {
        return false;
      } else {
        return true;
      }
    }
    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;
      }
    }