DesktopPane: on HiDPI screens, use high-resolution images for preview of iconified internal frames in dock

This commit is contained in:
Karl Tauber
2021-04-10 14:36:46 +02:00
parent a331760321
commit 07bf6e4506
2 changed files with 29 additions and 3 deletions

View File

@@ -8,7 +8,7 @@ FlatLaf Change Log
- Button and ToggleButton: Support borderless button style (set client property - Button and ToggleButton: Support borderless button style (set client property
`JButton.buttonType` to `borderless`). (PR #276) `JButton.buttonType` to `borderless`). (PR #276)
- DesktopPane: Improved layout of iconified internal frames in dock: - DesktopPane: Improved layout of iconified internal frames in dock:
- Always placed in bottom left of desktop pane. - Always placed at bottom-left in desktop pane.
- Newly iconified frames are added to the right side of the dock. - Newly iconified frames are added to the right side of the dock.
- If frame is deiconified, dock is compacted (icons move to the left). - If frame is deiconified, dock is compacted (icons move to the left).
- If dock is wider than desktop width, additional rows are used. - If dock is wider than desktop width, additional rows are used.
@@ -17,8 +17,12 @@ FlatLaf Change Log
#### Fixed bugs #### Fixed bugs
- DesktopPane: - DesktopPane:
- Fixed empty minimized icon when using a custom desktop manager. (PR #294) - Fixed missing preview of iconified internal frames in dock when using a
- Fixed incomplete minimized icon when switching LaF. custom desktop manager. (PR #294)
- Fixed incomplete preview of iconified internal frames in dock when switching
LaF.
- On HiDPI screens, use high-resolution images for preview of iconified
internal frames in dock.
## 1.1.2 ## 1.1.2

View File

@@ -45,6 +45,7 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicDesktopIconUI; import javax.swing.plaf.basic.BasicDesktopIconUI;
import com.formdev.flatlaf.util.MultiResolutionImageSupport;
import com.formdev.flatlaf.util.UIScale; import com.formdev.flatlaf.util.UIScale;
/** /**
@@ -279,6 +280,27 @@ public class FlatDesktopIconUI
// scale preview // scale preview
Image previewImage = frameImage.getScaledInstance( previewWidth, previewHeight, Image.SCALE_SMOOTH ); Image previewImage = frameImage.getScaledInstance( previewWidth, previewHeight, Image.SCALE_SMOOTH );
if( MultiResolutionImageSupport.isAvailable() ) {
// On HiDPI screens, create preview images for 1x, 2x and current scale factor.
// The icon then chooses the best resolution for painting, which is usually
// the one for the current scale factor. But if changing scale factor or
// moving window to another screen with different scale factor, then another
// resolution may be used because the preview icon is not updated.
Image previewImage2x = frameImage.getScaledInstance( previewWidth * 2, previewHeight * 2, Image.SCALE_SMOOTH );
double scaleFactor = UIScale.getSystemScaleFactor( desktopIcon.getGraphicsConfiguration() );
if( scaleFactor != 1 && scaleFactor != 2 ) {
Image previewImageCurrent = frameImage.getScaledInstance(
(int) Math.round( previewWidth * scaleFactor ),
(int) Math.round( previewHeight * scaleFactor ),
Image.SCALE_SMOOTH );
// the images must be ordered by resolution
previewImage = (scaleFactor < 2)
? MultiResolutionImageSupport.create( 0, previewImage, previewImageCurrent, previewImage2x )
: MultiResolutionImageSupport.create( 0, previewImage, previewImage2x, previewImageCurrent );
} else
previewImage = MultiResolutionImageSupport.create( 0, previewImage, previewImage2x );
}
dockIcon.setIcon( new ImageIcon( previewImage ) ); dockIcon.setIcon( new ImageIcon( previewImage ) );
} }