mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 15:00:54 +03:00
Merge PR #453: Add a system property to load pre-extracted native libraries from a directory
This commit is contained in:
@@ -139,6 +139,14 @@ public interface FlatSystemProperties
|
|||||||
*/
|
*/
|
||||||
String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection";
|
String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies a directory in which the native FlatLaf library have been extracted.
|
||||||
|
* This can be used to avoid extraction of the native libraries to the temporary directory at runtime.
|
||||||
|
*
|
||||||
|
* @since 2
|
||||||
|
*/
|
||||||
|
String NATIVE_LIBRARY_PATH = "flatlaf.nativeLibraryPath";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a system property is set and returns {@code true} if its value
|
* Checks whether a system property is set and returns {@code true} if its value
|
||||||
* is {@code "true"} (case-insensitive), otherwise it returns {@code false}.
|
* is {@code "true"} (case-insensitive), otherwise it returns {@code false}.
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.awt.Window;
|
|||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
|
import java.io.File;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -37,6 +38,7 @@ import javax.swing.Timer;
|
|||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import javax.swing.event.EventListenerList;
|
import javax.swing.event.EventListenerList;
|
||||||
|
import com.formdev.flatlaf.FlatSystemProperties;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
import com.formdev.flatlaf.util.NativeLibrary;
|
import com.formdev.flatlaf.util.NativeLibrary;
|
||||||
import com.formdev.flatlaf.util.SystemInfo;
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
@@ -114,11 +116,7 @@ class FlatWindowsNativeWindowBorder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String libraryName = "com/formdev/flatlaf/natives/flatlaf-windows-x86";
|
nativeLibrary = createNativeLibrary();
|
||||||
if( SystemInfo.isX86_64 )
|
|
||||||
libraryName += "_64";
|
|
||||||
|
|
||||||
nativeLibrary = new NativeLibrary( libraryName, null, true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check whether native library was successfully loaded
|
// check whether native library was successfully loaded
|
||||||
@@ -131,6 +129,23 @@ class FlatWindowsNativeWindowBorder
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static NativeLibrary createNativeLibrary() {
|
||||||
|
String libraryName = "flatlaf-windows-x86";
|
||||||
|
if( SystemInfo.isX86_64 )
|
||||||
|
libraryName += "_64";
|
||||||
|
|
||||||
|
String libraryPath = System.getProperty( FlatSystemProperties.NATIVE_LIBRARY_PATH );
|
||||||
|
if( libraryPath != null ) {
|
||||||
|
File libraryFile = new File( libraryPath, libraryName + ".dll" );
|
||||||
|
if( libraryFile.exists() )
|
||||||
|
return new NativeLibrary( libraryFile, true );
|
||||||
|
else
|
||||||
|
LoggingFacade.INSTANCE.logSevere( "Did not find external library " + libraryFile + ", using extracted library instead", null );
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NativeLibrary( "com/formdev/flatlaf/natives/" + libraryName, null, true );
|
||||||
|
}
|
||||||
|
|
||||||
private FlatWindowsNativeWindowBorder() {
|
private FlatWindowsNativeWindowBorder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,19 @@ public class NativeLibrary
|
|||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load native library from given file.
|
||||||
|
*
|
||||||
|
* @param libraryFile the file of the native library
|
||||||
|
* @param supported whether the native library is supported on the current platform
|
||||||
|
* @since 2
|
||||||
|
*/
|
||||||
|
public NativeLibrary( File libraryFile, boolean supported ) {
|
||||||
|
this.loaded = supported
|
||||||
|
? loadLibraryFromFile( libraryFile )
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the native library is loaded.
|
* Returns whether the native library is loaded.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -120,6 +133,16 @@ public class NativeLibrary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean loadLibraryFromFile( File libraryFile ) {
|
||||||
|
try {
|
||||||
|
System.load( libraryFile.getPath() );
|
||||||
|
return true;
|
||||||
|
} catch( Throwable ex ) {
|
||||||
|
log( null, ex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String decorateLibraryName( String libraryName ) {
|
private static String decorateLibraryName( String libraryName ) {
|
||||||
if( SystemInfo.isWindows )
|
if( SystemInfo.isWindows )
|
||||||
return libraryName.concat( ".dll" );
|
return libraryName.concat( ".dll" );
|
||||||
|
|||||||
Reference in New Issue
Block a user