KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > util > PixelConverter


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.jdt.internal.ui.util;
12
13 import org.eclipse.swt.graphics.Font;
14 import org.eclipse.swt.graphics.FontMetrics;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.widgets.Control;
17
18 import org.eclipse.jface.dialogs.Dialog;
19
20 public class PixelConverter {
21     
22     private final FontMetrics fFontMetrics;
23     
24     public PixelConverter(Control control) {
25         this(control.getFont());
26     }
27     
28     public PixelConverter(Font font) {
29         GC gc = new GC(font.getDevice());
30         gc.setFont(font);
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 }
64
Popular Tags