From ce64a2d4f82fa4b44a592ad8f0b6026c846d9373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 5 Apr 2024 21:38:36 +0300 Subject: [PATCH] Stop using deprecated FontMetrics.getAverageCharWidth() --- .../eclipse/compare/examples/xml/SWTUtil.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/team/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java b/team/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java index e4120dd0f1d..f8a575eab0a 100644 --- a/team/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java +++ b/team/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/SWTUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2024 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -30,10 +30,10 @@ import org.eclipse.swt.widgets.Widget; /** - * Utility class to simplify access to some SWT resources. + * Utility class to simplify access to some SWT resources. */ public class SWTUtil { - + /* * Returns the standard display to be used. The method first checks, if * the thread calling this method has an associated disaply. If so, this @@ -44,13 +44,13 @@ public static Display getStandardDisplay() { display= Display.getCurrent(); if (display == null) display= Display.getDefault(); - return display; + return display; } - + /* * Returns the shell for the given widget. If the widget doesn't represent * a SWT object that manage a shell, null is returned. - * + * * @return the shell for the given widget */ public static Shell getShell(Widget widget) { @@ -65,10 +65,10 @@ public static Shell getShell(Widget widget) { if (widget instanceof Menu) return ((Menu)widget).getParent().getShell(); if (widget instanceof ScrollBar) - return ((ScrollBar)widget).getParent().getShell(); - return null; + return ((ScrollBar)widget).getParent().getShell(); + return null; } - + private static double getVerticalDialogUnitSize(Control control) { GC gc= new GC(control); try { @@ -78,17 +78,17 @@ private static double getVerticalDialogUnitSize(Control control) { gc.dispose(); } } - + private static double getHorizontalDialogUnitSize(Control control) { GC gc= new GC(control); try { - int averageWidth= gc.getFontMetrics().getAverageCharWidth(); + double averageWidth = gc.getFontMetrics().getAverageCharacterWidth(); return averageWidth * 0.25; } finally { gc.dispose(); } - } - + } + public static int convertHeightInCharsToPixels(int chars, Control control) { return convertVerticalDLUsToPixels(chars * 8, control); } @@ -100,11 +100,11 @@ public static int convertHorizontalDLUsToPixels(int dlus, Control control) { public static int convertVerticalDLUsToPixels(int dlus, Control control) { return (int)Math.round(dlus * getVerticalDialogUnitSize(control)); } - + public static int convertWidthInCharsToPixels(int chars, Control control) { return convertHorizontalDLUsToPixels(chars * 4, control); } - + /* * Returns a width hint for a button control. */ @@ -115,24 +115,24 @@ public static int getButtonWidthHint(Button button) { /* * Returns a height hint for a button control. - */ + */ // public static int getButtonHeigthHint(Button button) { // return convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT, button); -// } +// } /* * Sets width and height hint for the button control. * Note: This is a NOP if the button's layout data is not * an instance of GridData. - * + * * @param the button for which to set the dimension hint - */ + */ public static void setButtonDimensionHint(Button button) { Assert.isNotNull(button); Object gd= button.getLayoutData(); if (gd instanceof GridData) { //((GridData)gd).heightHint= getButtonHeigthHint(button); - ((GridData)gd).widthHint= getButtonWidthHint(button); + ((GridData)gd).widthHint= getButtonWidthHint(button); } } }