KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.pde.internal.ui.util;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.swt.graphics.FontMetrics;
15 import org.eclipse.swt.graphics.GC;
16 import org.eclipse.swt.widgets.Control;
17
18 public class PixelConverter {
19     
20     private FontMetrics fFontMetrics;
21     
22     public PixelConverter(Control control) {
23         GC gc = new GC(control);
24         gc.setFont(control.getFont());
25         fFontMetrics= gc.getFontMetrics();
26         gc.dispose();
27     }
28     
29         
30     /**
31      * @see DialogPage#convertHeightInCharsToPixels
32      */

33     public int convertHeightInCharsToPixels(int chars) {
34         return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
35     }
36
37     /**
38      * @see DialogPage#convertHorizontalDLUsToPixels
39      */

40     public int convertHorizontalDLUsToPixels(int dlus) {
41         return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
42     }
43
44     /**
45      * @see DialogPage#convertVerticalDLUsToPixels
46      */

47     public int convertVerticalDLUsToPixels(int dlus) {
48         return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
49     }
50     
51     /**
52      * @see DialogPage#convertWidthInCharsToPixels
53      */

54     public int convertWidthInCharsToPixels(int chars) {
55         return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
56     }
57
58 }
59
60
Popular Tags