diff options
author | Lakshmi Shanmugam | 2018-03-07 08:49:26 +0000 |
---|---|---|
committer | Lakshmi Shanmugam | 2018-03-07 12:44:29 +0000 |
commit | 7d9906cffbafce82f51535ea889a3ff0b63eafe1 (patch) | |
tree | 6173dfa95d38e5393dae06108569821ddb9237c4 /examples | |
parent | b6dae09ffe8e33c280e9b64df56de266f919bf7f (diff) | |
download | eclipse.platform.swt-7d9906cffbafce82f51535ea889a3ff0b63eafe1.tar.gz eclipse.platform.swt-7d9906cffbafce82f51535ea889a3ff0b63eafe1.tar.xz eclipse.platform.swt-7d9906cffbafce82f51535ea889a3ff0b63eafe1.zip |
Bug 532063: Replace calls to getAverageCharWidth() withI20180307-0800
getAverageCharacterWidth() in SWT
Update snippets and examples with the new API
Change-Id: I68a61091f07c60978f60e99f1fd76da2b51537e9
Diffstat (limited to 'examples')
6 files changed, 9 insertions, 8 deletions
diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableColumn.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableColumn.java index 37723c1880..f4dfea85fd 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableColumn.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableColumn.java @@ -228,7 +228,7 @@ void computeDisplayText (GC gc) { } /* Make initial guess. */ - int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ()); + int index = (int) Math.min (availableWidth / gc.getFontMetrics ().getAverageCharacterWidth (), text.length ()); textWidth = gc.textExtent (text.substring (0, index), SWT.DRAW_MNEMONIC).x; /* Initial guess is correct. */ diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableItem.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableItem.java index 6a637033bd..3d59c6b418 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableItem.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/accessibility/CTableItem.java @@ -332,7 +332,7 @@ void computeDisplayText (int columnIndex, GC gc) { } /* Make initial guess. */ - int index = Math.min (availableWidth / gc.getFontMetrics ().getAverageCharWidth (), text.length ()); + int index = (int) Math.min (availableWidth / gc.getFontMetrics ().getAverageCharacterWidth (), text.length ()); textWidth = gc.stringExtent (text.substring (0, index)).x; /* Initial guess is correct. */ diff --git a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java index 198c475034..e224a4dcb2 100644 --- a/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java +++ b/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/graphics/ImageTransformTab.java @@ -76,7 +76,7 @@ public void createControlPanel(Composite parent) { new Label(comp, SWT.CENTER).setText(GraphicsExample.getResourceString("Rotate")); //$NON-NLS-1$ rotateSpinner = new Spinner(comp, SWT.BORDER | SWT.WRAP); GC gc = new GC(rotateSpinner); - int width = gc.getFontMetrics().getAverageCharWidth() * 5; + int width = (int) (gc.getFontMetrics().getAverageCharacterWidth() * 5); gc.dispose(); rotateSpinner.setLayoutData(new GridData(width, SWT.DEFAULT)); rotateSpinner.setSelection(0); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java index b375eaeec6..9bcd89e596 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet363.java @@ -44,7 +44,7 @@ public static void main(String [] args) { GC gc = new GC(liveLabel); Point pt = gc.textExtent(errorMessage); GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false); - data.minimumWidth = pt.x + gc.getFontMetrics().getAverageCharWidth() * 2; + data.minimumWidth = (int) (pt.x + gc.getFontMetrics().getAverageCharacterWidth() * 2); gc.dispose(); liveLabel.setLayoutData(data); liveLabel.setText(""); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java index 30f1c77c58..4a9d58d339 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet55.java @@ -26,12 +26,13 @@ public static void main (String [] args) { Display display = new Display (); Shell shell = new Shell (display); Text text = new Text (shell, SWT.BORDER); + text.setFont (new Font (display, "Courier", 13, SWT.NORMAL)); // Use a fixed size font Rectangle clientArea = shell.getClientArea (); text.setLocation (clientArea.x, clientArea.y); int columns = 10; GC gc = new GC (text); FontMetrics fm = gc.getFontMetrics (); - int width = columns * fm.getAverageCharWidth (); + int width = (int) (columns * fm.getAverageCharacterWidth ()); int height = fm.getHeight (); gc.dispose (); text.setSize (text.computeSize (width, height)); diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java index 11d434b3c6..56d9dbec78 100644 --- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet69.java @@ -18,8 +18,8 @@ package org.eclipse.swt.snippets; */ import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; public class Snippet69 { @@ -36,8 +36,8 @@ public static void main (String [] args) { GC gc = new GC (text); FontMetrics fm = gc.getFontMetrics (); - int charWidth = fm.getAverageCharWidth (); - int width = text.computeSize (charWidth * 8, SWT.DEFAULT).x; + double charWidth = fm.getAverageCharacterWidth (); + int width = text.computeSize ((int) (charWidth * 8), SWT.DEFAULT).x; gc.dispose (); FormData data = new FormData (width, SWT.DEFAULT); text.setLayoutData (data); |