1 11 package org.eclipse.ltk.internal.ui.refactoring.util; 12 13 import org.eclipse.swt.graphics.FontMetrics; 14 import org.eclipse.swt.graphics.GC; 15 import org.eclipse.swt.widgets.Control; 16 17 import org.eclipse.jface.dialogs.Dialog; 18 19 22 public final class PixelConverter { 23 24 private FontMetrics fFontMetrics; 25 26 public PixelConverter(Control control) { 27 GC gc= null; 28 try { 29 gc= new GC(control); 30 gc.setFont(control.getFont()); 31 fFontMetrics= gc.getFontMetrics(); 32 } finally { 33 if (gc != null) 34 gc.dispose(); 35 } 36 } 37 38 public int convertHeightInCharsToPixels(int chars) { 39 return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars); 40 } 41 42 public int convertHorizontalDLUsToPixels(int dlus) { 43 return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus); 44 } 45 46 public int convertVerticalDLUsToPixels(int dlus) { 47 return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus); 48 } 49 50 public int convertWidthInCharsToPixels(int chars) { 51 return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars); 52 } 53 } | Popular Tags |