From f22862b0a40608db8528921dcbd0da5f4a2bb971 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Mon, 6 Jul 2020 14:41:17 +0200 Subject: [PATCH] InternalFrame: use default icon in internal frames (issue #122) --- CHANGELOG.md | 2 ++ .../flatlaf/ui/FlatInternalFrameTitlePane.java | 13 ++++++++----- .../flatlaf/testing/FlatInternalFrameTest.java | 9 ++++++--- .../flatlaf/testing/FlatInternalFrameTest.jfd | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e0c9c7a..eadb2cfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ FlatLaf Change Log - Hide focus indicator when window is inactive. - Custom window decorations: Improved/fixed window border color in dark themes. - Custom window decorations: Hide window border if window is maximized. +- Custom window decorations: Center title if menu bar is embedded. +- InternalFrame: Use default icon in internal frames. (issue #122) ## 0.37 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameTitlePane.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameTitlePane.java index 52695bbb..fa0913e8 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameTitlePane.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatInternalFrameTitlePane.java @@ -26,13 +26,14 @@ import java.beans.PropertyChangeListener; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.Icon; +import javax.swing.ImageIcon; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.LookAndFeel; -import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.basic.BasicInternalFrameTitlePane; +import com.formdev.flatlaf.util.ScaledImageIcon; import com.formdev.flatlaf.util.UIScale; /** @@ -103,14 +104,16 @@ public class FlatInternalFrameTitlePane add( buttonPanel, BorderLayout.LINE_END ); } - private void updateFrameIcon() { + protected void updateFrameIcon() { Icon frameIcon = frame.getFrameIcon(); - if( frameIcon == UIManager.getIcon( "InternalFrame.icon" ) ) + if( frameIcon != null && (frameIcon.getIconWidth() == 0 || frameIcon.getIconHeight() == 0) ) frameIcon = null; + else if( frameIcon instanceof ImageIcon ) + frameIcon = new ScaledImageIcon( (ImageIcon) frameIcon ); titleLabel.setIcon( frameIcon ); } - private void updateColors() { + protected void updateColors() { Color background = FlatUIUtils.nonUIResource( frame.isSelected() ? selectedTitleColor : notSelectedTitleColor ); Color foreground = FlatUIUtils.nonUIResource( frame.isSelected() ? selectedTextColor : notSelectedTextColor ); @@ -123,7 +126,7 @@ public class FlatInternalFrameTitlePane closeButton.setForeground( foreground ); } - private void updateButtonsVisibility() { + protected void updateButtonsVisibility() { iconButton.setVisible( frame.isIconifiable() ); maxButton.setVisible( frame.isMaximizable() ); closeButton.setVisible( frame.isClosable() ); diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.java index 3e1af100..c80b8677 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.java @@ -7,6 +7,7 @@ package com.formdev.flatlaf.testing; import java.awt.*; import java.beans.PropertyVetoException; import javax.swing.*; +import com.formdev.flatlaf.extras.TriStateCheckBox; import com.formdev.flatlaf.icons.FlatFileViewFloppyDriveIcon; import com.formdev.flatlaf.util.UIScale; import net.miginfocom.swing.*; @@ -50,8 +51,10 @@ public class FlatInternalFrameTest maximizableCheckBox.isSelected(), iconifiableCheckBox.isSelected() ); - if( iconCheckBox.isSelected() ) + if( iconCheckBox.getState() == TriStateCheckBox.State.SELECTED ) internalFrame.setFrameIcon( new FlatFileViewFloppyDriveIcon() ); + else if( iconCheckBox.getState() == TriStateCheckBox.State.UNSELECTED ) + internalFrame.setFrameIcon( null ); if( menuBarCheckBox.isSelected() ) { JMenuBar menuBar = new JMenuBar(); @@ -100,7 +103,7 @@ public class FlatInternalFrameTest closableCheckBox = new JCheckBox(); iconifiableCheckBox = new JCheckBox(); maximizableCheckBox = new JCheckBox(); - iconCheckBox = new JCheckBox(); + iconCheckBox = new TriStateCheckBox(); menuBarCheckBox = new JCheckBox(); titleLabel = new JLabel(); titleField = new JTextField(); @@ -192,7 +195,7 @@ public class FlatInternalFrameTest private JCheckBox closableCheckBox; private JCheckBox iconifiableCheckBox; private JCheckBox maximizableCheckBox; - private JCheckBox iconCheckBox; + private TriStateCheckBox iconCheckBox; private JCheckBox menuBarCheckBox; private JLabel titleLabel; private JTextField titleField; diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.jfd index e8d8bb9b..d9a9a8ef 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatInternalFrameTest.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.2.0.298" Java: "14" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -50,7 +50,7 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 1 1,alignx left,growx 0" } ) - add( new FormComponent( "javax.swing.JCheckBox" ) { + add( new FormComponent( "com.formdev.flatlaf.extras.TriStateCheckBox" ) { name: "iconCheckBox" "text": "Frame icon" }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {