KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > PixelConverter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.editors.text;
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  * Pixel conversion utility.
21  *
22  * @since 3.0
23  */

24 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
Popular Tags