View Javadoc

1   /*
2    * $Id: PixelConverter.java,v 1.3 2004/09/13 14:13:26 jlerner Exp $
3    * Created on May 6, 2004
4    *
5    * Copyright (c) 1999-2004, BBN Technologies, LLC.
6    * All rights reserved.
7    * http://www.daml.org/legal/opensource/bbn_license.html
8    */
9   
10  package com.bbn.swede.ui.util;
11  
12  import org.eclipse.swt.graphics.FontMetrics;
13  import org.eclipse.swt.graphics.GC;
14  import org.eclipse.swt.widgets.Control;
15  
16  import org.eclipse.jface.dialogs.Dialog;
17  
18  /***
19   * Converts character sizes and dialog units to pixels.
20   * @author tself
21   */
22  public class PixelConverter
23  {
24  
25     private FontMetrics _fontMetrics;
26  
27     /***
28      * Creates a pixel convertor for a given control.
29      * @param control The control.
30      */
31     public PixelConverter(Control control)
32     {
33        GC gc = new GC(control);
34        gc.setFont(control.getFont());
35        _fontMetrics = gc.getFontMetrics();
36        gc.dispose();
37     }
38  
39     /***
40      * @see org.eclipse.jface.dialogs.DialogPage#convertHeightInCharsToPixels(int)
41      */
42     public int convertHeightInCharsToPixels(int chars)
43     {
44        return Dialog.convertHeightInCharsToPixels(_fontMetrics, chars);
45     }
46  
47     /***
48      * @see org.eclipse.jface.dialogs.DialogPage#convertHorizontalDLUsToPixels(int)
49      */
50     public int convertHorizontalDLUsToPixels(int dlus)
51     {
52        return Dialog.convertHorizontalDLUsToPixels(_fontMetrics, dlus);
53     }
54  
55     /***
56      * @see org.eclipse.jface.dialogs.DialogPage#convertVerticalDLUsToPixels(int)
57      */
58     public int convertVerticalDLUsToPixels(int dlus)
59     {
60        return Dialog.convertVerticalDLUsToPixels(_fontMetrics, dlus);
61     }
62  
63     /***
64      * @see org.eclipse.jface.dialogs.DialogPage#convertWidthInCharsToPixels(int)
65      */
66     public int convertWidthInCharsToPixels(int chars)
67     {
68        return Dialog.convertWidthInCharsToPixels(_fontMetrics, chars);
69     }
70  
71  }