(TransferHandler.TransferSupport support)
| 384 | } |
| 385 | |
| 386 | public boolean importData(TransferHandler.TransferSupport support) { |
| 387 | int successful = 0; |
| 388 | |
| 389 | if (!canImport(support)) { |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | try { |
| 394 | Transferable transferable = support.getTransferable(); |
| 395 | DataFlavor uriListFlavor = |
| 396 | new DataFlavor("text/uri-list;class=java.lang.String"); |
| 397 | |
| 398 | if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { |
| 399 | List<?> list = (List<?>) |
| 400 | transferable.getTransferData(DataFlavor.javaFileListFlavor); |
| 401 | for (Object o : list) { |
| 402 | File file = (File) o; |
| 403 | if (sketch.addFile(file)) { |
| 404 | successful++; |
| 405 | } |
| 406 | } |
| 407 | } else if (transferable.isDataFlavorSupported(uriListFlavor)) { |
| 408 | // Some platforms (Mac OS X and Linux, when this began) preferred |
| 409 | // this method of moving files. |
| 410 | String data = (String)transferable.getTransferData(uriListFlavor); |
| 411 | String[] pieces = PApplet.splitTokens(data, "\r\n"); |
| 412 | for (String piece : pieces) { |
| 413 | if (piece.startsWith("#")) continue; |
| 414 | |
| 415 | String path = null; |
| 416 | if (piece.startsWith("file:///")) { |
| 417 | path = piece.substring(7); |
| 418 | } else if (piece.startsWith("file:/")) { |
| 419 | path = piece.substring(5); |
| 420 | } |
| 421 | if (path != null) { |
| 422 | if (sketch.addFile(new File(path))) { |
| 423 | successful++; |
| 424 | } |
| 425 | } else { |
| 426 | System.err.println("Path not found for: " + data); |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | } catch (Exception e) { |
| 431 | Messages.showWarning("Drag & Drop Problem", |
| 432 | "An error occurred while trying to add files to the sketch.", e); |
| 433 | return false; |
| 434 | } |
| 435 | statusNotice(Language.pluralize("editor.status.drag_and_drop.files_added", successful)); |
| 436 | return true; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 |
nothing calls this directly
no test coverage detected