mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
FileChooser: improved performance when navigating to large directories with thousands of files (issue #953)
This commit is contained in:
@@ -14,6 +14,11 @@ FlatLaf Change Log
|
|||||||
- Extras: `FlatSVGIcon` color filters now can access painting component to
|
- Extras: `FlatSVGIcon` color filters now can access painting component to
|
||||||
implement component state based color mappings. (issue #906)
|
implement component state based color mappings. (issue #906)
|
||||||
|
|
||||||
|
#### Fixed bugs
|
||||||
|
|
||||||
|
- FileChooser: Improved performance when navigating to large directories with
|
||||||
|
thousands of files. (issue #953)
|
||||||
|
|
||||||
|
|
||||||
## 3.5.4
|
## 3.5.4
|
||||||
|
|
||||||
|
|||||||
@@ -376,31 +376,68 @@ public class FlatFileChooserUI
|
|||||||
if( icon != null )
|
if( icon != null )
|
||||||
return icon;
|
return icon;
|
||||||
|
|
||||||
// get system icon
|
// new proxy icon
|
||||||
if( f != null ) {
|
//
|
||||||
try {
|
// Note: Since this is a super light weight icon object, we do not add it
|
||||||
icon = getFileChooser().getFileSystemView().getSystemIcon( f );
|
// to the icon cache here. This keeps cache small in case of large directories
|
||||||
} catch( NullPointerException ex ) {
|
// with thousands of files when icons of all files are only needed to compute
|
||||||
// Java 21 may throw a NPE for exe files that use default Windows exe icon
|
// the layout of list/table, but never painted because located outside of visible area.
|
||||||
}
|
// When an icon needs to be painted, the proxy adds it to the icon cache
|
||||||
|
// and loads the real icon.
|
||||||
|
return new FlatFileViewIcon( f );
|
||||||
|
}
|
||||||
|
|
||||||
if( icon != null ) {
|
//---- class FlatFileViewIcon -----------------------------------------
|
||||||
if( icon instanceof ImageIcon )
|
|
||||||
icon = new ScaledImageIcon( (ImageIcon) icon );
|
/**
|
||||||
cacheIcon( f, icon );
|
* A proxy icon that has a fixed (scaled) width/height (16x16) and
|
||||||
return icon;
|
* gets/loads the real (system) icon only for painting.
|
||||||
}
|
* Avoids unnecessary getting/loading system icons.
|
||||||
|
*/
|
||||||
|
private class FlatFileViewIcon
|
||||||
|
implements Icon
|
||||||
|
{
|
||||||
|
private final File f;
|
||||||
|
private Icon realIcon;
|
||||||
|
|
||||||
|
FlatFileViewIcon( File f ) {
|
||||||
|
this.f = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get default icon
|
@Override
|
||||||
icon = super.getIcon( f );
|
public int getIconWidth() {
|
||||||
|
return UIScale.scale( 16 );
|
||||||
if( icon instanceof ImageIcon ) {
|
|
||||||
icon = new ScaledImageIcon( (ImageIcon) icon );
|
|
||||||
cacheIcon( f, icon );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon;
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return UIScale.scale( 16 );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon( Component c, Graphics g, int x, int y ) {
|
||||||
|
// get icon on demand
|
||||||
|
if( realIcon == null ) {
|
||||||
|
// get system icon
|
||||||
|
try {
|
||||||
|
if( f != null )
|
||||||
|
realIcon = getFileChooser().getFileSystemView().getSystemIcon( f );
|
||||||
|
} catch( NullPointerException ex ) {
|
||||||
|
// Java 21 may throw a NPE for exe files that use default Windows exe icon
|
||||||
|
}
|
||||||
|
|
||||||
|
// get default icon
|
||||||
|
if( realIcon == null )
|
||||||
|
realIcon = FlatFileView.super.getIcon( f );
|
||||||
|
|
||||||
|
if( realIcon instanceof ImageIcon )
|
||||||
|
realIcon = new ScaledImageIcon( (ImageIcon) realIcon );
|
||||||
|
|
||||||
|
cacheIcon( f, this );
|
||||||
|
}
|
||||||
|
|
||||||
|
realIcon.paintIcon( c, g, x, y );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user