From 07bf6e450618f9bd10b5875c8c100f9176ad0b0d Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 10 Apr 2021 14:36:46 +0200 Subject: [PATCH] DesktopPane: on HiDPI screens, use high-resolution images for preview of iconified internal frames in dock --- CHANGELOG.md | 10 ++++++--- .../formdev/flatlaf/ui/FlatDesktopIconUI.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d5420b..aeed11f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ FlatLaf Change Log - Button and ToggleButton: Support borderless button style (set client property `JButton.buttonType` to `borderless`). (PR #276) - 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. - If frame is deiconified, dock is compacted (icons move to the left). - If dock is wider than desktop width, additional rows are used. @@ -17,8 +17,12 @@ FlatLaf Change Log #### Fixed bugs - DesktopPane: - - Fixed empty minimized icon when using a custom desktop manager. (PR #294) - - Fixed incomplete minimized icon when switching LaF. + - Fixed missing preview of iconified internal frames in dock when using a + 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 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDesktopIconUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDesktopIconUI.java index 338a4294..5dda474e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDesktopIconUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatDesktopIconUI.java @@ -45,6 +45,7 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicDesktopIconUI; +import com.formdev.flatlaf.util.MultiResolutionImageSupport; import com.formdev.flatlaf.util.UIScale; /** @@ -279,6 +280,27 @@ public class FlatDesktopIconUI // scale preview 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 ) ); }