1. /*
  2. * @(#)FileView.java 1.8 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.filechooser;
  8. import java.io.File;
  9. import javax.swing.*;
  10. /**
  11. * FileView defines an abstract class that can be implemented to
  12. * provide the filechooser with ui information for a File.
  13. *
  14. * Each L&F JFileChooserUI object implements this class to pass
  15. * back the correct icons and type descriptions specific to
  16. * that L&F. For example, the Windows L&F returns the generic Windows
  17. * icons for directories and generic files.
  18. *
  19. * Additionally, you may want to provide your own FileView to
  20. * JFileChooser to return different icons or additional information
  21. * using {@link javax.swing.JFileChooser#setFileView}.
  22. *
  23. * JFileChooser first looks to see if there is a user defined FileView,
  24. * if there is, it gets type information from there first. If FileView
  25. * returns null for any method, JFileChooser then uses the L&F specific
  26. * view to get the information.
  27. *
  28. * So, for example, if you provide a FileView class that returns an
  29. * <code>Icon</code> for JPG files, and returns <code>null</code>
  30. * icons for all other files, the UI's FileView will provide default
  31. * icons for all other files.
  32. *
  33. * For an example implementation of a simple file filter, see
  34. * <code><i>yourJDK</i>/demo/jfc/FileChooserDemo/ExampleFileView.java</code>.
  35. * For more information, see the Swing Connection article on the
  36. * <a href="http://java.sun.com/products/jfc/swingdoc-current/file_chooser.html">File Chooser</a>
  37. *
  38. * @see javax.swing.JFileChooser
  39. *
  40. * @version 1.8 11/29/01
  41. * @author Jeff Dinkins
  42. *
  43. */
  44. public abstract class FileView {
  45. /**
  46. * The name of the file. Normally this would be simply f.getName()
  47. */
  48. public abstract String getName(File f);
  49. /**
  50. * A human readable description of the file. For example,
  51. * a file named jag.jpg might have a description that read:
  52. * "A JPEG image file of James Gosling's face"
  53. */
  54. public abstract String getDescription(File f);
  55. /**
  56. * A human readable description of the type of the file. For
  57. * example, a jpg file might have a type description of:
  58. * "A JPEG Compressed Image File"
  59. */
  60. public abstract String getTypeDescription(File f);
  61. /**
  62. * The icon that represents this file in the JFileChooser.
  63. */
  64. public abstract Icon getIcon(File f);
  65. /**
  66. * Whether the directory is traversable or not. This might be
  67. * useful, for example, if you want a directory to represent
  68. * a compound document and don't want the user to descend into it.
  69. */
  70. public abstract Boolean isTraversable(File f);
  71. }