mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-09 16:25:10 +03:00
fixed memory leak in Panel, Separator and ToolBarSeparator (issue #471)
This commit is contained in:
@@ -1,6 +1,11 @@
|
|||||||
FlatLaf Change Log
|
FlatLaf Change Log
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
## 2.0.1-SNAPSHOT
|
||||||
|
|
||||||
|
- Fixed memory leak in Panel, Separator and ToolBarSeparator. (issue #471)
|
||||||
|
|
||||||
|
|
||||||
## 2.0
|
## 2.0
|
||||||
|
|
||||||
- Added system property `flatlaf.nativeLibraryPath` to load native libraries
|
- Added system property `flatlaf.nativeLibraryPath` to load native libraries
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
val releaseVersion = "2.0"
|
val releaseVersion = "2.0"
|
||||||
val developmentVersion = "2.1-SNAPSHOT"
|
val developmentVersion = "2.0.1-SNAPSHOT"
|
||||||
|
|
||||||
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
version = if( java.lang.Boolean.getBoolean( "release" ) ) releaseVersion else developmentVersion
|
||||||
|
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ package com.formdev.flatlaf.ui;
|
|||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicPanelUI;
|
import javax.swing.plaf.basic.BasicPanelUI;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
@@ -43,13 +45,12 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
*/
|
*/
|
||||||
public class FlatPanelUI
|
public class FlatPanelUI
|
||||||
extends BasicPanelUI
|
extends BasicPanelUI
|
||||||
implements StyleableUI
|
implements StyleableUI, PropertyChangeListener
|
||||||
{
|
{
|
||||||
// only used via styling (not in UI defaults)
|
// only used via styling (not in UI defaults)
|
||||||
/** @since 2 */ @Styleable protected int arc = -1;
|
/** @since 2 */ @Styleable protected int arc = -1;
|
||||||
|
|
||||||
private final boolean shared;
|
private final boolean shared;
|
||||||
private PropertyChangeListener propertyChangeListener;
|
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -67,9 +68,7 @@ public class FlatPanelUI
|
|||||||
public void installUI( JComponent c ) {
|
public void installUI( JComponent c ) {
|
||||||
super.installUI( c );
|
super.installUI( c );
|
||||||
|
|
||||||
propertyChangeListener = FlatStylingSupport.createPropertyChangeListener(
|
c.addPropertyChangeListener( this );
|
||||||
c, () -> stylePropertyChange( (JPanel) c ), null );
|
|
||||||
c.addPropertyChangeListener( propertyChangeListener );
|
|
||||||
|
|
||||||
installStyle( (JPanel) c );
|
installStyle( (JPanel) c );
|
||||||
}
|
}
|
||||||
@@ -78,21 +77,28 @@ public class FlatPanelUI
|
|||||||
public void uninstallUI( JComponent c ) {
|
public void uninstallUI( JComponent c ) {
|
||||||
super.uninstallUI( c );
|
super.uninstallUI( c );
|
||||||
|
|
||||||
c.removePropertyChangeListener( propertyChangeListener );
|
c.removePropertyChangeListener( this );
|
||||||
propertyChangeListener = null;
|
|
||||||
|
|
||||||
oldStyleValues = null;
|
oldStyleValues = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stylePropertyChange( JPanel c ) {
|
/** @since 2.0.1 */
|
||||||
if( shared && FlatStylingSupport.hasStyleProperty( c ) ) {
|
@Override
|
||||||
// unshare component UI if necessary
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
// updateUI() invokes installStyle() from installUI()
|
switch( e.getPropertyName() ) {
|
||||||
c.updateUI();
|
case FlatClientProperties.STYLE:
|
||||||
} else
|
case FlatClientProperties.STYLE_CLASS:
|
||||||
installStyle( c );
|
JPanel c = (JPanel) e.getSource();
|
||||||
c.revalidate();
|
if( shared && FlatStylingSupport.hasStyleProperty( c ) ) {
|
||||||
c.repaint();
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes installStyle() from installUI()
|
||||||
|
c.updateUI();
|
||||||
|
} else
|
||||||
|
installStyle( c );
|
||||||
|
c.revalidate();
|
||||||
|
c.repaint();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -28,6 +29,7 @@ import javax.swing.JSeparator;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicSeparatorUI;
|
import javax.swing.plaf.basic.BasicSeparatorUI;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
@@ -50,7 +52,7 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
*/
|
*/
|
||||||
public class FlatSeparatorUI
|
public class FlatSeparatorUI
|
||||||
extends BasicSeparatorUI
|
extends BasicSeparatorUI
|
||||||
implements StyleableUI
|
implements StyleableUI, PropertyChangeListener
|
||||||
{
|
{
|
||||||
@Styleable protected int height;
|
@Styleable protected int height;
|
||||||
@Styleable protected int stripeWidth;
|
@Styleable protected int stripeWidth;
|
||||||
@@ -58,7 +60,6 @@ public class FlatSeparatorUI
|
|||||||
|
|
||||||
private final boolean shared;
|
private final boolean shared;
|
||||||
private boolean defaults_initialized = false;
|
private boolean defaults_initialized = false;
|
||||||
private PropertyChangeListener propertyChangeListener;
|
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -109,28 +110,33 @@ public class FlatSeparatorUI
|
|||||||
protected void installListeners( JSeparator s ) {
|
protected void installListeners( JSeparator s ) {
|
||||||
super.installListeners( s );
|
super.installListeners( s );
|
||||||
|
|
||||||
propertyChangeListener = FlatStylingSupport.createPropertyChangeListener(
|
s.addPropertyChangeListener( this );
|
||||||
s, () -> stylePropertyChange( s ), null );
|
|
||||||
s.addPropertyChangeListener( propertyChangeListener );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void uninstallListeners( JSeparator s ) {
|
protected void uninstallListeners( JSeparator s ) {
|
||||||
super.uninstallListeners( s );
|
super.uninstallListeners( s );
|
||||||
|
|
||||||
s.removePropertyChangeListener( propertyChangeListener );
|
s.removePropertyChangeListener( this );
|
||||||
propertyChangeListener = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stylePropertyChange( JSeparator s ) {
|
/** @since 2.0.1 */
|
||||||
if( shared && FlatStylingSupport.hasStyleProperty( s ) ) {
|
@Override
|
||||||
// unshare component UI if necessary
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
// updateUI() invokes installStyle() from installUI()
|
switch( e.getPropertyName() ) {
|
||||||
s.updateUI();
|
case FlatClientProperties.STYLE:
|
||||||
} else
|
case FlatClientProperties.STYLE_CLASS:
|
||||||
installStyle( s );
|
JSeparator s = (JSeparator) e.getSource();
|
||||||
s.revalidate();
|
if( shared && FlatStylingSupport.hasStyleProperty( s ) ) {
|
||||||
s.repaint();
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes installStyle() from installUI()
|
||||||
|
s.updateUI();
|
||||||
|
} else
|
||||||
|
installStyle( s );
|
||||||
|
s.revalidate();
|
||||||
|
s.repaint();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -31,6 +32,7 @@ import javax.swing.SwingConstants;
|
|||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.basic.BasicToolBarSeparatorUI;
|
import javax.swing.plaf.basic.BasicToolBarSeparatorUI;
|
||||||
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
|
||||||
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
import com.formdev.flatlaf.ui.FlatStylingSupport.StyleableUI;
|
||||||
import com.formdev.flatlaf.util.LoggingFacade;
|
import com.formdev.flatlaf.util.LoggingFacade;
|
||||||
@@ -47,7 +49,7 @@ import com.formdev.flatlaf.util.LoggingFacade;
|
|||||||
*/
|
*/
|
||||||
public class FlatToolBarSeparatorUI
|
public class FlatToolBarSeparatorUI
|
||||||
extends BasicToolBarSeparatorUI
|
extends BasicToolBarSeparatorUI
|
||||||
implements StyleableUI
|
implements StyleableUI, PropertyChangeListener
|
||||||
{
|
{
|
||||||
private static final int LINE_WIDTH = 1;
|
private static final int LINE_WIDTH = 1;
|
||||||
|
|
||||||
@@ -56,7 +58,6 @@ public class FlatToolBarSeparatorUI
|
|||||||
|
|
||||||
private final boolean shared;
|
private final boolean shared;
|
||||||
private boolean defaults_initialized = false;
|
private boolean defaults_initialized = false;
|
||||||
private PropertyChangeListener propertyChangeListener;
|
|
||||||
private Map<String, Object> oldStyleValues;
|
private Map<String, Object> oldStyleValues;
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
@@ -105,28 +106,33 @@ public class FlatToolBarSeparatorUI
|
|||||||
protected void installListeners( JSeparator s ) {
|
protected void installListeners( JSeparator s ) {
|
||||||
super.installListeners( s );
|
super.installListeners( s );
|
||||||
|
|
||||||
propertyChangeListener = FlatStylingSupport.createPropertyChangeListener(
|
s.addPropertyChangeListener( this );
|
||||||
s, () -> stylePropertyChange( s ), null );
|
|
||||||
s.addPropertyChangeListener( propertyChangeListener );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void uninstallListeners( JSeparator s ) {
|
protected void uninstallListeners( JSeparator s ) {
|
||||||
super.uninstallListeners( s );
|
super.uninstallListeners( s );
|
||||||
|
|
||||||
s.removePropertyChangeListener( propertyChangeListener );
|
s.removePropertyChangeListener( this );
|
||||||
propertyChangeListener = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stylePropertyChange( JSeparator s ) {
|
/** @since 2.0.1 */
|
||||||
if( shared && FlatStylingSupport.hasStyleProperty( s ) ) {
|
@Override
|
||||||
// unshare component UI if necessary
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
// updateUI() invokes installStyle() from installUI()
|
switch( e.getPropertyName() ) {
|
||||||
s.updateUI();
|
case FlatClientProperties.STYLE:
|
||||||
} else
|
case FlatClientProperties.STYLE_CLASS:
|
||||||
installStyle( s );
|
JSeparator s = (JSeparator) e.getSource();
|
||||||
s.revalidate();
|
if( shared && FlatStylingSupport.hasStyleProperty( s ) ) {
|
||||||
s.repaint();
|
// unshare component UI if necessary
|
||||||
|
// updateUI() invokes installStyle() from installUI()
|
||||||
|
s.updateUI();
|
||||||
|
} else
|
||||||
|
installStyle( s );
|
||||||
|
s.revalidate();
|
||||||
|
s.repaint();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.awt.FontMetrics;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
@@ -49,9 +50,8 @@ import com.formdev.flatlaf.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
public class FlatToolTipUI
|
public class FlatToolTipUI
|
||||||
extends BasicToolTipUI
|
extends BasicToolTipUI
|
||||||
|
implements PropertyChangeListener
|
||||||
{
|
{
|
||||||
private static PropertyChangeListener sharedPropertyChangedListener;
|
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return FlatUIUtils.createSharedUI( FlatToolTipUI.class, FlatToolTipUI::new );
|
return FlatUIUtils.createSharedUI( FlatToolTipUI.class, FlatToolTipUI::new );
|
||||||
}
|
}
|
||||||
@@ -68,24 +68,24 @@ public class FlatToolTipUI
|
|||||||
protected void installListeners( JComponent c ) {
|
protected void installListeners( JComponent c ) {
|
||||||
super.installListeners( c );
|
super.installListeners( c );
|
||||||
|
|
||||||
if( sharedPropertyChangedListener == null ) {
|
c.addPropertyChangeListener( this );
|
||||||
sharedPropertyChangedListener = e -> {
|
|
||||||
String name = e.getPropertyName();
|
|
||||||
if( name == "tiptext" || name == "font" || name == "foreground" ) {
|
|
||||||
JToolTip toolTip = (JToolTip) e.getSource();
|
|
||||||
FlatLabelUI.updateHTMLRenderer( toolTip, toolTip.getTipText(), false );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
c.addPropertyChangeListener( sharedPropertyChangedListener );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void uninstallListeners( JComponent c ) {
|
protected void uninstallListeners( JComponent c ) {
|
||||||
super.uninstallListeners( c );
|
super.uninstallListeners( c );
|
||||||
|
|
||||||
c.removePropertyChangeListener( sharedPropertyChangedListener );
|
c.removePropertyChangeListener( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @since 2.0.1 */
|
||||||
|
@Override
|
||||||
|
public void propertyChange( PropertyChangeEvent e ) {
|
||||||
|
String name = e.getPropertyName();
|
||||||
|
if( name == "tiptext" || name == "font" || name == "foreground" ) {
|
||||||
|
JToolTip toolTip = (JToolTip) e.getSource();
|
||||||
|
FlatLabelUI.updateHTMLRenderer( toolTip, toolTip.getTipText(), false );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user