1. /*
  2. * @(#)FileView.java 1.19 04/06/28
  3. *
  4. * Copyright 2004 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. * <code>FileView</code> defines an abstract class that can be implemented
  12. * to provide the filechooser with UI information for a <code>File</code>.
  13. * Each L&F <code>JFileChooserUI</code> object implements this
  14. * class to pass back the correct icons and type descriptions specific to
  15. * that L&F. For example, the Microsoft Windows L&F returns the
  16. * generic Windows icons for directories and generic files.
  17. * Additionally, you may want to provide your own <code>FileView</code> to
  18. * <code>JFileChooser</code> to return different icons or additional
  19. * information using {@link javax.swing.JFileChooser#setFileView}.
  20. *
  21. * <p>
  22. *
  23. * <code>JFileChooser</code> first looks to see if there is a user defined
  24. * <code>FileView</code>, if there is, it gets type information from
  25. * there first. If <code>FileView</code> returns <code>null</code> for
  26. * any method, <code>JFileChooser</code> then uses the L&F specific
  27. * view to get the information.
  28. * So, for example, if you provide a <code>FileView</code> class that
  29. * returns an <code>Icon</code> for JPG files, and returns <code>null</code>
  30. * icons for all other files, the UI's <code>FileView</code> will provide
  31. * default icons for all other files.
  32. *
  33. * <p>
  34. *
  35. * For an example implementation of a simple file view, see
  36. * <code><i>yourJDK</i>/demo/jfc/FileChooserDemo/ExampleFileView.java</code>.
  37. * For more information and examples see
  38. * <a
  39. href="http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html">How to Use File Choosers</a>,
  40. * a section in <em>The Java Tutorial</em>.
  41. *
  42. * @see javax.swing.JFileChooser
  43. *
  44. * @version 1.19 06/28/04
  45. * @author Jeff Dinkins
  46. *
  47. */
  48. public abstract class FileView {
  49. /**
  50. * The name of the file. Normally this would be simply
  51. * <code>f.getName()</code>.
  52. */
  53. public String getName(File f) {
  54. return null;
  55. };
  56. /**
  57. * A human readable description of the file. For example,
  58. * a file named <i>jag.jpg</i> might have a description that read:
  59. * "A JPEG image file of James Gosling's face".
  60. */
  61. public String getDescription(File f) {
  62. return null;
  63. }
  64. /**
  65. * A human readable description of the type of the file. For
  66. * example, a <code>jpg</code> file might have a type description of:
  67. * "A JPEG Compressed Image File"
  68. */
  69. public String getTypeDescription(File f) {
  70. return null;
  71. }
  72. /**
  73. * The icon that represents this file in the <code>JFileChooser</code>.
  74. */
  75. public Icon getIcon(File f) {
  76. return null;
  77. }
  78. /**
  79. * Whether the directory is traversable or not. This might be
  80. * useful, for example, if you want a directory to represent
  81. * a compound document and don't want the user to descend into it.
  82. */
  83. public Boolean isTraversable(File f) {
  84. return null;
  85. }
  86. }