net.sf.sfac.file
Enum FileType

java.lang.Object
  extended by java.lang.Enum<FileType>
      extended by net.sf.sfac.file.FileType
All Implemented Interfaces:
FileFilter, FilenameFilter, Serializable, Comparable<FileType>

public enum FileType
extends Enum<FileType>
implements FileFilter, FilenameFilter

All knows file types descriptors/filters. Those FileType are mostly language independent, only the filter for the JFileChooser (inner class FileChooserFilter) contains a language-dependent description.

Author:
Olivier Berlanger

Enum Constant Summary
FILE_TYPE_ALL
           
FILE_TYPE_CBZ
           
FILE_TYPE_CSV
           
FILE_TYPE_DB
           
FILE_TYPE_FO
           
FILE_TYPE_GIF
           
FILE_TYPE_HTML
           
FILE_TYPE_IMAGES
           
FILE_TYPE_JPEG
           
FILE_TYPE_MP3
           
FILE_TYPE_PDF
           
FILE_TYPE_PNG
           
FILE_TYPE_PROPERTIES
           
FILE_TYPE_SONG
           
FILE_TYPE_TEXT
           
FILE_TYPE_VIDEO
           
FILE_TYPE_XML
           
FILE_TYPE_ZIP
           
 
Method Summary
 boolean accept(File f)
          Return true if the given file has the good extension or if the given file is a directory.
 boolean accept(File dir, String name)
          Return true if the given file name has the good extension.
 String[] getAcceptedExtensions()
           
 String getDefaultDescription()
           
 String getDefaultExtension()
           
static String getFileExtension(String fileName)
          Utility method to get the extension of a file name (without the dot).
static FileType getFileType(File fil, FileType[] possibleTypes, FileType defaultType)
          Get the type of the given file.
 boolean isAcceptedExtension(String extension)
           
 boolean isFileOfType(File fil)
          Check if the given file is of the specifed type.
static File setFileExtension(File fil, FileType type, boolean overrideExisting)
          Add the correct extension to the given file.
 String toString()
           
static FileType valueOf(String name)
          Returns the enum constant of this type with the specified name.
static FileType[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

FILE_TYPE_ALL

public static final FileType FILE_TYPE_ALL

FILE_TYPE_TEXT

public static final FileType FILE_TYPE_TEXT

FILE_TYPE_XML

public static final FileType FILE_TYPE_XML

FILE_TYPE_PROPERTIES

public static final FileType FILE_TYPE_PROPERTIES

FILE_TYPE_PNG

public static final FileType FILE_TYPE_PNG

FILE_TYPE_JPEG

public static final FileType FILE_TYPE_JPEG

FILE_TYPE_GIF

public static final FileType FILE_TYPE_GIF

FILE_TYPE_IMAGES

public static final FileType FILE_TYPE_IMAGES

FILE_TYPE_PDF

public static final FileType FILE_TYPE_PDF

FILE_TYPE_ZIP

public static final FileType FILE_TYPE_ZIP

FILE_TYPE_CBZ

public static final FileType FILE_TYPE_CBZ

FILE_TYPE_HTML

public static final FileType FILE_TYPE_HTML

FILE_TYPE_DB

public static final FileType FILE_TYPE_DB

FILE_TYPE_CSV

public static final FileType FILE_TYPE_CSV

FILE_TYPE_FO

public static final FileType FILE_TYPE_FO

FILE_TYPE_SONG

public static final FileType FILE_TYPE_SONG

FILE_TYPE_MP3

public static final FileType FILE_TYPE_MP3

FILE_TYPE_VIDEO

public static final FileType FILE_TYPE_VIDEO
Method Detail

values

public static FileType[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (FileType c : FileType.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static FileType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

getFileType

public static FileType getFileType(File fil,
                                   FileType[] possibleTypes,
                                   FileType defaultType)
Get the type of the given file. The returned value will be one of the given possible type or the given defaultType. The type FILE_TYPE_ALL is ignored if it's present in the possible types.

Parameters:
fil - the file of which we want to know the type.
possibleTypes - all the possible types.
defaultType - the type returned if none of the given types matched.
Returns:
the file type.

setFileExtension

public static File setFileExtension(File fil,
                                    FileType type,
                                    boolean overrideExisting)
Add the correct extension to the given file.

Parameters:
fil - The file to be updated with correct extension.
type - The type of the file (defining the extension it should have)
overrideExisting - if true any existing extension not matching the expected one will be replaced. If false, the correct extension is only added if there is no extension currently defined.
Returns:
File the given file with possibly updated extension.

getFileExtension

public static String getFileExtension(String fileName)
Utility method to get the extension of a file name (without the dot).

Parameters:
fileName - The full file name (like: "myFile.txt").
Returns:
String The file extension (like "txt").

getDefaultDescription

public String getDefaultDescription()

getDefaultExtension

public String getDefaultExtension()

getAcceptedExtensions

public String[] getAcceptedExtensions()

accept

public boolean accept(File f)
Return true if the given file has the good extension or if the given file is a directory.
Returns false otherwise.

Specified by:
accept in interface FileFilter

accept

public boolean accept(File dir,
                      String name)
Return true if the given file name has the good extension.
Note: the given directory is ignored.

Specified by:
accept in interface FilenameFilter

isFileOfType

public boolean isFileOfType(File fil)
Check if the given file is of the specifed type. (the type check is only done on the file name extension).
This method always returns false for directories. If the given file is null, false is returned.


isAcceptedExtension

public boolean isAcceptedExtension(String extension)

toString

public String toString()
Overrides:
toString in class Enum<FileType>


Copyright © 2012. All Rights Reserved.