01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal;
11:
12: import org.eclipse.jface.dialogs.Dialog;
13: import org.eclipse.jface.resource.JFaceResources;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.graphics.GC;
16: import org.eclipse.swt.graphics.Point;
17: import org.eclipse.swt.layout.GridData;
18: import org.eclipse.swt.layout.GridLayout;
19: import org.eclipse.swt.widgets.Display;
20: import org.eclipse.swt.widgets.Shell;
21: import org.eclipse.swt.widgets.ToolBar;
22: import org.eclipse.swt.widgets.ToolItem;
23:
24: /**
25: * Simple class to provide some common internal Trim support.
26: *
27: * @since 3.2
28: *
29: */
30: public class TrimUtil {
31:
32: /**
33: * Default height for workbench trim.
34: */
35: public static final int TRIM_DEFAULT_HEIGHT;
36: static {
37: Shell s = new Shell(Display.getCurrent(), SWT.NONE);
38: s.setLayout(new GridLayout());
39: ToolBar t = new ToolBar(s, SWT.NONE);
40: t.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
41: ToolItem ti = new ToolItem(t, SWT.PUSH);
42: ti.setImage(JFaceResources.getImageRegistry().get(
43: Dialog.DLG_IMG_MESSAGE_INFO));
44: s.layout();
45: int toolItemHeight = t.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
46: GC gc = new GC(s);
47: Point fontSize = gc.textExtent("Wg"); //$NON-NLS-1$
48: gc.dispose();
49: TRIM_DEFAULT_HEIGHT = Math.max(toolItemHeight, fontSize.y);
50: s.dispose();
51:
52: }
53: }
|