示例#1
0
 @Override
 public boolean importData(TransferHandler.TransferSupport info) {
   JTable target = (JTable) info.getComponent();
   JTable.DropLocation dl = (JTable.DropLocation) info.getDropLocation();
   int rowTo = dl.getRow();
   int max = table.getModel().getRowCount();
   if ((rowTo < 0) || (rowTo > max)) {
     rowTo = max;
   }
   target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   try {
     Integer rowFrom = (Integer) info.getTransferable().getTransferData(localObjectFlavor);
     if (rowTo > rowFrom) {
       rowTo--;
     }
     if ((rowFrom != -1) && (rowFrom != rowTo)) {
       StateTableModel stateTableModel = (StateTableModel) table.getModel();
       stateTableModel.reorder(rowFrom, rowTo);
       target.getSelectionModel().addSelectionInterval(rowTo, rowTo);
       return true;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
示例#2
0
 @Override
 public boolean canImport(TransferHandler.TransferSupport info) {
   boolean b =
       (info.getComponent() == table)
           && info.isDrop()
           && info.isDataFlavorSupported(localObjectFlavor);
   table.setCursor(b ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop);
   return b;
 }
  /**
   * 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;
  }
示例#4
0
  @Override
  public boolean importData(TransferHandler.TransferSupport th) {
    Transferable tr = th.getTransferable();
    Component cp = th.getComponent();
    if (tr.isDataFlavorSupported(MyTransferable.data)) {
      if (cp instanceof JTree) {
        JTree tree = (JTree) cp;
        JTree.DropLocation location = tree.getDropLocation();
        TreePath path = location.getPath();
        int index = location.getChildIndex();
        if (index == -1) {
          index = 0;
        }
        // System.out.println(index);
        DefaultMutableTreeNode node;
        try {
          node = (DefaultMutableTreeNode) tr.getTransferData(MyTransferable.data);
          DefaultMutableTreeNode parent = (DefaultMutableTreeNode) path.getLastPathComponent();

          // vérifie si on ne drop pas dans un noeud fils
          if (node.isNodeChild(parent)) {
            return false;
          }
          Controleur controleur = Controleur.getInstance();
          controleur.deplacerElement(node, parent, index);

          DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
          model.removeNodeFromParent(node);
          // vérifie si on est plus hors index lors d'une réorganisation par ex
          if (index > parent.getChildCount()) {
            index = parent.getChildCount();
          }
          model.insertNodeInto(node, parent, index);
          //					controleur.ajoutElement(node, parent, index);

          TreePath newPath = path.pathByAddingChild(node);
          tree.makeVisible(newPath);
          tree.scrollRectToVisible(tree.getPathBounds(newPath));
        } catch (Exception e) {
          e.printStackTrace();
        }
        return true;
      }
    }
    return false;
  }
示例#5
0
        // ****************************************
        public boolean canImport(TransferHandler.TransferSupport support)
              // ****************************************
            {
          if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
            return false;
          }

          return true;
        }
示例#6
0
 @Override
 public boolean canImport(TransferHandler.TransferSupport t) {
   DataFlavor[] df = t.getDataFlavors();
   // vérifie si le bon type est drop
   for (int i = 0; i < df.length; i++) {
     if (df[i].equals(MyTransferable.data)) {
       return true;
     }
   }
   return false;
 }
  /**
   * 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;
  }
示例#8
0
        // ****************************************
        public boolean importData(TransferHandler.TransferSupport support)
              // ****************************************
            {

          if (!canImport(support)) {
            return false;
          }

          Transferable t = support.getTransferable();

          try {
            List<File> l = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);

            for (File f : l) {
              process_dropped_file(f);
            }
          } catch (UnsupportedFlavorException | IOException e) {
            return false;
          }

          return true;
        }