KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > 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.team.internal.ui;
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 final FontMetrics fFontMetrics;
21     
22     public PixelConverter(Control control) {
23         GC gc = new GC(control);
24         try {
25             gc.setFont(control.getFont());
26             fFontMetrics= gc.getFontMetrics();
27         } finally {
28             gc.dispose();
29         }
30     }
31     
32     public int convertHeightInCharsToPixels(int chars) {
33         return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
34     }
35
36     public int convertHorizontalDLUsToPixels(int dlus) {
37         return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
38     }
39
40     public int convertVerticalDLUsToPixels(int dlus) {
41         return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
42     }
43     
44     public int convertWidthInCharsToPixels(int chars) {
45         return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
46     }
47 }
48
Popular Tags