KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > comment > DefaultTextMeasurement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.text.comment;
13
14 import org.eclipse.swt.graphics.GC;
15 import org.eclipse.swt.widgets.Control;
16
17 /**
18  * Text measurement based on the font set for a SWT control.
19  *
20  * @since 3.0
21  */

22 public class DefaultTextMeasurement implements ITextMeasurement {
23     
24     /** Control */
25     private Control fControl;
26     
27     /**
28      * Initialize with the given control.
29      *
30      * @param control The control
31      */

32     public DefaultTextMeasurement(Control control) {
33         fControl= control;
34     }
35     
36     /*
37      * @see org.eclipse.jdt.internal.ui.text.comment.ITextMeasurement#computeWidth(java.lang.String)
38      */

39     public int computeWidth(String JavaDoc string) {
40         GC graphics= new GC(fControl);
41         graphics.setFont(fControl.getFont());
42         int width= graphics.stringExtent(string).x;
43         graphics.dispose();
44         return width;
45     }
46 }
47
Popular Tags