Quaqua 8.0 2011-10-02

ch.randelshofer.quaqua.osx
Class OSXFile

java.lang.Object
  extended by ch.randelshofer.quaqua.osx.OSXFile

public class OSXFile
extends java.lang.Object

OSXFile provides access to Mac OS X file meta data and can resolve file aliases.

Version:
$Id: OSXFile.java 82 2009-06-11 08:57:33Z wrandelshofer $
Author:
Werner Randelshofer

Field Summary
static int FILE_TYPE_ALIAS
           
static int FILE_TYPE_DIRECTORY
           
static int FILE_TYPE_FILE
           
static int FILE_TYPE_UNKOWN
           
 
Method Summary
static boolean canWorkWithAliases()
          Returns true if this class can work with aliases.
static boolean canWorkWithLabels()
          Returns true if this class can work with labels.
static java.io.File getAbsoluteFile(java.io.File f)
          Converts the path name denoted by the file to an absolute path.
static java.lang.String getDisplayName(java.io.File f)
          Returns the localized display name of the specified file.
static int getFileType(java.io.File f)
          Returns the file type: 0=file, 1=directory, 2=alias, -1=unknown.
static javax.swing.Icon getIcon(java.io.File file, int size)
          Returns the icon for the specified file.
static java.awt.image.BufferedImage getIconImage(java.io.File file, int size)
          Returns the icon image for the specified file.
static java.lang.String getKindString(java.io.File file)
          Returns the kind string of the specified file.
static int getLabel(java.io.File f)
          Returns the label of the specified file.
static java.awt.Color getLabelColor(int label, int type)
          Returns the color of the specified label.
static javax.swing.Icon getQuickLookThumbnail(java.io.File file, int size)
          Returns a QuickLook thumbnail for the specified file.
static java.awt.image.BufferedImage getQuickLookThumbnailImage(java.io.File file, int size)
          Returns the QuickLook thumbnail image for the specified file.
static boolean isTraversable(java.io.File file)
           
static java.io.File resolveAlias(byte[] serializedAlias, boolean noUI)
          Resolves a serialized Alias to a File object.
static java.io.File resolveAlias(java.io.File alias, boolean noUI)
          Resolves an alias to a File object.
static int resolveAliasType(byte[] serializedAlias, boolean noUI)
          Resolves an alias to a type info.
static int resolveAliasType(java.io.File alias, boolean noUI)
          Resolves an alias to a type info.
static byte[] toSerializedAlias(java.io.File f)
          Creates a serialized Alias.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_TYPE_ALIAS

public static final int FILE_TYPE_ALIAS
See Also:
Constant Field Values

FILE_TYPE_DIRECTORY

public static final int FILE_TYPE_DIRECTORY
See Also:
Constant Field Values

FILE_TYPE_FILE

public static final int FILE_TYPE_FILE
See Also:
Constant Field Values

FILE_TYPE_UNKOWN

public static final int FILE_TYPE_UNKOWN
See Also:
Constant Field Values
Method Detail

getAbsoluteFile

public static java.io.File getAbsoluteFile(java.io.File f)
Converts the path name denoted by the file to an absolute path. Relative paths are always resolved against the home directory of the user and not against the current user.dir directory. The returned file objects represents an absolute path containing no '.' and '..' relative path components. This method acts solely on the textual representation of the file and therefore does does not necessarily canonicalize the path nor does it resolve aliases.

Parameters:
f - The file which we must ensure contains an absolute path.

canWorkWithAliases

public static boolean canWorkWithAliases()
Returns true if this class can work with aliases.


getFileType

public static int getFileType(java.io.File f)
Returns the file type: 0=file, 1=directory, 2=alias, -1=unknown.


resolveAlias

public static java.io.File resolveAlias(java.io.File alias,
                                        boolean noUI)
Resolves an alias to a File object.

Parameters:
alias - the Alias file to be resolved.
noUI - Set this to true, if the alias should be resolved without user interaction.
Returns:
Returns the resolved File object.

resolveAliasType

public static int resolveAliasType(java.io.File alias,
                                   boolean noUI)
Resolves an alias to a type info. Resolves the type of the path if the provided path is not an alias.

Parameters:
alias - the path to the alias to be resolved.
noUI - Set this to true, if the alias should be resolved without user interaction.
Returns:
Returns the resolved path.

toSerializedAlias

public static byte[] toSerializedAlias(java.io.File f)
Creates a serialized Alias.

Returns:
A serialized alias or null, if serialization could not be done.

resolveAlias

public static java.io.File resolveAlias(byte[] serializedAlias,
                                        boolean noUI)
Resolves a serialized Alias to a File object.

Parameters:
noUI - Set this to true, if the alias should be resolved without user interaction.
Returns:
A File or null, if the serialized Alias could not be resolved.

resolveAliasType

public static int resolveAliasType(byte[] serializedAlias,
                                   boolean noUI)
Resolves an alias to a type info. Resolves the type of the path if the provided path is not an alias.

Parameters:
serializedAlias - the path to the alias to be resolved.
noUI - Set this to true, if the alias should be resolved without user interaction.
Returns:
Returns the resolved path.

canWorkWithLabels

public static boolean canWorkWithLabels()
Returns true if this class can work with labels.


getLabel

public static int getLabel(java.io.File f)
Returns the label of the specified file. The label is a value in the interval from 0 through 7. Returns -1 if the label could not be determined, e.g. if the file does not exist.


getLabelColor

public static java.awt.Color getLabelColor(int label,
                                           int type)
Returns the color of the specified label. Returns null, if the label does not have a color.

Parameters:
label - value from 0 through 7
type - 0=dark enabled,1=bright enabld,2=dark disabled,3=bright enabled

getIconImage

public static java.awt.image.BufferedImage getIconImage(java.io.File file,
                                                        int size)
Returns the icon image for the specified file. If the file does not exist, a generic image is returned. XXX - Returns null if it was not possible to get the icon image. We should return a generic image in this case!


getQuickLookThumbnailImage

public static java.awt.image.BufferedImage getQuickLookThumbnailImage(java.io.File file,
                                                                      int size)
Returns the QuickLook thumbnail image for the specified file. If it could not be created, native code fetches the file's icon instead.

Please only call this method on Mac OS X 10.6 Snow Leopard and above. Altough the native API is also present on Mac OS X 10.5 our code does not run stable there.


getIcon

public static javax.swing.Icon getIcon(java.io.File file,
                                       int size)
Returns the icon for the specified file. If the file does not exist, a generic icon is returned.


getQuickLookThumbnail

public static javax.swing.Icon getQuickLookThumbnail(java.io.File file,
                                                     int size)
Returns a QuickLook thumbnail for the specified file.


getKindString

public static java.lang.String getKindString(java.io.File file)
Returns the kind string of the specified file. The description is localized in the current Locale of the Finder.

Returns:
The kind or null, if it couldn't be determined.

isTraversable

public static boolean isTraversable(java.io.File file)

getDisplayName

public static java.lang.String getDisplayName(java.io.File f)
Returns the localized display name of the specified file.


Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.