PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/datatransfer/ListVFSFileTransferable.java

#
Java | 93 lines | 60 code | 8 blank | 25 comment | 11 complexity | 782394fe319abd8f7d8efad287a60f48 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * ListVFSFileTransferable.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2010 Matthieu Casanova
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.datatransfer;
  23. import org.gjt.sp.jedit.io.FileVFS;
  24. import org.gjt.sp.jedit.io.VFSFile;
  25. import java.awt.datatransfer.DataFlavor;
  26. import java.awt.datatransfer.Transferable;
  27. import java.awt.datatransfer.UnsupportedFlavorException;
  28. import java.io.File;
  29. import java.io.IOException;
  30. import java.util.ArrayList;
  31. import java.util.Arrays;
  32. import java.util.Collections;
  33. import java.util.List;
  34. /**
  35. * @author Matthieu Casanova
  36. * @since jEdit 4.4.x
  37. */
  38. public class ListVFSFileTransferable implements Transferable
  39. {
  40. public static final DataFlavor jEditFileList = new DataFlavor(List.class, "application/x-java-jEdit-list-vfsfile");
  41. public static final DataFlavor[] supported = {jEditFileList, DataFlavor.stringFlavor, DataFlavor.javaFileListFlavor};
  42. private final List<VFSFile> files;
  43. public ListVFSFileTransferable(VFSFile[] files)
  44. {
  45. this.files = Collections.unmodifiableList(Arrays.asList(files));
  46. }
  47. public DataFlavor[] getTransferDataFlavors()
  48. {
  49. return supported;
  50. }
  51. public boolean isDataFlavorSupported(DataFlavor flavor)
  52. {
  53. return jEditFileList.equals(flavor) || DataFlavor.stringFlavor.equals(flavor);
  54. }
  55. public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
  56. {
  57. if (jEditFileList.equals(flavor))
  58. {
  59. return files;
  60. }
  61. else if (DataFlavor.stringFlavor.equals(flavor))
  62. {
  63. StringBuilder builder = new StringBuilder();
  64. for (int i = 0; i < files.size(); i++)
  65. {
  66. VFSFile vfsFile = files.get(i);
  67. if (i != 0)
  68. builder.append('\n');
  69. builder.append(vfsFile);
  70. }
  71. return builder.toString();
  72. }
  73. else if (DataFlavor.javaFileListFlavor.equals(flavor))
  74. {
  75. List<File> files = new ArrayList<File>(this.files.size());
  76. for (VFSFile file : this.files)
  77. {
  78. if (file.getVFS() instanceof FileVFS)
  79. files.add(new File(file.getPath()));
  80. }
  81. return files;
  82. }
  83. throw new UnsupportedFlavorException(flavor);
  84. }
  85. }