public final void drop(DropTargetDropEvent dtde) {
    try {
      if (drawImage) {
        clearImage();
      }
      int action = dtde.getDropAction();

      Transferable transferable = dtde.getTransferable();
      Point pt = dtde.getLocation();
      if (transferable.isDataFlavorSupported(TransferableNode.NODE_FLAVOR)
          && canPerformAction(tree, draggedPath, action, pt)) {
        TreePath pathTarget = tree.getPathForLocation(pt.x, pt.y);
        TreePath node = (TreePath) transferable.getTransferData(TransferableNode.NODE_FLAVOR);
        if (executeDrop(tree, node, pathTarget, action)) {
          dtde.acceptDrop(action);
          dtde.dropComplete(true);
          return;
        }
      }
      dtde.rejectDrop();
      dtde.dropComplete(false);
    } catch (Exception e) {
      System.out.println(e);
      dtde.rejectDrop();
      dtde.dropComplete(false);
    }
  }
Ejemplo n.º 2
0
  public void drop(final DropTargetDropEvent dtde) {
    if (dragHandler == null) {
      dtde.rejectDrop();
      return;
    }
    try {
      if (ElementMetaDataTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final ElementMetaData metaData = (ElementMetaData) getTransferData();
        dragHandler.drop(dtde, editorContext, metaData, null);
        return;
      }

      if (FieldDescriptionTransferable.ELEMENT_FLAVOR.equals(getFlavor())) {
        final String fieldName = (String) getTransferData();
        final ElementMetaData metaData = createMetaData(fieldName);
        dragHandler.drop(dtde, editorContext, metaData, fieldName);
        return;
      }
      dtde.rejectDrop();
    } finally {
      editorContext.getRepresentationContainer().revalidate();
      editorContext.getRepresentationContainer().repaint();
      dragHandler = null;
    }
  }
  @SuppressWarnings("rawtypes")
  public void drop(DropTargetDropEvent dtde) {
    try {
      Transferable tr = dtde.getTransferable();
      if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        List files = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);

        this.txtRawData.setText(((File) files.get(0)).getAbsolutePath());

        dtde.getDropTargetContext().dropComplete(true);
      } else {
        System.err.println("DataFlavor.javaFileListFlavor is not supported, rejected");
        dtde.rejectDrop();
      }
    } catch (IOException ex) {
      System.err.println("IOException");
      ex.printStackTrace();
      dtde.rejectDrop();
    } catch (UnsupportedFlavorException ex) {
      System.err.println("UnsupportedFlavorException");
      ex.printStackTrace();
      dtde.rejectDrop();
    }
  }
Ejemplo n.º 4
0
    @SuppressWarnings("unchecked")
    public void drop(DropTargetDropEvent event) {

      try {
        if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
          Transferable tr = event.getTransferable();
          int action = event.getDropAction();
          event.acceptDrop(action);

          java.util.List<File> files =
              (java.util.List<File>) tr.getTransferData(DataFlavor.javaFileListFlavor);
          for (File f : files) {
            JEXStatics.logManager.log("Copying file " + f, 1, this);
            String newDest = parent.folder.getPath() + File.separator + f.getName();
            FileUtility.copy(f, new File(newDest));
          }
          parent.rebuild();

          event.dropComplete(true);
          JEXStatics.logManager.log("Drop completed...", 1, this);

          return;
        }
        event.rejectDrop();
      } catch (Exception e) {
        e.printStackTrace();
        event.rejectDrop();
      }
    }
Ejemplo n.º 5
0
  public void drop(DropTargetDropEvent dtde) {
    // System.out.println("drop");
    // System.out.println(dtde.getDropAction());
    // System.out.println();
    // Check the drop action
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
      // Accept the drop and get the transfer data
      dtde.acceptDrop(dtde.getDropAction());
      Transferable transferable = dtde.getTransferable();

      try {
        boolean result = false;

        if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
          result = dropFile(transferable);
        } else {
          result = false;
        }
        dtde.dropComplete(result);

      } catch (Exception e) {
        System.out.println("Exception while handling drop " + e);
        dtde.rejectDrop();
      }
    } else {
      System.out.println("Drop target rejected drop");
      dtde.dropComplete(false);
    }
  }
Ejemplo n.º 6
0
  public void drop(DropTargetDropEvent dtde) {
    dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
    if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      try {
        content =
            (java.util.List) dtde.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
        repaint();
      } catch (UnsupportedFlavorException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
      dtde.dropComplete(true);

      boolean listsAreEqual = true;

      for (int i = 0; i < content.size(); i++) {
        if (!FileListTransferable.files[i].getName().equals(content.get(i).getName())) {
          listsAreEqual = false;
        }
      }

      if (listsAreEqual) {
        System.err.println(InterprocessMessages.EXECUTION_IS_SUCCESSFULL);
        System.exit(0);
      }
    }
    dtde.rejectDrop();
    System.err.println(InterprocessMessages.FILES_ON_TARGET_ARE_CORRUPTED);
    System.exit(1);
  }
Ejemplo n.º 7
0
  public void drop(DropTargetDropEvent dtde) {
    if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
      dtde.rejectDrop();
      return;
    }
    dtde.acceptDrop(DnDConstants.ACTION_COPY);
    Vector<RowContainer> oldvec = this.filevector;

    Transferable transferable = dtde.getTransferable();
    try {
      java.util.List<File> filelist =
          (java.util.List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
      for (File f : filelist) {
        filevector.add(new RowContainer(f));

        model.fireTableDataChanged();
        System.out.println(f.toString());
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (UnsupportedFlavorException ex) {
      ex.printStackTrace();
    }
    dtde.dropComplete(true);
    File[] filar = new File[filevector.size()];
    for (int i = 0; i < filevector.size(); i++) {
      filar[i] = filevector.get(i).getFile();
    }
    super.firePropertyChange("filevector", null, filar);
  }
Ejemplo n.º 8
0
    /**
     * The drag operation has terminated with a drop on this <code>DropTarget</code>. This method is
     * responsible for undertaking the transfer of the data associated with the gesture. The <code>
     * DropTargetDropEvent</code> provides a means to obtain a <code>Transferable</code> object that
     * represents the data object(s) to be transfered.
     *
     * <p>From this method, the <code>DropTargetListener</code> shall accept or reject the drop via
     * the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent
     * </code> parameter.
     *
     * <p>Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s
     * getTransferable() method may be invoked, and data transfer may be performed via the returned
     * <code>Transferable</code>'s getTransferData() method.
     *
     * <p>At the completion of a drop, an implementation of this method is required to signal the
     * success/failure of the drop by passing an appropriate <code>boolean</code> to the <code>
     * DropTargetDropEvent</code>'s dropComplete(boolean success) method.
     *
     * <p>Note: The actual processing of the data transfer is not required to finish before this
     * method returns. It may be deferred until later.
     *
     * <p>
     *
     * @param dtde the <code>DropTargetDropEvent</code>
     */
    @Override
    @SuppressWarnings("unchecked")
    public void drop(DropTargetDropEvent event) {
      if (event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
        event.acceptDrop(DnDConstants.ACTION_COPY);

        try {
          List<File> files =
              (List<File>) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);

          splitMPOFiles(files);

        } catch (IOException e) {
          JOptionPane.showConfirmDialog(
              MPOImageSplitter.this,
              "Could not access the dropped data.",
              "MPOImageSplitter: Drop Failed",
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.INFORMATION_MESSAGE);
        } catch (UnsupportedFlavorException e) {
          JOptionPane.showConfirmDialog(
              MPOImageSplitter.this,
              "Unsupported data flavor.",
              "MPOImageSplitter: Drop Failed",
              JOptionPane.DEFAULT_OPTION,
              JOptionPane.INFORMATION_MESSAGE);
        }
      } else {
        event.rejectDrop();
      }
    }
Ejemplo n.º 9
0
 public void drop(java.awt.dnd.DropTargetDropEvent dtde) {
   if (getParent() instanceof java.awt.dnd.DropTargetListener) {
     ((java.awt.dnd.DropTargetListener) getParent()).drop(dtde);
   } else {
     dtde.rejectDrop();
   }
 }
 public void drop(DropTargetDropEvent dtde) {
   if (draggingFiles != null) {
     dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
     fireActionPerformed(dtde);
     draggingFiles = null;
   } else {
     dtde.rejectDrop();
   }
 }
  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);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();

    try {
      // Transferable tr = dtde.getTransferable(); // !!! this should work, but doesn't. after one
      // click on the draggable node, this call here will not return the TransferableTreeNode that
      // is created in dragGestureRecognized()
      Transferable tr =
          ObjectInspector
              .transferNode; // therefore, we use this hack, which just stores the current
      // transferable in a static variable

      DataFlavor[] flavors = tr.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        if (tr.isDataFlavorSupported(flavors[i])) {
          dtde.acceptDrop(dtde.getDropAction());
          TreePath p = (TreePath) tr.getTransferData(flavors[i]);
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent();
          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();

          Object sourceObject = node.getUserObject();

          FieldWrapperObjectTree targetField = ((FieldWrapperObjectTree) parent.getUserObject());

          if (sourceObject != null) {
            if (sourceObject instanceof FieldWrapperObjectTree) {
              FieldWrapperObjectTree sourceField = (FieldWrapperObjectTree) sourceObject;

              if (sourceField.getTheField().getType().equals(targetField.getTheField().getType())) {
                targetField
                    .getTheField()
                    .set(
                        targetField.getOnObject(),
                        sourceField.getTheField().get(sourceField.getOnObject()));
              }
            } else if (sourceObject.getClass().equals(targetField.getTheField().getType())) {
              targetField.getTheField().set(targetField.getOnObject(), sourceObject);
            }

            tree.invalidate();
            tree.repaint();
          }

          dtde.dropComplete(true);
          return;
        }
      }
      dtde.rejectDrop();
    } catch (Exception e) {
      e.printStackTrace();
      // dtde.rejectDrop();
    }
  }
  public void drop(DropTargetDropEvent evt) {
    try {
      Transferable t = evt.getTransferable();

      if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
        evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);

        String s = (String) t.getTransferData(DataFlavor.stringFlavor);
        evt.getDropTargetContext().dropComplete(true);
        process(s);
      } else {
        evt.rejectDrop();
      }
    } catch (IOException e) {
      evt.rejectDrop();
    } catch (UnsupportedFlavorException e) {
      evt.rejectDrop();
    }
  }
  @Override
  public void drop(DropTargetDropEvent dtde) {
    if (dtde.isDataFlavorSupported(CardFlavor.cardFlavor) && this.canDrop) {
      Transferable trans = dtde.getTransferable();
      try {
        Object data = trans.getTransferData(CardFlavor.cardFlavor);
        CardWindow card = (CardWindow) data;
        DropTargetContext context = dtde.getDropTargetContext();
        CardCollection comp = (CardCollection) context.getComponent();
        Container parent = comp.getParent();
        GameController.getController(false)
            .makeMove(
                CardCollection.getMoveFromIndex(
                    comp.getCardMouseLocation(), new OrderedCard(card.card, card.cardLocation)));
        if (parent != null) parent.remove(card);
        comp.setCard(card, comp.getCardMouseLocation());
        dtde.acceptDrop(DnDConstants.ACTION_MOVE);
        comp.validate();
        comp.repaint();

        dtde.dropComplete(true);
      } catch (Exception e) {
        dtde.rejectDrop();
        dtde.dropComplete(false);
        JOptionPane.showMessageDialog(
            MainWindow.getMainWindow(),
            "Invalid move.",
            "Invalid Move Error",
            JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
      }
    } else {
      dtde.rejectDrop();
      dtde.dropComplete(false);
      JOptionPane.showMessageDialog(
          MainWindow.getMainWindow(),
          "Invalid move.",
          "Invalid Move Error",
          JOptionPane.ERROR_MESSAGE);
    }
  }
Ejemplo n.º 14
0
  public void drop(
      java.awt.dnd.DropTargetDropEvent evt) { // System.out.println( "DropTargetListener.drop" );
    java.awt.datatransfer.Transferable transferable = evt.getTransferable();

    // If it's our native TransferableObject, use that
    if (transferable.isDataFlavorSupported(TransferableObject.DATA_FLAVOR)) {
      evt.acceptDrop(java.awt.dnd.DnDConstants.ACTION_MOVE);
      Object obj = null;
      try {
        obj = transferable.getTransferData(TransferableObject.DATA_FLAVOR);
      } // end try
      catch (java.awt.datatransfer.UnsupportedFlavorException e) {
        e.printStackTrace();
      } // end catch
      catch (java.io.IOException e) {
        e.printStackTrace();
      } // end catch

      if (obj != null) {
        // See where in the list we dropped the element.
        int dropIndex = locationToIndex(evt.getLocation());
        javax.swing.DefaultListModel model = (javax.swing.DefaultListModel) getModel();

        if (dropIndex < 0) model.addElement(obj);

        // Else is it moving down the list?
        else if (sourceIndex >= 0 && dropIndex > sourceIndex) model.add(dropIndex - 1, obj);
        else model.add(dropIndex, obj);

      } // end if: we got the object

      // Else there was a problem getting the object
      else {
        evt.rejectDrop();
      } // end else: can't get the object
    } // end if: it's a native TransferableObject

    // Else we can't handle this
    else evt.rejectDrop();
  } // end drop
Ejemplo n.º 15
0
  @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);
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent();
    if (!parent.isLeaf()) {
      dtde.rejectDrop();
      return;
    }

    try {
      Transferable tr = dtde.getTransferable();
      DataFlavor[] flavors = tr.getTransferDataFlavors();
      for (int i = 0; i < flavors.length; i++) {
        if (tr.isDataFlavorSupported(flavors[i])) {
          dtde.acceptDrop(dtde.getDropAction());
          EMedium eMedium = (EMedium) tr.getTransferData(flavors[i]);
          TreeNodeUserData userData = (TreeNodeUserData) parent.getUserObject();
          String shelfName = userData.getCaption();
          if (isLibrarySelected(dtde)
              && shelfName.equals(AppProperties.INSTANCE.RENTALS_SHELF_NAME)) {
            if (!uiDelegate.addRentalEMedium(eMedium))
              JOptionPane.showMessageDialog(
                  frame, "Cannot rent e-medium!", "Add document error", JOptionPane.ERROR_MESSAGE);
          } else if (!isLibrarySelected(dtde)
              && !shelfName.equals(AppProperties.INSTANCE.RENTALS_SHELF_NAME)) {
            if (!uiDelegate.addEMediumShelf(shelfName, eMedium))
              JOptionPane.showMessageDialog(
                  frame, "Duplicated e-medium!", "Add document error", JOptionPane.ERROR_MESSAGE);
          } else
            JOptionPane.showMessageDialog(
                frame,
                "Need to rent the e-medium first!",
                "Add document error",
                JOptionPane.ERROR_MESSAGE);
          dtde.dropComplete(true);
          return;
        }
      }
      // dtde.rejectDrop();
    } catch (OperationNotSupportedException e) {
      JOptionPane.showMessageDialog(
          frame,
          "Cannot add a document to this shelf",
          "Add document error",
          JOptionPane.ERROR_MESSAGE);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 16
0
	/**
	 * 当拖动系统中的文件放置drop到该List中时,调用此方法。
	 */
	public synchronized void drop(DropTargetDropEvent dropTargetDropEvent) {
		System.out
				.println("method: drop(DropTargetDropEvent dropTargetDropEvent)");
		try {
			// 获取传入的Transfer对象
			Transferable tr = dropTargetDropEvent.getTransferable();
			// 如果Transfer对象支持文件放置到java平台,则进行下一步处理
			if (tr.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
				// 使用“拷贝、移动”方式接收放置操作。
				dropTargetDropEvent
						.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
				// 从Transfer中取数据,得到的是一个文件列表。即可以一次拖放多个文件
				java.util.List fileList = (java.util.List) tr
						.getTransferData(DataFlavor.javaFileListFlavor);
				Iterator iterator = fileList.iterator();
				while (iterator.hasNext()) {
					// 将拖放进来的文件的信息添加到List的数据模型中
					File file = (File) iterator.next();
					Hashtable hashtable = new Hashtable();
					hashtable.put("name", file.getName());
					hashtable.put("url", file.toURL().toString());
					hashtable.put("path", file.getAbsolutePath());
					((DefaultListModel) getModel()).addElement(hashtable);
				}
				// 放置操作成功结束
				dropTargetDropEvent.getDropTargetContext().dropComplete(true);
			} else {
				// Transferable对象不支持文件放置到java中,拒绝。
				System.err.println("Rejected");
				dropTargetDropEvent.rejectDrop();
			}
		} catch (IOException io) {
			io.printStackTrace();
			dropTargetDropEvent.rejectDrop();
		} catch (UnsupportedFlavorException ufe) {
			ufe.printStackTrace();
			dropTargetDropEvent.rejectDrop();
		}
	}
  public final void drop(DropTargetDropEvent event) {
    IWorkspaceView view = WorkspaceController.getCurrentModeExtension().getView();
    if (view == null) {
      return;
    }

    TreePath targetPath = view.getPathForLocation(event.getLocation().x, event.getLocation().y);
    if (targetPath != null) {
      AWorkspaceTreeNode targetNode = (AWorkspaceTreeNode) targetPath.getLastPathComponent();
      if (processDrop(targetNode, event)) {
        return;
      }
    }
    event.rejectDrop();
  }
Ejemplo n.º 18
0
    public void drop(DropTargetDropEvent event) {
      if (!isDropAcceptable(event)) {
        event.rejectDrop();
        return;
      }

      event.acceptDrop(DnDConstants.ACTION_COPY);

      Transferable transferable = event.getTransferable();

      MessageCollection messages = new MessageCollection();
      try {
        List<File> files = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);

        for (File file : files) {
          try {
            ResourceLocator locator = new ResourceLocator(file.getAbsolutePath());
            IGV.getInstance().load(locator, panel);
          } catch (DataLoadException de) {
            messages.append(de.getMessage());
          }
        }
        String obj = transferable.getTransferData(DataFlavor.stringFlavor).toString();
        if (HttpUtils.isRemoteURL(obj)) {
          IGV.getInstance().load(new ResourceLocator(obj), panel);
        }
        if (messages != null && !messages.isEmpty()) {
          log.error(messages.getFormattedMessage());
          MessageUtils.showMessage(messages.getFormattedMessage());
        }
      } catch (Exception e) {
        String obj = null;
        try {
          obj = transferable.getTransferData(DataFlavor.stringFlavor).toString();
          if (HttpUtils.isRemoteURL(obj)) {
            IGV.getInstance().load(new ResourceLocator(obj), panel);
          }
        } catch (Exception e1) {
          log.error(e1);
          if (messages != null && !messages.isEmpty()) {
            MessageUtils.showMessage(messages.getFormattedMessage());
          }
        }
      }
      IGV.getMainFrame().repaint();
      event.dropComplete(true);
    }
 public void drop(DropTargetDropEvent event) {
   if (!event.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
     event.rejectDrop();
     return;
   }
   event.acceptDrop(event.getDropAction());
   try {
     List<File> data =
         (List<File>) event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
     Vector<String> pages = this.model.addWikiPages((File[]) data.toArray());
     JList pagelist = new JList(pages);
     this.updateUI(this.ui, pagelist);
     event.dropComplete(true);
   } catch (Exception e) {
     event.dropComplete(false);
     log.error("Failed to accept drag n drop", e);
   }
   highlightUI(false);
 }
 public void drop(DropTargetDropEvent dropTargetDropEvent) {
   DropData dropData = convertEventIntoDropData(dropTargetDropEvent);
   if (null == dropData) {
     dropTargetDropEvent.rejectDrop();
   } else {
     int dropAction = dropTargetDropEvent.getDropAction();
     if (DnDConstants.ACTION_MOVE == dropAction) {
       _widget.removeEntry(dropData.whatToDrop);
       processDrop(dropData, dropTargetDropEvent);
     }
     if (DnDConstants.ACTION_COPY == dropAction) {
       dropData.whatToDrop =
           RecursiveCopy.recursivelyCopyInstance(
               dropData.whatToDrop, Constants.RECURSIVE_COPY_DEPTH_FOR_DND);
       processDrop(dropData, dropTargetDropEvent);
     }
   }
   _widget.setIsCurrentlyDragging(false);
   return;
 }
Ejemplo n.º 21
0
 @Override
 public void drop(DropTargetDropEvent dtde) {
   try {
     if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
       dtde.acceptDrop(DnDConstants.ACTION_COPY);
       Transferable t = dtde.getTransferable();
       List list = (List) t.getTransferData(DataFlavor.javaFileListFlavor);
       for (Object o : list) {
         if (o instanceof File) {
           File f = (File) o;
           System.out.println(f.getAbsolutePath());
         }
       }
       dtde.dropComplete(true);
       return;
     }
   } catch (UnsupportedFlavorException | IOException ex) {
     ex.printStackTrace();
   }
   dtde.rejectDrop();
 }
Ejemplo n.º 22
0
    /*
     * (non-Javadoc)
     *
     * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
     */
    public void drop(DropTargetDropEvent e) {
      if (dragSource != null) {
        e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
        Point p = e.getLocation();
        int targetRow = rowAtPoint(p);

        Object edge =
            graph.insertEdge(
                null,
                null,
                null,
                dragSource.cell,
                JTableRenderer.this.cell,
                "sourceRow=" + sourceRow + ";targetRow=" + targetRow);
        graph.setSelectionCell(edge);

        // System.out.println("clearing drag source");
        dragSource = null;
        e.dropComplete(true);
      } else {
        e.rejectDrop();
      }
    }
  /**
   * The drag operation has terminated with a drop on this DropTarget. Be nice to somehow
   * incorporate FigureTransferCommand here.
   */
  public void drop(java.awt.dnd.DropTargetDropEvent dtde) {
    System.out.println("DropTargetDropEvent-drop");

    if (dtde.isDataFlavorSupported(DNDFiguresTransferable.DNDFiguresFlavor) == true) {
      log("DNDFiguresFlavor");
      if ((dtde.getDropAction() & DnDConstants.ACTION_COPY_OR_MOVE) != 0) {
        log("copy or move");
        if (dtde.isLocalTransfer() == false) {
          System.err.println("Intra-JVM Transfers not implemented for figures yet.");
          dtde.rejectDrop();
          return;
        }
        dtde.acceptDrop(dtde.getDropAction());
        try {
            /* protection from a malicious dropped object */
          setTargetUndoActivity(createTargetUndoActivity(view()));
          DNDFigures ff =
              (DNDFigures)
                  DNDHelper.processReceivedData(
                      DNDFiguresTransferable.DNDFiguresFlavor, dtde.getTransferable());
          getTargetUndoActivity().setAffectedFigures(ff.getFigures());
          Point theO = ff.getOrigin();
          view().clearSelection();
          Point newP = dtde.getLocation();
          /**
           * origin is where the figure thinks it is now newP is where the mouse is now. we move the
           * figure to where the mouse is with this equation
           */
          int dx = newP.x - theO.x; /* distance the mouse has moved */
          int dy = newP.y - theO.y; /* distance the mouse has moved */
          log("mouse at " + newP);
          FigureEnumeration fe =
              view().insertFigures(getTargetUndoActivity().getAffectedFigures(), dx, dy, false);
          getTargetUndoActivity().setAffectedFigures(fe);

          if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            view().addToSelectionAll(getTargetUndoActivity().getAffectedFigures());
          }

          view().checkDamage();
          editor().getUndoManager().pushUndo(getTargetUndoActivity());
          editor().getUndoManager().clearRedos();
          // update menus
          editor().figureSelectionChanged(view());
          dtde.dropComplete(true);
        } catch (NullPointerException npe) {
          npe.printStackTrace();
          dtde.dropComplete(false);
        }
      } else {
        dtde.rejectDrop();
      }
    } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      log("String flavor dropped.");
      dtde.acceptDrop(dtde.getDropAction());
      Object o = DNDHelper.processReceivedData(DataFlavor.stringFlavor, dtde.getTransferable());
      if (o != null) {
        log("Received string flavored data.");
        dtde.getDropTargetContext().dropComplete(true);
      } else {
        dtde.getDropTargetContext().dropComplete(false);
      }
    } else if (dtde.isDataFlavorSupported(DNDHelper.ASCIIFlavor) == true) {
      log("ASCII Flavor dropped.");
      dtde.acceptDrop(DnDConstants.ACTION_COPY);
      Object o = DNDHelper.processReceivedData(DNDHelper.ASCIIFlavor, dtde.getTransferable());
      if (o != null) {
        log("Received ASCII Flavored data.");
        dtde.getDropTargetContext().dropComplete(true);
        // System.out.println(o);
      } else {
        dtde.getDropTargetContext().dropComplete(false);
      }
    } else if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      log("Java File List Flavor dropped.");
      dtde.acceptDrop(DnDConstants.ACTION_COPY);
      File[] fList =
          (File[])
              DNDHelper.processReceivedData(DataFlavor.javaFileListFlavor, dtde.getTransferable());
      if (fList != null) {
        log("Got list of files.");
        for (int x = 0; x < fList.length; x++) {
          System.out.println(fList[x].getAbsolutePath());
        }
        dtde.getDropTargetContext().dropComplete(true);
      } else {
        dtde.getDropTargetContext().dropComplete(false);
      }
    }
    fLastX = 0;
    fLastY = 0;
  }
Ejemplo n.º 24
0
  @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(TransferableUDO.UDO_CAT_FLAVOR)) {
      if (!(node instanceof UDOCategory)) {
        dtde.rejectDrop();
        return;
      }

      if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
        dtde.acceptDrop(dtde.getDropAction());

        Transferable tr = dtde.getTransferable();
        try {
          Object transferNode = tr.getTransferData(TransferableUDO.UDO_CAT_FLAVOR);

          UDOCategory udoCategory = (UDOCategory) transferNode;
          UDOCategory parentNode = (UDOCategory) node;

          UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();

          udoLibrary.addCategory(parentNode, udoCategory);

          dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
          dtde.dropComplete(false);
        }
      } else {
        dtde.rejectDrop();
      }

    } else if (dtde.isDataFlavorSupported(TransferableUDO.UDO_FLAVOR)) {
      dtde.acceptDrop(dtde.getDropAction());

      try {
        Transferable tr = dtde.getTransferable();

        Object transferNode = tr.getTransferData(TransferableUDO.UDO_FLAVOR);

        UserDefinedOpcode udo = (UserDefinedOpcode) transferNode;
        UDOLibrary udoLibrary = (UDOLibrary) tree.getModel();

        // iLibrary.removeInstrument(instrument);
        if (node instanceof UDOCategory) {
          UDOCategory parentNode = (UDOCategory) node;

          udoLibrary.addUDO(parentNode, udo);
        } else if (node instanceof UserDefinedOpcode) {
          UDOCategory parentNode =
              (UDOCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);

          int index = ListUtil.indexOfByRef(parentNode.getUserDefinedOpcodes(), node);

          int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);

          Rectangle bounds = tree.getRowBounds(closestRow);

          if (pt.y > bounds.y + bounds.height) {
            udoLibrary.addUDO(parentNode, udo);
          } else {
            udoLibrary.addUDO(parentNode, index, udo);
          }
        }

        dtde.dropComplete(true);
      } catch (UnsupportedFlavorException | IOException e) {
        dtde.dropComplete(false);
      }
    } else {
      dtde.rejectDrop();
    }
  }
Ejemplo n.º 25
0
    public void drop(DropTargetDropEvent dtde) {
      if (!isAcceptable(dtde.getTransferable(), dtde.getLocation())) {
        dtde.rejectDrop();
      } else {
        try {
          Transferable transferable = dtde.getTransferable();
          Object transferData =
              transferable.getTransferData(transferable.getTransferDataFlavors()[0]);
          if (transferData instanceof PropertyModelItem) {
            dtde.acceptDrop(dtde.getDropAction());
            PropertyModelItem modelItem = (PropertyModelItem) transferData;

            String xpath = modelItem.getXPath();
            if (xpath == null && XmlUtils.seemsToBeXml(modelItem.getProperty().getValue())) {
              xpath =
                  UISupport.selectXPath(
                      "Create PropertyExpansion",
                      "Select XPath below",
                      modelItem.getProperty().getValue(),
                      null);

              if (xpath != null) {
                xpath =
                    PropertyExpansionUtils.shortenXPathForPropertyExpansion(
                        xpath, modelItem.getProperty().getValue());
              }
            }

            PropertyExpansion propertyExpansion =
                new PropertyExpansionImpl(modelItem.getProperty(), xpath);

            Point point = dtde.getLocation();
            int column = getPropertiesTable().columnAtPoint(point);
            int row = getPropertiesTable().rowAtPoint(point);

            if (row == -1) {
              if (holder instanceof MutableTestPropertyHolder) {
                MutableTestPropertyHolder mtph = (MutableTestPropertyHolder) holder;
                String name =
                    UISupport.prompt(
                        "Specify unique name of property",
                        "Add Property",
                        modelItem.getProperty().getName());
                while (name != null && mtph.hasProperty(name)) {
                  name =
                      UISupport.prompt(
                          "Specify unique name of property",
                          "Add Property",
                          modelItem.getProperty().getName());
                }

                if (name != null) {
                  mtph.addProperty(name).setValue(propertyExpansion.toString());
                }
              }
            } else {
              getPropertiesTable().setValueAt(propertyExpansion.toString(), row, column);
            }

            dtde.dropComplete(true);
          }
        } catch (Exception e) {
          SoapUI.logError(e);
        }
      }
    }
Ejemplo n.º 26
0
  @SuppressWarnings("unchecked")
  public void drop(DropTargetDropEvent dtde) {
    Logger.debug("Drop detected...");
    Transferable t = dtde.getTransferable();
    boolean isAccepted = false;
    if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
      while (true) {
        Object o = null;
        try {
          dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
          o = t.getTransferData(DataFlavor.javaFileListFlavor);
          isAccepted = true;
        } catch (Exception e) {
          Logger.error("transfer failed");
        }
        // if o is still null we had an exception
        if (o instanceof List) {
          List<File> fileList = (List<File>) o;
          final int length = fileList.size();
          if (length == 1) {
            String fileName = fileList.get(0).getAbsolutePath().trim();
            if (fileName.endsWith(".bmp")) break; // try another flavor -- Mozilla bug
            dtde.getDropTargetContext().dropComplete(true);
            loadFile(fileName);
            return;
          }
          dtde.getDropTargetContext().dropComplete(true);
          loadFiles(fileList);
          return;
        }
        break;
      }
    }

    Logger.debug("browsing supported flavours to find something useful...");
    DataFlavor[] df = t.getTransferDataFlavors();

    if (df == null || df.length == 0) return;
    for (int i = 0; i < df.length; ++i) {
      DataFlavor flavor = df[i];
      Object o = null;
      if (true) {
        Logger.info("df " + i + " flavor " + flavor);
        Logger.info("  class: " + flavor.getRepresentationClass().getName());
        Logger.info("  mime : " + flavor.getMimeType());
      }

      if (flavor.getMimeType().startsWith("text/uri-list")
          && flavor.getRepresentationClass().getName().equals("java.lang.String")) {

        /*
         * This is one of the (many) flavors that KDE provides: df 2 flavour
         * java.awt.datatransfer.DataFlavor[mimetype=text/uri-list;
         * representationclass=java.lang.String] java.lang.String String: file
         * :/home/egonw/data/Projects/SourceForge/Jmol/Jmol-HEAD/samples/
         * cml/methanol2.cml
         *
         * A later KDE version gave me the following. Note the mime!! hence the
         * startsWith above
         *
         * df 3 flavor java.awt.datatransfer.DataFlavor[mimetype=text/uri-list
         * ;representationclass=java.lang.String] class: java.lang.String mime :
         * text/uri-list; class=java.lang.String; charset=Unicode
         */

        try {
          o = null;
          if (!isAccepted) dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
          isAccepted = true;
          o = t.getTransferData(flavor);
        } catch (Exception e) {
          Logger.error(null, e);
        }

        if (o instanceof String) {
          if (Logger.debugging) {
            Logger.debug("  String: " + o.toString());
          }
          loadFile(o.toString());
          dtde.getDropTargetContext().dropComplete(true);
          return;
        }
      } else if (flavor
          .getMimeType()
          .equals("application/x-java-serialized-object; class=java.lang.String")) {

        /*
         * This is one of the flavors that jEdit provides:
         *
         * df 0 flavor java.awt.datatransfer.DataFlavor[mimetype=application/
         * x-java-serialized-object;representationclass=java.lang.String] class:
         * java.lang.String mime : application/x-java-serialized-object;
         * class=java.lang.String String: <molecule title="benzene.mol"
         * xmlns="http://www.xml-cml.org/schema/cml2/core"
         *
         * But KDE also provides:
         *
         * df 24 flavor java.awt.datatransfer.DataFlavor[mimetype=application
         * /x-java-serialized-object;representationclass=java.lang.String]
         * class: java.lang.String mime : application/x-java-serialized-object;
         * class=java.lang.String String: file:/home/egonw/Desktop/1PN8.pdb
         */

        try {
          o = null;
          if (!isAccepted) dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
          isAccepted = true;
          o = t.getTransferData(df[i]);
        } catch (Exception e) {
          Logger.error(null, e);
        }

        if (o instanceof String) {
          String content = (String) o;
          if (Logger.debugging) {
            Logger.debug("  String: " + content);
          }
          if (content.startsWith("file:/")) {
            loadFile(content);
          } else {
            PropertyChangeEvent pce =
                new PropertyChangeEvent(this, FD_PROPERTY_INLINE, fd_oldFileName, content);
            fd_propSupport.firePropertyChange(pce);
          }
          dtde.getDropTargetContext().dropComplete(true);
          return;
        }
      }
    }
    if (!isAccepted) dtde.rejectDrop();
  }
 /**
  * Called when the drag operation has terminated with a drop on the operable part of the drop site
  * for the <code>DropTarget</code> registered with this listener.
  *
  * <p>This method is responsible for undertaking the transfer of the data associated with the
  * gesture. The <code>DropTargetDropEvent</code> provides a means to obtain a <code>Transferable
  * </code> object that represents the data object(s) to be transfered.
  *
  * <p>From this method, the <code>DropTargetListener</code> shall accept or reject the drop via
  * the acceptDrop(int dropAction) or rejectDrop() methods of the <code>DropTargetDropEvent</code>
  * parameter.
  *
  * <p>Subsequent to acceptDrop(), but not before, <code>DropTargetDropEvent</code>'s
  * getTransferable() method may be invoked, and data transfer may be performed via the returned
  * <code>Transferable</code>'s getTransferData() method.
  *
  * <p>At the completion of a drop, an implementation of this method is required to signal the
  * success/failure of the drop by passing an appropriate <code>boolean</code> to the <code>
  * DropTargetDropEvent</code>'s dropComplete(boolean success) method.
  *
  * <p>Note: The data transfer should be completed before the call to the <code>DropTargetDropEvent
  * </code>'s dropComplete(boolean success) method. After that, a call to the getTransferData()
  * method of the <code>Transferable</code> returned by <code>DropTargetDropEvent.getTransferable()
  * </code> is guaranteed to succeed only if the data transfer is local; that is, only if <code>
  * DropTargetDropEvent.isLocalTransfer()</code> returns <code>true</code>. Otherwise, the behavior
  * of the call is implementation-dependent.
  *
  * <p>
  *
  * @param dtde the <code>DropTargetDropEvent</code>
  */
 public void drop(final DropTargetDropEvent dtde) {
   dtde.rejectDrop();
   transferData = null;
   position = null;
   flavor = null;
 }
Ejemplo n.º 28
0
  public void drop(DropTargetDropEvent dtde) {
    Transferable t = dtde.getTransferable();
    StringBuffer dropData = null;
    DataFlavor dtf;

    JConfig.log().logVerboseDebug("Dropping!");

    if (t.getTransferDataFlavors().length == 0) {
      Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
      Transferable t2 = sysClip.getContents(null);
      DataFlavor[] dfa2;
      int j;

      JConfig.log().logDebug("Dropped 0 data flavors, trying clipboard.");
      dfa2 = null;

      if (t2 != null) {
        JConfig.log().logVerboseDebug("t2 is not null: " + t2);
        dfa2 = t2.getTransferDataFlavors();
        JConfig.log().logVerboseDebug("Back from getTransferDataFlavors()!");
      } else {
        JConfig.log().logVerboseDebug("t2 is null!");
      }

      if (JConfig.queryConfiguration("debug.uber", "false").equals("true")) {
        if (dfa2 != null) {
          if (dfa2.length == 0) {
            JConfig.log().logVerboseDebug("Length is still zero!");
          }
          for (j = 0; j < dfa2.length; j++) {
            JConfig.log()
                .logVerboseDebug("Flavah " + j + " == " + dfa2[j].getHumanPresentableName());
            JConfig.log().logVerboseDebug("Flavah/mime " + j + " == " + dfa2[j].getMimeType());
          }
        } else {
          JConfig.log().logVerboseDebug("Flavahs supported: none!\n");
        }
      }
    }

    if (JConfig.queryConfiguration("debug.uber", "false").equals("true") && JConfig.debugging)
      dumpFlavorsOld(t);

    dtf = testAllFlavors(t);
    if (dtf != null) {
      JConfig.log().logVerboseDebug("Accepting!");
      acceptDrop(dtde);

      dropData = getTransferData(t);
      dtde.dropComplete(true);
      dtde.getDropTargetContext().dropComplete(true);
      if (dropData != null) {
        if (handler != null) {
          handler.receiveDropString(dropData);
        }
      }
    } else {
      JConfig.log().logVerboseDebug("Rejecting!");
      dtde.rejectDrop();
      handler.receiveDropString(dropData);
    }
  }
Ejemplo n.º 29
0
    public void drop(final DropTargetDropEvent e) {
      _timerHover.stop(); // Prevent hover timer from doing an unwanted expandPath or collapsePath

      if (!isDropAcceptable(e)) {
        e.rejectDrop();
        return;
      }

      e.acceptDrop(e.getDropAction());

      final Transferable transferable = e.getTransferable();

      final DataFlavor[] flavors = transferable.getTransferDataFlavors();

      for (int i = 0; i < flavors.length; i++) {
        final DataFlavor flavor = flavors[i];
        if (flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType)) {
          try {
            final Point pt = e.getLocation();
            final TreePath pathTarget = getClosestPathForLocation(pt.x, pt.y);
            final TreePath pathSource = (TreePath) transferable.getTransferData(flavor);

            if ((pathTarget == null) || (pathSource == null)) {
              e.dropComplete(false);
              return;
            }

            final MutableTreeNode sourceNode = (MutableTreeNode) pathSource.getLastPathComponent();
            final MutableTreeNode oldParent = (MutableTreeNode) sourceNode.getParent();

            final MutableTreeNode targetNode = (MutableTreeNode) pathTarget.getLastPathComponent();
            final MutableTreeNode newParent = (MutableTreeNode) targetNode.getParent();

            if (!sourceNode.isLeaf() && (targetNode.getParent() == sourceNode)) {
              // trying to drag a folder into its own childs
              e.dropComplete(false);
              return;
            }

            final DefaultTreeModel model = (DefaultTreeModel) getModel();
            final TreePath pathNewChild = null;

            if (targetNode.isLeaf() || JDragTree.this.isCollapsed(pathTarget)) {
              // collapsed tree node or leaf
              // dropped on a leaf, insert into leaf's parent AFTER leaf
              int idx = newParent.getIndex(targetNode);
              if (idx < 0) {
                JDragTree.logger.warning("child not found in parent!!!");
                e.dropComplete(false);
                return;
              } else {
                idx++; // insert AFTER targetNode

                // remove node from oldParent ...
                final Object[] removedChilds = {sourceNode};
                final int[] childIndices = {oldParent.getIndex(sourceNode)};
                sourceNode.removeFromParent();
                model.nodesWereRemoved(oldParent, childIndices, removedChilds);

                // ... and insert into newParent
                if (idx >= newParent.getChildCount()) {
                  // newParent.add( sourceNode );
                  newParent.insert(sourceNode, newParent.getChildCount());
                  final int insertedIndex[] = {newParent.getChildCount() - 1};
                  model.nodesWereInserted(newParent, insertedIndex);
                } else {
                  newParent.insert(sourceNode, idx);
                  final int insertedIndex[] = {idx};
                  model.nodesWereInserted(newParent, insertedIndex);
                }
              }
            } else {
              // expanded node, insert UNDER the node (before first child)
              // remove node from oldParent ...
              final Object[] removedChilds = {sourceNode};
              final int[] childIndices = {oldParent.getIndex(sourceNode)};
              sourceNode.removeFromParent();
              model.nodesWereRemoved(oldParent, childIndices, removedChilds);
              // ... and add to newParent
              targetNode.insert(sourceNode, 0);
              final int insertedIndex[] = {0};
              model.nodesWereInserted(targetNode, insertedIndex);
            }

            if (pathNewChild != null)
              setSelectionPath(pathNewChild); // Mark this as the selected path in the tree
            break; // No need to check remaining flavors
          } catch (final UnsupportedFlavorException ufe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ufe);
            e.dropComplete(false);
            return;
          } catch (final IOException ioe) {
            JDragTree.logger.log(
                Level.SEVERE, "Exception thrown in drop(DropTargetDropEvent e)", ioe);
            e.dropComplete(false);
            return;
          }
        }
      }
      e.dropComplete(true);
    }