KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jsch > internal > ui > preference > 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  * Atsuhiko Yamanaka, JCraft,Inc. - Bug 170883
11  *******************************************************************************/

12 package org.eclipse.jsch.internal.ui.preference;
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.swt.graphics.FontMetrics;
16 import org.eclipse.swt.graphics.GC;
17 import org.eclipse.swt.widgets.Control;
18
19 public class PixelConverter {
20     
21     private final FontMetrics fFontMetrics;
22     
23     public PixelConverter(Control control) {
24         GC gc = new GC(control);
25         try {
26             gc.setFont(control.getFont());
27             fFontMetrics= gc.getFontMetrics();
28         } finally {
29             gc.dispose();
30         }
31     }
32     
33     public int convertHeightInCharsToPixels(int chars) {
34         return Dialog.convertHeightInCharsToPixels(fFontMetrics, chars);
35     }
36
37     public int convertHorizontalDLUsToPixels(int dlus) {
38         return Dialog.convertHorizontalDLUsToPixels(fFontMetrics, dlus);
39     }
40
41     public int convertVerticalDLUsToPixels(int dlus) {
42         return Dialog.convertVerticalDLUsToPixels(fFontMetrics, dlus);
43     }
44     
45     public int convertWidthInCharsToPixels(int chars) {
46         return Dialog.convertWidthInCharsToPixels(fFontMetrics, chars);
47     }
48 }
49
Popular Tags