src/macosx/classes/com/apple/laf/AquaFileView.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.apple.laf;
  27 
  28 import java.io.*;
  29 import java.security.PrivilegedAction;
  30 import java.util.*;
  31 import java.util.Map.Entry;
  32 
  33 import javax.swing.Icon;
  34 import javax.swing.filechooser.FileView;
  35 
  36 import com.apple.laf.AquaUtils.RecyclableSingleton;
  37 
  38 class AquaFileView extends FileView {
  39     private static final boolean DEBUG = false;
  40 
  41     private static final int UNINITALIZED_LS_INFO = -1;
  42 
  43     // Constants from LaunchServices.h
  44     static final int kLSItemInfoIsPlainFile        = 0x00000001; /* Not a directory, volume, or symlink*/
  45     static final int kLSItemInfoIsPackage          = 0x00000002; /* Packaged directory*/
  46     static final int kLSItemInfoIsApplication      = 0x00000004; /* Single-file or packaged application*/
  47     static final int kLSItemInfoIsContainer        = 0x00000008; /* Directory (includes packages) or volume*/
  48     static final int kLSItemInfoIsAliasFile        = 0x00000010; /* Alias file (includes sym links)*/
  49     static final int kLSItemInfoIsSymlink          = 0x00000020; /* UNIX sym link*/
  50     static final int kLSItemInfoIsInvisible        = 0x00000040; /* Invisible by any known mechanism*/
  51     static final int kLSItemInfoIsNativeApp        = 0x00000080; /* Carbon or Cocoa native app*/
  52     static final int kLSItemInfoIsClassicApp       = 0x00000100; /* CFM/68K Classic app*/
  53     static final int kLSItemInfoAppPrefersNative   = 0x00000200; /* Carbon app that prefers to be launched natively*/
  54     static final int kLSItemInfoAppPrefersClassic  = 0x00000400; /* Carbon app that prefers to be launched in Classic*/
  55     static final int kLSItemInfoAppIsScriptable    = 0x00000800; /* App can be scripted*/
  56     static final int kLSItemInfoIsVolume           = 0x00001000; /* Item is a volume*/
  57     static final int kLSItemInfoExtensionIsHidden  = 0x00100000; /* Item has a hidden extension*/
  58 
  59     static {
  60         java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));




  61     }


  62 
  63     // TODO: Un-comment this out when the native version exists
  64     //private static native String getNativePathToRunningJDKBundle();
  65     private static native String getNativePathToSharedJDKBundle();
  66 
  67     private static native String getNativeMachineName();
  68     private static native String getNativeDisplayName(final byte[] pathBytes, final boolean isDirectory);
  69     private static native int getNativeLSInfo(final byte[] pathBytes, final boolean isDirectory);
  70     private static native String getNativePathForResolvedAlias(final byte[] absolutePath, final boolean isDirectory);
  71 
  72     static final RecyclableSingleton<String> machineName = new RecyclableSingleton<String>() {
  73         @Override
  74         protected String getInstance() {
  75             return getNativeMachineName();
  76         }
  77     };
  78     private static String getMachineName() {
  79         return machineName.get();
  80     }
  81 




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.apple.laf;
  27 
  28 import java.io.*;

  29 import java.util.*;
  30 import java.util.Map.Entry;
  31 
  32 import javax.swing.Icon;
  33 import javax.swing.filechooser.FileView;
  34 
  35 import com.apple.laf.AquaUtils.RecyclableSingleton;
  36 
  37 class AquaFileView extends FileView {
  38     private static final boolean DEBUG = false;
  39 
  40     private static final int UNINITALIZED_LS_INFO = -1;
  41 
  42     // Constants from LaunchServices.h
  43     static final int kLSItemInfoIsPlainFile        = 0x00000001; /* Not a directory, volume, or symlink*/
  44     static final int kLSItemInfoIsPackage          = 0x00000002; /* Packaged directory*/
  45     static final int kLSItemInfoIsApplication      = 0x00000004; /* Single-file or packaged application*/
  46     static final int kLSItemInfoIsContainer        = 0x00000008; /* Directory (includes packages) or volume*/
  47     static final int kLSItemInfoIsAliasFile        = 0x00000010; /* Alias file (includes sym links)*/
  48     static final int kLSItemInfoIsSymlink          = 0x00000020; /* UNIX sym link*/
  49     static final int kLSItemInfoIsInvisible        = 0x00000040; /* Invisible by any known mechanism*/
  50     static final int kLSItemInfoIsNativeApp        = 0x00000080; /* Carbon or Cocoa native app*/
  51     static final int kLSItemInfoIsClassicApp       = 0x00000100; /* CFM/68K Classic app*/
  52     static final int kLSItemInfoAppPrefersNative   = 0x00000200; /* Carbon app that prefers to be launched natively*/
  53     static final int kLSItemInfoAppPrefersClassic  = 0x00000400; /* Carbon app that prefers to be launched in Classic*/
  54     static final int kLSItemInfoAppIsScriptable    = 0x00000800; /* App can be scripted*/
  55     static final int kLSItemInfoIsVolume           = 0x00001000; /* Item is a volume*/
  56     static final int kLSItemInfoExtensionIsHidden  = 0x00100000; /* Item has a hidden extension*/
  57 
  58     static {
  59         java.security.AccessController.doPrivileged(
  60             new java.security.PrivilegedAction<Void>() {
  61                 public Void run() {
  62                     System.loadLibrary("osxui");
  63                     return null;
  64                 }
  65             });
  66     }
  67 
  68     // TODO: Un-comment this out when the native version exists
  69     //private static native String getNativePathToRunningJDKBundle();
  70     private static native String getNativePathToSharedJDKBundle();
  71 
  72     private static native String getNativeMachineName();
  73     private static native String getNativeDisplayName(final byte[] pathBytes, final boolean isDirectory);
  74     private static native int getNativeLSInfo(final byte[] pathBytes, final boolean isDirectory);
  75     private static native String getNativePathForResolvedAlias(final byte[] absolutePath, final boolean isDirectory);
  76 
  77     static final RecyclableSingleton<String> machineName = new RecyclableSingleton<String>() {
  78         @Override
  79         protected String getInstance() {
  80             return getNativeMachineName();
  81         }
  82     };
  83     private static String getMachineName() {
  84         return machineName.get();
  85     }
  86