471341: [Draw2d] FigureUtilities#setFont does not check for disposed
Fonts
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=471341
diff --git a/bundles/org.eclipse.rap.draw2d.compatibility/src/org/eclipse/draw2d/rap/swt/graphics/ColorUtil.java b/bundles/org.eclipse.rap.draw2d.compatibility/src/org/eclipse/draw2d/rap/swt/graphics/ColorUtil.java
index 76a8dc9..3979a11 100644
--- a/bundles/org.eclipse.rap.draw2d.compatibility/src/org/eclipse/draw2d/rap/swt/graphics/ColorUtil.java
+++ b/bundles/org.eclipse.rap.draw2d.compatibility/src/org/eclipse/draw2d/rap/swt/graphics/ColorUtil.java
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2015.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+
+ * Contributors:
+ * Arnaud Mergey - initial API and implementation
+*******************************************************************************/
package org.eclipse.draw2d.rap.swt.graphics;
import java.text.MessageFormat;
@@ -26,4 +36,4 @@
public static Color getColor( int rgb ) {
return getColor( rgb, rgb, rgb );
}
-}
+}
\ No newline at end of file
diff --git a/bundles/org.eclipse.rap.draw2d/src/org/eclipse/draw2d/FigureUtilities.java b/bundles/org.eclipse.rap.draw2d/src/org/eclipse/draw2d/FigureUtilities.java
index 7857e6e..b05ed74 100644
--- a/bundles/org.eclipse.rap.draw2d/src/org/eclipse/draw2d/FigureUtilities.java
+++ b/bundles/org.eclipse.rap.draw2d/src/org/eclipse/draw2d/FigureUtilities.java
@@ -12,16 +12,15 @@
import java.util.ArrayList;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.draw2d.rap.swt.graphics.ColorUtil;
+import org.eclipse.rap.rwt.SingletonUtil;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.draw2d.rap.swt.graphics.ColorUtil;
-import org.eclipse.jface.resource.JFaceResources;
/**
* Provides miscellaneous Figure operations.
@@ -29,15 +28,19 @@
public class FigureUtilities {
private static final float RGB_VALUE_MULTIPLIER = 0.6f;
- private static GC gc;
- private static Font appliedFont;
- private static FontMetrics metrics;
//[RAP AM] remove static usage
+ private GC gc;
+ private Font appliedFont;
+ private FontMetrics metrics;
//private static Color ghostFillColor = new Color(null, 31, 31, 31);
private static Color ghostFillColor() {
return ColorUtil.getColor( 31, 31, 31 );
}
+ private static FigureUtilities instance() {
+ return SingletonUtil.getSessionInstance( FigureUtilities.class );
+ }
+
/**
* Returns a new Color the same as the passed color in a darker hue.
*
@@ -63,9 +66,10 @@
*/
public static FontMetrics getFontMetrics(Font f) {
setFont(f);
- if (metrics == null)
- metrics = getGC().getFontMetrics();
- return metrics;
+ FigureUtilities fu = instance();
+ if (fu.metrics == null)
+ fu.metrics = getGC().getFontMetrics();
+ return fu.metrics;
}
/**
@@ -76,11 +80,12 @@
* @return the GC
*/
protected static GC getGC() {
- if (gc == null) {
- gc = new GC(new Shell());
- appliedFont = gc.getFont();
+ FigureUtilities fu = instance();
+ if (fu.gc == null) {
+ fu.gc = new GC(new Shell());
+ fu.appliedFont = fu.gc.getFont();
}
- return gc;
+ return fu.gc;
}
/**
@@ -364,11 +369,12 @@
* @since 2.0
*/
protected static void setFont(Font f) {
- if (appliedFont == f || (f != null && f.equals(appliedFont)))
+ FigureUtilities fu = instance();
+ if (fu.appliedFont == f || (f != null && f.equals(fu.appliedFont)))
return;
getGC().setFont(f);
- appliedFont = f;
- metrics = null;
+ fu.appliedFont = f;
+ fu.metrics = null;
}
/**