KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > TrimUtil


1 /*******************************************************************************
2  * Copyright (c) 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
12 package org.eclipse.ui.internal;
13
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.graphics.GC;
18 import org.eclipse.swt.graphics.Point;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Display;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.swt.widgets.ToolBar;
24 import org.eclipse.swt.widgets.ToolItem;
25
26 /**
27  * Simple class to provide some common internal Trim support.
28  *
29  * @since 3.2
30  *
31  */

32 public class TrimUtil {
33
34     /**
35      * Default height for workbench trim.
36      */

37     public static final int TRIM_DEFAULT_HEIGHT;
38     static {
39         Shell s = new Shell(Display.getCurrent(), SWT.NONE);
40         s.setLayout(new GridLayout());
41         ToolBar t = new ToolBar(s, SWT.NONE);
42         t.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
43         ToolItem ti = new ToolItem(t, SWT.PUSH);
44         ti.setImage(JFaceResources.getImageRegistry().get(Dialog.DLG_IMG_MESSAGE_INFO));
45         s.layout();
46         int toolItemHeight = t.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
47         GC gc = new GC(s);
48         Point fontSize = gc.textExtent("Wg"); //$NON-NLS-1$
49
gc.dispose();
50         TRIM_DEFAULT_HEIGHT = Math.max(toolItemHeight, fontSize.y);
51         s.dispose();
52         
53     }
54 }
55
Popular Tags