Bug 508133 - Use FontRegistry

It avoids to create/dispose similar Font each time the mouse hovers a
new EditPart

Change-Id: I5faad12396f672bd3355e7a94192003112283d7a
Signed-off-by: Aurelien Pupier <apupier@redhat.com>
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
index 5c3e9a3..39c706c 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButton.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * <copyright>
  *
- * Copyright (c) 2005, 2013 SAP AG.
+ * Copyright (c) 2005, 2016 SAP AG.
  * 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
@@ -15,6 +15,7 @@
  *    fvelasco - Bug 396247 - ImageDescriptor changes
  *    pjpaulin - Bug 352120 - Now uses IDiagramContainerUI interface
  *    fvelasco - Bug 417577 - state call backs review
+ *    apupier - Bug 508133 - Use FontRegistry for Tooltip
  *
  * </copyright>
  *
@@ -655,15 +656,6 @@
 		getContextButtonPad().getContextButtonManagerForPad().hideContextButtonsInstantly();
 	}
 
-	/*
-	 * Introduced to fix bug 373298
-	 */
-	void dispose() {
-		if (tooltip != null) {
-			tooltip.dispose();
-		}
-	}
-
 	/**
 	 * Returns all context button menu entries, which are executable.
 	 * 
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
index 232ea2c..d951d2f 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/contextbuttons/ContextButtonPad.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * <copyright>
  *
- * Copyright (c) 2005, 2013 SAP AG.
+ * Copyright (c) 2005, 2016 SAP AG.
  * 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
@@ -14,6 +14,7 @@
  *    fvelasco - Bug 396247 - ImageDescriptor changes
  *    mwenz - Bug 397303 - Accessibility issue with Graphiti diagram in High Contrast Mode
  *    pjpaulin - Bug 352120 - Now uses IDiagramContainerUI interface
+ *    apupier - Bug 508133 - Use FontRegistry for Tooltip
  *
  * </copyright>
  *
@@ -549,16 +550,6 @@
 		control.removeMouseTrackListener(mouseTrackListener);
 
 		super.removeNotify();
-
-		// Notify the ContextButton children of this pad to free its resources
-		// (holds a font). Introduced to fix bug 373298
-		List<?> childrenList = getChildren();
-		for (Object object : childrenList) {
-			if (object instanceof ContextButton) {
-				((ContextButton) object).dispose();
-			}
-
-		}
 	}
 
 	// ============================== painting ================================
diff --git a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
index 824d8b0..5ed308c 100644
--- a/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
+++ b/plugins/org.eclipse.graphiti.ui/src/org/eclipse/graphiti/ui/internal/util/draw2d/Tooltip.java
@@ -1,7 +1,7 @@
 /*******************************************************************************
  * <copyright>
  *
- * Copyright (c) 2005, 2012 SAP AG.
+ * Copyright (c) 2005, 2016 SAP AG.
  * 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
@@ -10,6 +10,7 @@
  * Contributors:
  *    SAP AG - initial API, implementation and documentation
  *    mwenz - Bug 373298 - Possible Resource leaks in Graphiti
+ *    apupier - Bug 508133 - Use FontRegistry for Tooltip
  *
  * </copyright>
  *
@@ -22,10 +23,8 @@
 import org.eclipse.draw2d.geometry.Dimension;
 import org.eclipse.draw2d.text.FlowPage;
 import org.eclipse.draw2d.text.TextFlow;
-import org.eclipse.swt.SWT;
+import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.widgets.Display;
 
 /**
  * @noinstantiate This class is not intended to be instantiated by clients.
@@ -36,8 +35,6 @@
 	private static final int TOOLTIP_MAX_WIDTH = 250;
 	private static final Border TOOLTIP_BORDER = new MarginBorder(0, 2, 1, 2);
 
-	private static Font boldFont;
-
 	private TextFlow header;
 	private TextFlow description;
 	private String headerText;
@@ -87,22 +84,7 @@
 		return d;
 	}
 
-	/*
-	 * Introduced to fix bug 373298
-	 */
-	public void dispose() {
-		if (boldFont != null) {
-			boldFont.dispose();
-			boldFont = null;
-		}
-	}
-
 	private Font getBoldFont() {
-		if (boldFont == null) {
-			FontData fd = Display.getDefault().getSystemFont().getFontData()[0];
-			fd.setStyle(fd.getStyle() | SWT.BOLD);
-			boldFont = new Font(Display.getDefault(), fd);
-		}
-		return boldFont;
+		return JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
 	}
 }