KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > util > PixelConverter


1 /*******************************************************************************
2  * Copyright (c) 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.ltk.internal.ui.refactoring.util;
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  * Utility class for pixel-related functions.
21  */

22 public final class PixelConverter {
23
24     private FontMetrics fFontMetrics;
25
26     public PixelConverter(Control control) {
27         GC gc= null;
28         try {
29             gc= new GC(control);
30             gc.setFont(control.getFont());
31             fFontMetrics= gc.getFontMetrics();
32         } finally {
33             if (gc != null)
34                 gc.dispose();
35         }
36     }
37
38     public int convertHeightInCharsToPixels(int chars) {
39         return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
40     }
41
42     public int convertHorizontalDLUsToPixels(int dlus) {
43         return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
44     }
45
46     public int convertVerticalDLUsToPixels(int dlus) {
47         return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
48     }
49
50     public int convertWidthInCharsToPixels(int chars) {
51         return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
52     }
53 }
Popular Tags