From 00d1c880696cd9b9b88655d064c1aba3cf5b0502 Mon Sep 17 00:00:00 2001 From: Christian W. Damus Date: Wed, 26 Mar 2014 12:51:25 -0400 Subject: 392301: Colors are leaked https://bugs.eclipse.org/bugs/show_bug.cgi?id=392301 Fix leaked SWT colours by caching frequently-used colours (especially for gradients) in GMF's ColorRegistry, which in GMF also is used for gradient painting. --- .../css/configuration/handler/AbstractStyleDialog.java | 8 +++++--- .../papyrus/infra/gmfdiag/css/debug/views/CSSDebugView.java | 7 +++++-- .../infra/gmfdiag/css/converters/ColorToGMFConverter.java | 12 +++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) (limited to 'plugins/infra/gmfdiag/css') diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleDialog.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleDialog.java index d377eadece7..1129c431c78 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleDialog.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleDialog.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012 CEA LIST. + * Copyright (c) 2012, 2014 CEA LIST and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,8 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 392301 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.css.configuration.handler; @@ -17,7 +19,7 @@ import java.util.Map; import java.util.Map.Entry; import org.eclipse.e4.ui.css.core.css2.CSS2ColorHelper; -import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; +import org.eclipse.gmf.runtime.draw2d.ui.graphics.ColorRegistry; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TrayDialog; @@ -396,7 +398,7 @@ public abstract class AbstractStyleDialog extends TrayDialog { protected Color getColor(HexColor color) { RGBColor rgbColor = CSS2ColorHelper.getRGBColor("#" + color.getValue()); int intColor = ColorToGMFConverter.getIntColor(rgbColor); - return FigureUtilities.integerToColor(intColor); + return ColorRegistry.getInstance().getColor(intColor); } public String getCSSClass() { diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.debug/src/org/eclipse/papyrus/infra/gmfdiag/css/debug/views/CSSDebugView.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.debug/src/org/eclipse/papyrus/infra/gmfdiag/css/debug/views/CSSDebugView.java index aa01aa82e08..54a9b96a181 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.debug/src/org/eclipse/papyrus/infra/gmfdiag/css/debug/views/CSSDebugView.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.debug/src/org/eclipse/papyrus/infra/gmfdiag/css/debug/views/CSSDebugView.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2013, 2014 CEA LIST and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,8 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 392301 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.css.debug.views; @@ -24,6 +26,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; +import org.eclipse.gmf.runtime.draw2d.ui.graphics.ColorRegistry; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; @@ -463,7 +466,7 @@ public class CSSDebugView extends ViewPart implements ISelectionListener, ISelec String text = getValueAsText(feature, value); cell.setText(text); if(feature.getName().endsWith("Color") && value instanceof Integer) { - Color color = FigureUtilities.integerToColor((Integer)value); + Color color = ColorRegistry.getInstance().getColor((Integer)value); cell.setBackground(color); int lightness = getLightness(color); //Use a white font when the color is dark diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/converters/ColorToGMFConverter.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/converters/ColorToGMFConverter.java index e6ee0c28f29..eaa9e63784d 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/converters/ColorToGMFConverter.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/converters/ColorToGMFConverter.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012 CEA LIST. + * Copyright (c) 2012, 2014 CEA LIST and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -8,6 +8,8 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + * Christian W. Damus (CEA) - bug 392301 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.css.converters; @@ -68,11 +70,11 @@ public class ColorToGMFConverter extends AbstractCSSValueConverter { * A GMF-compatible integer color */ public static int getIntColor(RGBColor color) { - int red = getInt(color.getRed()); - int green = getInt(color.getGreen()); - int blue = getInt(color.getBlue()); + int red = getInt(color.getRed()) & 0xFF; + int green = getInt(color.getGreen()) & 0xFF; + int blue = getInt(color.getBlue()) & 0xFF; - return blue * 256 * 256 + green * 256 + red; + return (blue << 16) | (green << 8) | red; } /** -- cgit v1.2.3