KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > texteditor > PixelConverter


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.texteditor;
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
20 /**
21  * Helper class to convert from various
22  * dimensions into pixels.
23  *
24  * @since 3.3
25  */

26 public class PixelConverter {
27     
28     private FontMetrics fFontMetrics;
29     
30     public PixelConverter(Control control) {
31         GC gc = new GC(control);
32         gc.setFont(control.getFont());
33         fFontMetrics= gc.getFontMetrics();
34         gc.dispose();
35     }
36
37     /*
38      * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
39      */

40     public int convertHeightInCharsToPixels(int chars) {
41         return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
42     }
43
44     /*
45      * @see org.eclipse.jface.dialogs.DialogPage#convertHorizontalDLUsToPixels(int)
46      */

47     public int convertHorizontalDLUsToPixels(int dlus) {
48         return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
49     }
50
51     /*
52      * see org.eclipse.jface.dialogs.DialogPage#convertVerticalDLUsToPixels(int)
53      */

54     public int convertVerticalDLUsToPixels(int dlus) {
55         return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
56     }
57     
58     /*
59      * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
60      */

61     public int convertWidthInCharsToPixels(int chars) {
62         return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
63     }
64
65 }
66
Popular Tags