Bug 574400 - ModifyDialog$FocusManager leaks Font

- change ModifyDialog.FocusManager.changeFont() method to
  add DisposeListener to the control to dispose of the new
  Font created

Change-Id: Ia0d0dd0c97604803692522d78b008e12c0a7fb30
Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/182479
Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Tested-by: JDT Bot <jdt-bot@eclipse.org>
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java
index 21755d7..20bded4 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/formatter/ModifyDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -1127,7 +1127,10 @@
 			Display.getCurrent().asyncExec(() -> {
 				FontData fd= control.getFont().getFontData()[0];
 				int style= italic ? (fd.getStyle() | SWT.ITALIC) : (fd.getStyle() & ~SWT.ITALIC);
-				control.setFont(new Font(control.getDisplay(), new FontData(fd.getName(), fd.getHeight(), style)));
+				FontData fontData= new FontData(fd.getName(), fd.getHeight(), style);
+				Font font= new Font(control.getDisplay(), fontData);
+				control.addDisposeListener(e -> font.dispose());
+				control.setFont(font);
 				if (control instanceof Composite)
 					((Composite) control).layout();
 			});