-
Notifications
You must be signed in to change notification settings - Fork 2
Adding thumbnails to VisUI FileChooser
FileChooser
can optionally support view mode where images thumbnails are shown. This requires writing custom thumbnail provider, vis-ui-contrib
contains 2 ready to use implementations.
Very fast, very small memory footprint, properly supports all images types. Works on Windows Vista and newer. Requires inlcuding following libraries:
compile "com.kotcrab.vne:vne-runtime:1.0.1"
compile "com.kotcrab.vne:vne-win-thumbnails:1.0.1"
Before creating check if platform is supported:
if (WindowsFileChooserIconProvider.isPlatformSupported()) {
fileChooser.setIconProvider(new WindowsFileChooserIconProvider(chooser));
}
Fast enough for medium size images, reasonable memory footprint but can cause rapid heap grow when generating many thumbnails. After generation heap might not shrunk even though actual memory used is low, this can be fixed by using -XX:MaxHeapFreeRatio=70
. Doesn't support CMYK JPGs correctly out the box (such images will be showed with wrong colors, this is due to JVM lacking proper ICC profiles and can be fixed by using custom library such as CMYKJPEGImageReader
from Monte Media Library). Works on all desktop platforms. Requires including library:
compile "org.imgscalr:imgscalr-lib:4.2"
chooser.setIconProvider(new ImgScalrFileChooserIconProvider(chooser));
To support all platforms you can use this code:
if (WindowsFileChooserIconProvider.isPlatformSupported()) {
chooser.setIconProvider(new WindowsFileChooserIconProvider(chooser));
} else { //fallback to ImgScalrFileChooserIconProvider
chooser.setIconProvider(new ImgScalrFileChooserIconProvider(chooser));
}
Note that you should call dispose()
on IconProvider when your application is shutting down. This will stop thumbnail generation (if it was running) and allow application to terminate much faster.