예제 #1
0
  /**
   * Imports data flavors and returns a true or false if the flavor is flavored or not
   *
   * @return Boolean
   */
  public boolean canImport(TransferHandler.TransferSupport info) {
    // we only import Strings
    if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      return false;
    }

    JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
    if (dl.getIndex() == -1) {
      return false;
    }
    return true;
  }
    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;
      }
    }
예제 #3
0
  /**
   * Imports data if the specific flavor is supported
   *
   * @return Boolean
   */
  public boolean importData(TransferHandler.TransferSupport info) {
    if (!info.isDrop()) {
      return false;
    }

    // Check for String flavor
    if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
      System.out.println("Data flavor not supported.");
      return false;
    }

    JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
    DefaultListModel listModel = (DefaultListModel) list.getModel();
    int index = dl.getIndex();
    boolean insert = dl.isInsert();
    // Get the current string under the drop.
    // String value = (String)listModel.getElementAt(index);

    // Get the string that is being dropped.
    Transferable t = info.getTransferable();
    String data;
    try {
      data = (String) t.getTransferData(DataFlavor.stringFlavor);
    } catch (Exception e) {
      return false;
    }

    /**
     * This is commented out for the basicdemo.html tutorial page. * If you add this code snippet
     * back and delete the * "return false;" line, the list will accept drops * of type string.
     */
    // Perform the actual import.
    if (insert) {
      listModel.add(index, data);
    } else {
      listModel.set(index, data);
    }
    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;
      }
    }