package vtk;

/**
 * Enum used to load native library more easily
 * 
 * @author sebastien jourdain - sebastien.jourdain@kitware.com
 */
public enum vtkNativeLibrary {

    COMMON("vtkCommonJava"), //
    FILTERING("vtkFilteringJava"), //
    GEOVIS("vtkGeovisJava"), //
    GRAPHICS("vtkGraphicsJava"), //
    HYBRID("vtkHybridJava"), //
    IMAGING("vtkImagingJava"), //
    INFOVIS("vtkInfovisJava"), //
    IO("vtkIOJava"), //
    RENDERING("vtkRenderingJava"), //
    VIEWS("vtkViewsJava"), //
    VOLUME_RENDERING("vtkVolumeRenderingJava"), //
    WIDGETS("vtkWidgetsJava"), //
    CHARTS("vtkChartsJava");

    /**
     * Try to load all library
     *
     * @return true if all library have been successfully loaded
     */
    public static boolean LoadAllNativeLibraries() {
        boolean isEveryThingLoaded = true;
        for (vtkNativeLibrary lib : values()) {
            try {
                lib.LoadLibrary();
            } catch (UnsatisfiedLinkError e) {
                isEveryThingLoaded = false;
            }
        }

        return isEveryThingLoaded;
    }

    /**
     * Load the set of given library and trows runtime exception if any given
     * library failed in the loading process
     *
     * @param nativeLibraries
     */
    public static void LoadNativeLibraries(vtkNativeLibrary... nativeLibraries) {
        for (vtkNativeLibrary lib : nativeLibraries) {
            lib.LoadLibrary();
        }
    }

    private vtkNativeLibrary(String nativeLibraryName) {
        this.nativeLibraryName = nativeLibraryName;
        this.loaded = false;
    }

    /**
     * Load the library and throws runtime exception if the library failed in
     * the loading process
     */
    public void LoadLibrary() throws UnsatisfiedLinkError {
        if (!loaded) {
            System.loadLibrary(nativeLibraryName);
        }
        loaded = true;
    }

    /**
     * @return true if the library has already been succefuly loaded
     */
    public boolean IsLoaded() {
        return loaded;
    }

    /**
     * @return the library name
     */
    public String GetLibraryName() {
        return nativeLibraryName;
    }

    private String nativeLibraryName;
    private boolean loaded;
}

@@ -7,16 +7,38 @@
 e vtk;%0A%0A
+import java.io.File;%0A%0A
 /**%0A * E
@@ -80,20 +80,373 @@
 e easily
+. If you don't want to set the%0A * specific environment variable you can provide the path of the directory that%0A * contains the VTK library through a Java Property. Like in the following%0A * command line:%0A *%0A * %3E java -cp vtk.jar -Dvtk.lib.dir=.../vtk-libs vtk.sample.SimpleVTK%0A *%0A * The directory .../vtk-libs must contain the so/dll/dylib + the jni files
 %0A *
- 
 %0A * @aut
@@ -2182,352 +2182,1379 @@
     
-System.loadLibrary(nativeLibraryName);%0A        %7D%0A        loaded = true;%0A    %7D%0A%0A    /**%0A     * @return true if the library has already been succefuly loaded%0A     */%0A    public boolean IsLoaded() %7B%0A        return loaded;%0A    %7D%0A%0A    /**%0A     * @return the library name%0A     */%0A    public String GetLibraryName() %7B%0A        return nativeLibraryName;
+if (System.getProperty(%22vtk.lib.dir%22) != null) %7B%0A                File dir = new File(System.getProperty(%22vtk.lib.dir%22));%0A                patchJavaLibraryPath(dir.getAbsolutePath());%0A                File libPath = new File(dir, System.mapLibraryName(nativeLibraryName));%0A                if (libPath.exists()) %7B%0A                    try %7B%0A                        Runtime.getRuntime().load(libPath.getAbsolutePath());%0A                        loaded = true;%0A                        return;%0A                    %7D catch (UnsatisfiedLinkError e) %7B%0A                    %7D%0A                %7D%0A            %7D%0A            System.loadLibrary(nativeLibraryName);%0A        %7D%0A        loaded = true;%0A    %7D%0A%0A    /**%0A     * @return true if the library has already been succefuly loaded%0A     */%0A    public boolean IsLoaded() %7B%0A        return loaded;%0A    %7D%0A%0A    /**%0A     * @return the library name%0A     */%0A    public String GetLibraryName() %7B%0A        return nativeLibraryName;%0A    %7D%0A%0A    private static void patchJavaLibraryPath(String vtkLibDir) %7B%0A        if (vtkLibDir != null) %7B%0A            String path_separator = System.getProperty(%22path.separator%22);%0A            String s = System.getProperty(%22java.library.path%22);%0A            if (!s.contains(vtkLibDir)) %7B%0A                s = s + path_separator + vtkLibDir;%0A                System.setProperty(%22java.library.path%22, s);%0A            %7D%0A        %7D
 %0A   

Add flexibility in the native library loading