01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.texteditor;
11:
12: import org.eclipse.swt.graphics.FontMetrics;
13: import org.eclipse.swt.graphics.GC;
14: import org.eclipse.swt.widgets.Control;
15:
16: import org.eclipse.jface.dialogs.Dialog;
17:
18: /**
19: * Helper class to convert from various
20: * dimensions into pixels.
21: *
22: * @since 3.3
23: */
24: public class PixelConverter {
25:
26: private FontMetrics fFontMetrics;
27:
28: public PixelConverter(Control control) {
29: GC gc = new GC(control);
30: gc.setFont(control.getFont());
31: fFontMetrics = gc.getFontMetrics();
32: gc.dispose();
33: }
34:
35: /*
36: * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
37: */
38: public int convertHeightInCharsToPixels(int chars) {
39: return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
40: }
41:
42: /*
43: * @see org.eclipse.jface.dialogs.DialogPage#convertHorizontalDLUsToPixels(int)
44: */
45: public int convertHorizontalDLUsToPixels(int dlus) {
46: return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
47: }
48:
49: /*
50: * see org.eclipse.jface.dialogs.DialogPage#convertVerticalDLUsToPixels(int)
51: */
52: public int convertVerticalDLUsToPixels(int dlus) {
53: return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
54: }
55:
56: /*
57: * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
58: */
59: public int convertWidthInCharsToPixels(int chars) {
60: return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
61: }
62:
63: }
|