View Javadoc

1   package com.melloware.jukes.file.image;
2   
3   import java.io.File;
4   
5   import javax.swing.Icon;
6   import javax.swing.ImageIcon;
7   import javax.swing.filechooser.FileView;
8   
9   import org.apache.commons.io.FilenameUtils;
10  
11  import com.melloware.jukes.file.filter.ImageFilter;
12  import com.melloware.jukes.gui.tool.Resources;
13  
14  /**
15   * Helper for Image File chooser.
16   * <p>
17   * Copyright (c) 2006
18   * Melloware, Inc. <http://www.melloware.com>
19   * @author Emil A. Lefkof III <info@melloware.com>
20   * @version 4.0
21   */
22  public final class ImageFileView
23      extends FileView {
24      
25      static ImageIcon gifIcon = (ImageIcon)Resources.FILE_GIF_ICON;
26      static ImageIcon jpgIcon = (ImageIcon)Resources.FILE_JPG_ICON;
27      static ImageIcon pngIcon = (ImageIcon)Resources.FILE_PNG_ICON;
28      static ImageIcon tiffIcon = (ImageIcon)Resources.FILE_TIF_ICON;
29  
30      public String getDescription(File f) {
31          return null;    // let the L&F FileView figure this out
32      }
33  
34      public Icon getIcon(File f) {
35          String extension = FilenameUtils.getExtension(f.getName());
36          Icon icon = null;
37  
38          if (extension != null) {
39              if (extension.equals(ImageFilter.JPEG) || extension.equals(ImageFilter.JPG)) {
40                  icon = jpgIcon;
41              } else if (extension.equals(ImageFilter.GIF)) {
42                  icon = gifIcon;
43              } else if (extension.equals(ImageFilter.TIF) || extension.equals(ImageFilter.TIFF)) {
44                  icon = tiffIcon;
45              } else if (extension.equals(ImageFilter.PNG)) {
46                  icon = pngIcon;
47              }
48          }
49          return icon;
50      }
51  
52      public String getName(File f) {
53          return null;    // let the L&F FileView figure this out
54      }
55  
56      public String getTypeDescription(File f) {
57          String extension = FilenameUtils.getExtension(f.getName());
58          String type = null;
59  
60          if (extension != null) {
61              if (extension.equals(ImageFilter.JPEG) || extension.equals(ImageFilter.JPG)) {
62                  type = "JPEG Image";
63              } else if (extension.equals(ImageFilter.GIF)) {
64                  type = "GIF Image";
65              } else if (extension.equals(ImageFilter.TIF) || extension.equals(ImageFilter.TIFF)) {
66                  type = "TIFF Image";
67              } else if (extension.equals(ImageFilter.PNG)) {
68                  type = "PNG Image";
69              }
70          }
71          return type;
72      }
73  
74      public Boolean isTraversable(File f) {
75          return null;    // let the L&F FileView figure this out
76      }
77  }