org.fife.ui.rtextfilechooser
Class Utilities

java.lang.Object
  extended by org.fife.ui.rtextfilechooser.Utilities

public class Utilities
extends java.lang.Object

Utility classes for dealing with an RTextFileChooser.

Version:
1.0
Author:
Robert Futrell
See Also:
RTextFileChooser

Constructor Summary
Utilities()
           
 
Method Summary
static boolean addFileFilters(java.io.File file, RTextFileChooser chooser)
          Adds user-defined file filters to a file chooser, as specified in a file.
static void copyFile(java.io.File sourceFile, java.io.File destFile)
          Copies a file from one location to another.
static java.lang.String getExtension(java.lang.String fileName)
          Returns the extension of a file name.
static java.lang.String getFileSizeStringFor(java.io.File file)
          Returns a string representation of a file size, such as "842 bytes", "1.43 KB" or "3.4 MB".
static java.lang.String getFileSizeStringFor(long size, boolean reportInKB)
          Returns a string representation of a file size, such as "842 bytes", "1.43 KB" or "3.4 MB".
static java.lang.String getLastModifiedString(long date)
          Returns a date string for the file's "last modified" time.
static boolean isCaseSensitiveFileSystem()
          Returns whether or not the current OS is case-sensitive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

addFileFilters

public static boolean addFileFilters(java.io.File file,
                                     RTextFileChooser chooser)
                              throws java.io.IOException
Adds user-defined file filters to a file chooser, as specified in a file.

The file should have the following format:

   <?xml version="1.0"?>

   <ExtraFileFilters>
      <ExtensionFileFilter name="filter-name" ignoreCase="true|false"
            showExtensions="true|false">
         <Extension>ext-with-no-dot</Extension>
         ...
      </ExtensionFileFilter>
   </ExtraFileFilters>
 
where filter-name is the description of the filter as displayed in the file chooser, ignoreCase designates whether the filter should ignore case when filtering files, and showExtensions designates whether the extensions should be displayed beside the description in the file chooser.

The values within Extension tags are the extensions of files to be accepted by the filter (excluding the initial period).

ignoreCase and showExtensions both have a default value of true.

Parameters:
file - The XML file, as described above.
chooser - The file chooser to which to add the file filters.
Returns:
Whether the operation was successful. This will return false if the file is not found, for example.
Throws:
java.io.IOException - If an I/O error occurs while reading the file.

copyFile

public static void copyFile(java.io.File sourceFile,
                            java.io.File destFile)
                     throws java.io.IOException
Copies a file from one location to another.

Parameters:
sourceFile - The file to copy.
destFile - The location for the new copy.
Throws:
java.io.IOException - If an error occurs.

getExtension

public static final java.lang.String getExtension(java.lang.String fileName)
Returns the extension of a file name.

Parameters:
fileName - The file name.
Returns:
The extension, or null if the file name has no extension.

getFileSizeStringFor

public static final java.lang.String getFileSizeStringFor(java.io.File file)
Returns a string representation of a file size, such as "842 bytes", "1.43 KB" or "3.4 MB".

Parameters:
file - The file for which you want its size converted into an appropriate string.
Returns:
The string. Note that this will be invalid if file is a directory.

getFileSizeStringFor

public static final java.lang.String getFileSizeStringFor(long size,
                                                          boolean reportInKB)
Returns a string representation of a file size, such as "842 bytes", "1.43 KB" or "3.4 MB". This method should only be called on the EDT.

Parameters:
size - the size of a file, in bytes.
Returns:
The string.
See Also:
getFileSizeStringFor(File)

getLastModifiedString

public static final java.lang.String getLastModifiedString(long date)
Returns a date string for the file's "last modified" time.

Parameters:
date - The date, as a long.
Returns:
A string representation of the date.

isCaseSensitiveFileSystem

public static final boolean isCaseSensitiveFileSystem()
Returns whether or not the current OS is case-sensitive. Windows and OS X will return false, other OSes will return true.

Returns:
Whether or not the underlying OS is case-sensitive.